1313using System . IO ;
1414using System . Xml ;
1515using System . Collections . Generic ;
16- using System . Net ;
1716using System . Text ;
1817using Microsoft . OData . Edm . Validation ;
1918using Xunit . Abstractions ;
@@ -23,48 +22,35 @@ namespace Microsoft.OpenApi.OData.Tests
2322 /// <summary>
2423 /// Edm model helpers
2524 /// </summary>
26- public class EdmModelHelper
25+ public class EdmModelHelper ( ITestOutputHelper output )
2726 {
2827 public static IEdmModel EmptyModel { get ; } = new EdmModel ( ) ;
2928
30- public static IEdmModel MultipleInheritanceEdmModel { get ; }
29+ public static IEdmModel MultipleInheritanceEdmModel { get ; } = CreateMultipleInheritanceEdmModel ( ) ;
3130
32- public static IEdmModel InheritanceEdmModelAcrossReferences { get ; }
31+ public static IEdmModel InheritanceEdmModelAcrossReferences { get ; } = CreateInheritanceEdmModelAcrossReferences ( ) ;
3332
34- public static IEdmModel BasicEdmModel { get ; }
33+ public static IEdmModel BasicEdmModel { get ; } = CreateEdmModel ( ) ;
3534
36- public static IEdmModel MultipleSchemasEdmModel { get ; }
35+ public static IEdmModel MultipleSchemasEdmModel { get ; } = LoadEdmModel ( "Multiple.Schema.OData.xml" ) ;
3736
38- public static IEdmModel CompositeKeyModel { get ; }
37+ public static IEdmModel CompositeKeyModel { get ; } = CreateCompositeKeyModel ( ) ;
3938
40- public static IEdmModel TripServiceModel { get ; }
39+ public static IEdmModel TripServiceModel { get ; } = LoadEdmModel ( "TripService.OData.xml" ) ;
4140
42- public static IEdmModel ContractServiceModel { get ; }
41+ public static IEdmModel ContractServiceModel { get ; } = LoadEdmModel ( "Contract.OData.xml" ) ;
4342
44- public static IEdmModel GraphBetaModel { get ; }
43+ public static IEdmModel GraphBetaModel { get ; } = LoadEdmModel ( "Graph.Beta.OData.xml" ) ;
4544
46- public static IEdmModel ComposableFunctionsModel { get ; }
47-
48- static EdmModelHelper ( )
49- {
50- MultipleInheritanceEdmModel = CreateMultipleInheritanceEdmModel ( ) ;
51- BasicEdmModel = CreateEdmModel ( ) ;
52- CompositeKeyModel = CreateCompositeKeyModel ( ) ;
53- TripServiceModel = LoadEdmModel ( "TripService.OData.xml" ) ;
54- ContractServiceModel = LoadEdmModel ( "Contract.OData.xml" ) ;
55- GraphBetaModel = LoadEdmModel ( "Graph.Beta.OData.xml" ) ;
56- MultipleSchemasEdmModel = LoadEdmModel ( "Multiple.Schema.OData.xml" ) ;
57- InheritanceEdmModelAcrossReferences = CreateInheritanceEdmModelAcrossReferences ( ) ;
58- ComposableFunctionsModel = LoadEdmModel ( "ComposableFunctions.OData.xml" ) ;
59- }
45+ public static IEdmModel ComposableFunctionsModel { get ; } = LoadEdmModel ( "ComposableFunctions.OData.xml" ) ;
6046
6147 private static IEdmModel LoadEdmModel ( string source )
6248 {
6349 string csdl = Resources . GetString ( source ) ;
6450 return CsdlReader . Parse ( XElement . Parse ( csdl ) . CreateReader ( ) ) ;
6551 }
6652
67- private static IEdmModel CreateMultipleInheritanceEdmModel ( )
53+ private static EdmModel CreateMultipleInheritanceEdmModel ( )
6854 {
6955 var model = new EdmModel ( ) ;
7056
@@ -112,7 +98,7 @@ private static IEdmModel CreateMultipleInheritanceEdmModel()
11298 horse . AddStructuralProperty ( "Height" , EdmCoreModel . Instance . GetDecimal ( false ) ) ;
11399 model . AddElement ( horse ) ;
114100
115- EdmNavigationPropertyInfo navInfo = new EdmNavigationPropertyInfo
101+ EdmNavigationPropertyInfo navInfo = new ( )
116102 {
117103 Name = "Creatures" ,
118104 Target = creature ,
@@ -202,19 +188,17 @@ public static IEdmModel CreateInheritanceEdmModelAcrossReferences()
202188 </edmx:DataServices>
203189</edmx:Edmx>" ;
204190
205- IEdmModel model ;
206- IEnumerable < EdmError > errors ;
207191
208192 XElement parsed = XElement . Parse ( modelText ) ;
209193 bool result = CsdlReader . TryParse ( parsed . CreateReader ( ) ,
210194 uri => XElement . Parse ( subModelText ) . CreateReader ( ) ,
211- out model ,
212- out errors ) ;
195+ out var model ,
196+ out var _ ) ;
213197 Assert . True ( result ) ;
214198 return model ;
215199 }
216200
217- private static IEdmModel CreateEdmModel ( )
201+ private static EdmModel CreateEdmModel ( )
218202 {
219203 var model = new EdmModel ( ) ;
220204
@@ -272,10 +256,10 @@ private static IEdmModel CreateEdmModel()
272256
273257 var entityContainer = new EdmEntityContainer ( "DefaultNs" , "Container" ) ;
274258 model . AddElement ( entityContainer ) ;
275- EdmSingleton me = new EdmSingleton ( entityContainer , "Me" , person ) ;
276- EdmEntitySet people = new EdmEntitySet ( entityContainer , "People" , person ) ;
277- EdmEntitySet cities = new EdmEntitySet ( entityContainer , "City" , city ) ;
278- EdmEntitySet countriesOrRegions = new EdmEntitySet ( entityContainer , "CountryOrRegion" , countryOrRegion ) ;
259+ EdmSingleton me = new ( entityContainer , "Me" , person ) ;
260+ EdmEntitySet people = new ( entityContainer , "People" , person ) ;
261+ EdmEntitySet cities = new ( entityContainer , "City" , city ) ;
262+ EdmEntitySet countriesOrRegions = new ( entityContainer , "CountryOrRegion" , countryOrRegion ) ;
279263 people . AddNavigationTarget ( navP , cities , new EdmPathExpression ( "HomeAddress/City" ) ) ;
280264 people . AddNavigationTarget ( navP , cities , new EdmPathExpression ( "Addresses/City" ) ) ;
281265 people . AddNavigationTarget ( navP2 , countriesOrRegions ,
@@ -295,7 +279,7 @@ private static IEdmModel CreateEdmModel()
295279 return model ;
296280 }
297281
298- private static IEdmModel CreateCompositeKeyModel ( )
282+ private static EdmModel CreateCompositeKeyModel ( )
299283 {
300284 var model = new EdmModel ( ) ;
301285
@@ -311,11 +295,7 @@ private static IEdmModel CreateCompositeKeyModel()
311295 return model ;
312296 }
313297
314- private ITestOutputHelper _output ;
315- public EdmModelHelper ( ITestOutputHelper output )
316- {
317- _output = output ;
318- }
298+ private readonly ITestOutputHelper _output = output ;
319299
320300 [ Fact ]
321301 public void MultipleInheritanceEdmModelMetadataDocumentTest ( )
@@ -413,24 +393,18 @@ public void MultipleInheritanceEdmModelMetadataDocumentTest()
413393
414394 public static string GetCsdl ( IEdmModel model )
415395 {
416- string edmx = String . Empty ;
417-
418- using ( StringWriter sw = new StringWriter ( ) )
396+ using StringWriter sw = new ( ) ;
397+ XmlWriterSettings settings = new ( )
419398 {
420- XmlWriterSettings settings = new XmlWriterSettings ( ) ;
421- settings . Encoding = Encoding . UTF8 ;
422- settings . Indent = true ;
423-
424- using ( XmlWriter xw = XmlWriter . Create ( sw , settings ) )
425- {
426- IEnumerable < EdmError > errors ;
427- CsdlWriter . TryWriteCsdl ( model , xw , CsdlTarget . OData , out errors ) ;
428- xw . Flush ( ) ;
429- }
399+ Encoding = Encoding . UTF8 ,
400+ Indent = true
401+ } ;
430402
431- edmx = sw . ToString ( ) ;
432- }
403+ using XmlWriter xw = XmlWriter . Create ( sw , settings ) ;
404+ CsdlWriter . TryWriteCsdl ( model , xw , CsdlTarget . OData , out var _ ) ;
405+ xw . Flush ( ) ;
433406
407+ string edmx = sw . ToString ( ) ;
434408 return edmx ;
435409 }
436410 }
0 commit comments