66using System . Linq ;
77using System . Reflection ;
88using Microsoft . VisualStudio . TestTools . UnitTesting ;
9+ using Newtonsoft . Json ;
10+ using Newtonsoft . Json . Serialization ;
911
1012namespace Dibix . Testing
1113{
@@ -36,6 +38,9 @@ public TestResultComposer(TestContext testContext, bool useDedicatedTestResultsD
3638 this . _actualDirectory = Path . Combine ( this . RunDirectory , ActualDirectoryName ) ;
3739 this . _testRunFiles = new HashSet < string > ( ) ;
3840 this . _testFiles = new HashSet < string > ( ) ;
41+ #if DEBUG
42+ this . EnsureTestContextDump ( ) ;
43+ #endif
3944 }
4045
4146 public string AddFile ( string fileName )
@@ -136,16 +141,22 @@ private void RegisterFile(string path, bool scopeIsTestRun)
136141 files . Add ( path ) ;
137142 }
138143
139- private void EnsureWinMergeStarter ( )
144+ private void EnsureWinMergeStarter ( ) => AddTestRunFile ( "winmerge.bat" , $@ "@echo off
145+ start winmergeU ""{ ExpectedDirectoryName } "" ""{ ActualDirectoryName } """);
146+ private void EnsureTestContextDump() => AddTestRunFile(" TestContext. json ", JsonConvert . SerializeObject ( this . _testContext , new JsonSerializerSettings
147+ {
148+ Formatting = Formatting . Indented ,
149+ ContractResolver = new TestContextContractResolver ( )
150+ } ) ) ;
151+
152+ private void AddTestRunFile ( string fileName , string content )
140153 {
141- const string fileName = "winmerge.bat" ;
142154 string path = Path . Combine ( this . RunDirectory , fileName ) ;
143155
144156 if ( ! this . ShouldRegisterTestRunFile ( path ) )
145157 return ;
146158
147- WriteContentToFile ( path , $@ "@echo off
148- start winmergeU ""{ ExpectedDirectoryName } "" ""{ ActualDirectoryName } """);
159+ WriteContentToFile ( path , content ) ;
149160 this . RegisterFile ( path , scopeIsTestRun : true ) ;
150161 }
151162
@@ -225,5 +236,19 @@ public enum EventLogEntryType
225236 SuccessAudit = 8 ,
226237 FailureAudit = 16
227238 }
239+
240+ private sealed class TestContextContractResolver : DefaultContractResolver , IContractResolver
241+ {
242+ protected override JsonObjectContract CreateObjectContract ( Type objectType )
243+ {
244+ JsonObjectContract contract = base . CreateObjectContract ( objectType ) ;
245+ if ( objectType . FullName == "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation" )
246+ {
247+ // Self referencing loop detected for property 'Context' with type 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation'. Path ''.
248+ contract . Properties . Remove ( "Context" ) ;
249+ }
250+ return contract ;
251+ }
252+ }
228253 }
229254}
0 commit comments