55using  System . Text ; 
66using  BenchmarkDotNet . Characteristics ; 
77using  BenchmarkDotNet . Environments ; 
8+ using  BenchmarkDotNet . Extensions ; 
89using  BenchmarkDotNet . Running ; 
910using  Xunit ; 
1011using  BenchmarkDotNet . Tests . XUnit ; 
12+ using  System . Runtime ; 
1113
1214namespace  BenchmarkDotNet . Tests 
1315{ 
@@ -20,10 +22,10 @@ public void GeneratesMinimalRequiredAppConfigForEmptySource()
2022        { 
2123            using  ( var  destination  =  new  Utf8StringWriter ( ) ) 
2224            { 
23-                 const   string  expectedMinimal  = 
25+                 string  expectedMinimal  = 
2426                    "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
2527                    "<configuration>"  + 
26-                     "<runtime/ >"  + 
28+                     $ "<runtime> { GcSettings } </runtime >"+ 
2729                    "</configuration>" ; 
2830
2931                AppConfigGenerator . Generate ( Job . Default ,  TextReader . Null ,  destination ,  Resolver ) ; 
@@ -38,10 +40,10 @@ public void GeneratesMinimalRequiredAppConfigForAlmostEmptySource()
3840            using  ( var  source  =  new  StringReader ( "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>" ) ) 
3941            using  ( var  destination  =  new  Utf8StringWriter ( ) ) 
4042            { 
41-                 const   string  expectedMinimal  = 
43+                 string  expectedMinimal  = 
4244                    "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
4345                    "<configuration>"  + 
44-                     "<runtime/ >"  + 
46+                     $ "<runtime> { GcSettings } </runtime >"+ 
4547                    "</configuration>" ; 
4648
4749                AppConfigGenerator . Generate ( Job . Default ,  source ,  destination ,  Resolver ) ; 
@@ -53,50 +55,69 @@ public void GeneratesMinimalRequiredAppConfigForAlmostEmptySource()
5355        [ Fact ] 
5456        public  void  RewritesCustomSettings ( ) 
5557        { 
56-             const   string  customSettings  = 
58+             string  customSettingsWithoutRuntimeNode  = 
5759                "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
5860                "<!--"  + 
5961                "commentsAreSupported"  + 
6062                "-->"  + 
6163                "<configuration>"  + 
6264                "<someConfig>withItsValue</someConfig>"  + 
63-                 "<runtime/>"  + 
6465                "</configuration>" ; 
6566
66-             using  ( var  source  =  new  StringReader ( customSettings ) ) 
67+             string  customSettingsWithRuntimeNode  = 
68+                 "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
69+                 "<!--"  + 
70+                 "commentsAreSupported"  + 
71+                 "-->"  + 
72+                 "<configuration>"  + 
73+                 "<someConfig>withItsValue</someConfig>"  + 
74+                 $ "<runtime>{ GcSettings } </runtime>"+ 
75+                 "</configuration>" ; 
76+ 
77+             using  ( var  source  =  new  StringReader ( customSettingsWithoutRuntimeNode ) ) 
6778            using  ( var  destination  =  new  Utf8StringWriter ( ) ) 
6879            { 
6980                AppConfigGenerator . Generate ( Job . Default ,  source ,  destination ,  Resolver ) ; 
7081
71-                 AssertAreEqualIgnoringWhitespacesAndCase ( customSettings ,  destination . ToString ( ) ) ; 
82+                 AssertAreEqualIgnoringWhitespacesAndCase ( customSettingsWithRuntimeNode ,  destination . ToString ( ) ) ; 
7283            } 
7384        } 
7485
7586        [ Fact ] 
7687        public  void  RewritesCustomRuntimeSettings ( ) 
7788        { 
78-             const   string  customSettings  = 
89+             string  customSettingsBefore  = 
7990                "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
8091                "<!--"  + 
8192                "commentsAreSupported"  + 
8293                "-->"  + 
8394                "<configuration>"  + 
8495                "<someConfig>withItsValue</someConfig>"  + 
85-                 "<runtime><AppContextSwitchOverrides value=\" Switch.System.IO.UseLegacyPathHandling=false\" /></runtime>"  + 
96+                 $ "<runtime><AppContextSwitchOverrides value=\" Switch.System.IO.UseLegacyPathHandling=false\" /></runtime>"+ 
8697                "</configuration>" ; 
8798
88-             using  ( var  source  =  new  StringReader ( customSettings ) ) 
99+             string  customSettingsAfter  = 
100+                 "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
101+                 "<!--"  + 
102+                 "commentsAreSupported"  + 
103+                 "-->"  + 
104+                 "<configuration>"  + 
105+                 "<someConfig>withItsValue</someConfig>"  + 
106+                 $ "<runtime><AppContextSwitchOverrides value=\" Switch.System.IO.UseLegacyPathHandling=false\" />{ GcSettings } </runtime>"+ 
107+                 "</configuration>" ; 
108+ 
109+             using  ( var  source  =  new  StringReader ( customSettingsBefore ) ) 
89110            using  ( var  destination  =  new  Utf8StringWriter ( ) ) 
90111            { 
91112                AppConfigGenerator . Generate ( Job . Default ,  source ,  destination ,  Resolver ) ; 
92113
93-                 AssertAreEqualIgnoringWhitespacesAndCase ( customSettings ,  destination . ToString ( ) ) ; 
114+                 AssertAreEqualIgnoringWhitespacesAndCase ( customSettingsAfter ,  destination . ToString ( ) ) ; 
94115            } 
95116        } 
96117
97118        [ Theory ] 
98-         [ InlineData ( Jit . LegacyJit ,  "<runtime>< useLegacyJit enabled=\" 1\"  /></runtime >" ) ] 
99-         [ InlineData ( Jit . RyuJit ,  "<runtime>< useLegacyJit enabled=\" 0\"  /></runtime >" ) ] 
119+         [ InlineData ( Jit . LegacyJit ,  "<useLegacyJit enabled=\" 1\"  />" ) ] 
120+         [ InlineData ( Jit . RyuJit ,  "<useLegacyJit enabled=\" 0\"  />" ) ] 
100121        public  void  GeneratesRightJitSettings ( Jit  jit ,  string  expectedRuntimeNode ) 
101122        { 
102123            const  string  customSettings  = 
@@ -109,7 +130,7 @@ public void GeneratesRightJitSettings(Jit jit, string expectedRuntimeNode)
109130                "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
110131                "<configuration>"  + 
111132                "<someConfig>withItsValue</someConfig>"  + 
112-                 expectedRuntimeNode  + 
133+                 $ "<runtime> { expectedRuntimeNode } { GcSettings } </runtime>" + 
113134                "</configuration>"  +  Environment . NewLine ; 
114135
115136            using  ( var  source  =  new  StringReader ( customSettings ) ) 
@@ -133,7 +154,7 @@ public void RemovesStartupSettingsForPrivateBuildsOfClr()
133154            string  withoutStartup  = 
134155                "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
135156                "<configuration>"  + 
136-                 "<runtime/ >"  + 
157+                 $ "<runtime> { GcSettings } </runtime >"+ 
137158                "</configuration>"  +  Environment . NewLine ; 
138159
139160            using  ( var  source  =  new  StringReader ( input ) ) 
@@ -158,7 +179,7 @@ public void LeavsStartupSettingsIntactForNonPrivateBuildsOfClr()
158179                "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
159180                "<configuration>"  + 
160181                "<startup><supportedRuntime version=\" v4.0\"  sku=\" .NETFramework,Version=v4.6.1\"  /></startup>"  + 
161-                 "<runtime/ >"  + 
182+                 $ "<runtime> { GcSettings } </runtime >"+ 
162183                "</configuration>"  +  Environment . NewLine ; 
163184
164185            using  ( var  source  =  new  StringReader ( input ) ) 
@@ -186,7 +207,7 @@ public void RewritesCustomAssemblyBindingRedirects()
186207                "</runtime>"  + 
187208                "</configuration>" ; 
188209
189-             const   string  settingsWithBindingsAndJit  = 
210+             string  settingsWithBindingsAndJit  = 
190211                "<?xml version=\" 1.0\"  encoding=\" UTF-8\" ?>"  + 
191212                "<configuration>"  + 
192213                "<runtime>"  + 
@@ -197,6 +218,7 @@ public void RewritesCustomAssemblyBindingRedirects()
197218                "</dependentAssembly>"  + 
198219                "</assemblyBinding>"  + 
199220                "<useLegacyJit enabled =\" 0\"  />"  + 
221+                 GcSettings  + 
200222                "</runtime>"  + 
201223                "</configuration>" ; 
202224
@@ -234,6 +256,8 @@ private static string RemoveWhiteSpaces(string input)
234256                } 
235257            return  buffer . ToString ( ) ; 
236258        } 
259+ 
260+         private  static readonly  string  GcSettings  =  $ "<gcConcurrentenabled=\" { ( GCSettings . LatencyMode  !=  GCLatencyMode . Batch ) . ToLowerCase ( ) } \" /><gcServerenabled=\" { GCSettings . IsServerGC . ToLowerCase ( ) } \" />"; 
237261    } 
238262
239263    internal  class  Utf8StringWriter  :  StringWriter 
0 commit comments