public void EdmReader_v3northwindmetadata_Test()
        {
            var testCfg = OfaSchlupfer.TestCfg.Get();
            IServiceCollection services = new ServiceCollection();

            services.AddLogging((builder) => { builder.AddDebug(); });
            var serviceProvider = services.BuildServiceProvider();

            //serviceProvider.GetRequiredService<ODataV3RepositoryModel>();
            var srcPath = System.IO.Path.Combine(testCfg.SolutionFolder, @"test\v3northwindmetadata.xml");

            var cachedMetadataResolver = new CachedMetadataResolver();

            cachedMetadataResolver.SetDynamicResolution((location) => new System.IO.StreamReader(location));
            var sut = new EdmReader {
                MetadataResolver = cachedMetadataResolver
            };

            var edmxModel = sut.Read(srcPath, true, null);

            Assert.NotNull(edmxModel);
            Assert.NotNull(edmxModel.Version);
            Assert.Equal(3, edmxModel.DataServices.Count);

            //var schema = sut.ReadSchema(sr);
            //sut.ModelSchema = schema;

            //try {
            //    string outputPath = System.IO.Path.Combine(testCfg.SolutionFolder, @"test\temp\ODataV3RepositoryModelTest_ReadSchema.json");
            //    System.IO.File.WriteAllText(outputPath, Newtonsoft.Json.JsonConvert.SerializeObject(
            //        sut.ModelSchema,
            //        Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings {
            //            PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
            //        }));
            //} catch {
            //    throw;
            //}
        }
        public void EdmxModelBuilder_v3northwindmetadata_Test()
        {
            var testCfg = OfaSchlupfer.TestCfg.Get();

            IServiceCollection services = new ServiceCollection();

            services.AddLogging((builder) => { builder.AddDebug(); });
            var serviceProvider = services.BuildServiceProvider();

            var srcPath = System.IO.Path.Combine(testCfg.SolutionFolder, @"test\v3northwindmetadata.xml");
            var cachedMetadataResolver = new CachedMetadataResolver();

            cachedMetadataResolver.SetDynamicResolution((location) => new System.IO.StreamReader(location));
            var edmReader = new EdmReader();

            edmReader.MetadataResolver = cachedMetadataResolver;

            var errors    = new ModelErrors();
            var edmxModel = edmReader.Read(srcPath, true, errors);

            if (errors.HasErrors())
            {
                output.WriteLine(errors.ToString());
                Assert.Equal("Error Read HasErrors", errors.ToString());
            }

            EdmxModelSchemaBuilder edmxModelBuilder = new EdmxModelSchemaBuilder();
            var modelSchema = edmxModelBuilder.Build(edmxModel, null, null, errors);

            if (errors.HasErrors())
            {
                output.WriteLine(errors.ToString());
                Assert.Equal("Error Builder HasErrors", errors.ToString());
            }

            var defaultEntityContainer = edmxModel.DataServices.SelectMany(_ => _.EntityContainer).FirstOrDefault(_ => _.IsDefaultEntityContainer);

            Assert.Equal(defaultEntityContainer.EntitySet.Count, modelSchema.Entities.Count);
            foreach (var entity in modelSchema.Entities)
            {
                if (entity.EntityType == null)
                {
                    throw new Xunit.Sdk.XunitException($"{entity.Name} has no EntityType.");
                }
                Assert.True(entity.EntityType.Properties.Count > 0);
                foreach (var property in entity.EntityType.Properties)
                {
                    Assert.NotNull(property.Name);
                    Assert.NotNull(property.Type);
                    //if (string.IsNullOrEmpty(property.Name)) {
                    //    property.Type
                    //}
                }
                foreach (var navigationProperty in entity.EntityType.NavigationProperty)
                {
                    Assert.NotNull(navigationProperty.Name);
                    Assert.NotNull(navigationProperty.ExternalName);
                    Assert.NotNull(navigationProperty.ItemType);
                }
            }
        }
        public void EdmReader_v4northwindmetadata_Test()
        {
            var testCfg = OfaSchlupfer.TestCfg.Get();
            IServiceCollection services = new ServiceCollection();

            services.AddLogging((builder) => { builder.AddDebug(); });
            var serviceProvider = services.BuildServiceProvider();

            //serviceProvider.GetRequiredService<ODataV3RepositoryModel>();
            var srcPath = System.IO.Path.Combine(testCfg.SolutionFolder, @"test\v4northwindmetadata.xml");

            var cachedMetadataResolver = new CachedMetadataResolver();

            cachedMetadataResolver.SetDynamicResolution((location) => new System.IO.StreamReader(location));
            var sut = new EdmReader {
                MetadataResolver = cachedMetadataResolver
            };

            var edmxModel = sut.Read(srcPath, true, null);

            Assert.NotNull(edmxModel);
            Assert.NotNull(edmxModel.Version);
            Assert.Equal(3, edmxModel.DataServices.Count);

            var schemaModels = edmxModel.DataServices.ToArray();

            var entityContainers = schemaModels
                                   .SelectMany((schema) => schema.EntityContainer)
                                   .ToArray();

            var entitySets = entityContainers
                             .SelectMany((entityContainer) => entityContainer.EntitySet)
                             .ToArray();

            foreach (var entitySet in entitySets)
            {
                Assert.NotNull(entitySet.EntityTypeModel);
            }

            var properties = entitySets
                             .SelectMany((entitySet) => entitySet.EntityTypeModel.Property)
                             .ToArray();

            foreach (var property in properties)
            {
                Assert.NotNull(property.TypeName);
            }

            var associationSets = entityContainers
                                  .SelectMany((entityContainer) => entityContainer.AssociationSet)
                                  .ToArray();

            foreach (var associationSet in associationSets)
            {
                Assert.NotNull(associationSet.AssociationModel);
            }

            var associationSetEnds = associationSets
                                     .SelectMany((associationSet) => associationSet.End)
                                     .ToArray();

            foreach (var end in associationSetEnds)
            {
                Assert.NotNull(end);
                Assert.NotNull(end.EntitySetName);
                Assert.NotNull(end.EntitySetModel);
                Assert.NotNull(end.Owner.AssociationModel.FindAssociationEnd(end.RoleName));
            }

            var entityTypes = schemaModels
                              .SelectMany((schemaModel) => schemaModel.EntityType)
                              .ToArray();

            foreach (var entityType in entityTypes)
            {
                foreach (var property in entityType.Property)
                {
                    Assert.NotNull(property.ScalarType);
                }
                foreach (var key in entityType.Keys)
                {
                    Assert.NotNull(key.Property);
                }
                foreach (var navigationProperty in entityType.NavigationProperty)
                {
                    Assert.Null(navigationProperty.RelationshipName);
                    Assert.Null(navigationProperty.FromRoleName);
                    Assert.Null(navigationProperty.ToRoleName);

                    if (navigationProperty.TypeName != null)
                    {
                        Assert.NotNull(navigationProperty.TypeName);
                        Assert.NotNull(navigationProperty.TypeModel);
                        Assert.NotNull(navigationProperty.PartnerName);
                        Assert.NotNull(navigationProperty.PartnerModel);
                    }

                    foreach (var referentialConstraint in navigationProperty.ReferentialConstraint)
                    {
                        Assert.NotNull(referentialConstraint.Property);
                        Assert.NotNull(referentialConstraint.ReferencedProperty);
                    }

                    //foreach(var end in property.en)
                }
            }

            var associations = schemaModels
                               .SelectMany((schemaModel) => schemaModel.Association)
                               .ToArray();

            foreach (var association in associations)
            {
                Assert.NotNull(association.Name);
            }

            //var schema = sut.ReadSchema(sr);
            //sut.ModelSchema = schema;

            //try {
            //    string outputPath = System.IO.Path.Combine(testCfg.SolutionFolder, @"test\temp\ODataV3RepositoryModelTest_ReadSchema.json");
            //    System.IO.File.WriteAllText(outputPath, Newtonsoft.Json.JsonConvert.SerializeObject(
            //        sut.ModelSchema,
            //        Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings {
            //            PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
            //        }));
            //} catch {
            //    throw;
            //}
        }