public void get_edm_models_should_split_models_between_routes()
        {
            // arrange
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new Mock <IHttpControllerTypeResolver>();
            var controllerTypes        = new List <Type>()
            {
                typeof(TestController), typeof(OtherTestController)
            };
            var options = new ApiVersioningOptions();

            controllerTypeResolver.Setup(ctr => ctr.GetControllerTypes(It.IsAny <IAssembliesResolver>())).Returns(controllerTypes);
            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver.Object);
            configuration.Services.Replace(typeof(IHttpControllerSelector), new ApiVersionControllerSelector(configuration, options));

            var defaultConfiguration = new Mock <Action <ODataModelBuilder, ApiVersion, string> >();
            var modelCreated         = new Mock <Action <ODataModelBuilder, IEdmModel> >();
            var builder = new VersionedODataModelBuilder(configuration)
            {
                DefaultModelConfiguration = (builder, version, prefix) =>
                {
                    if (prefix == "api2")
                    {
                        builder.EntitySet <TestEntity>("Tests");
                    }
                },
            };

            // act
            var models = builder.GetEdmModels("api2");

            // assert
            models.Should().HaveCount(2);
            models.ElementAt(1).FindDeclaredEntitySet("Tests").Should().NotBeNull();
        }
        public void get_edm_models_should_split_models_between_routes()
        {
            // arrange
            var apiVersion = new ApiVersion(1, 0);
            var actionDescriptorCollectionProvider = NewActionDescriptorCollectionProvider(new[] { apiVersion, new ApiVersion(2, 0) });
            var options = Options.Create(new ApiVersioningOptions()
            {
                DefaultApiVersion = apiVersion
            });
            var modelCreated = new Mock <Action <ODataModelBuilder, IEdmModel> >();
            var builder      = new VersionedODataModelBuilder(actionDescriptorCollectionProvider, options)
            {
                DefaultModelConfiguration = (builder, version, prefix) =>
                {
                    if (prefix == "api2")
                    {
                        builder.EntitySet <TestEntity>("Tests");
                    }
                },
            };

            // act
            var models = builder.GetEdmModels("api2");

            // assert
            models.Should().HaveCount(2);
            models.ElementAt(1).FindDeclaredEntitySet("Tests").Should().NotBeNull();
        }
        public void get_edm_models_should_return_expected_results()
        {
            // arrange
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new Mock <IHttpControllerTypeResolver>();
            var controllerTypes        = new List <Type>()
            {
                typeof(TestController)
            };

            controllerTypeResolver.Setup(ctr => ctr.GetControllerTypes(It.IsAny <IAssembliesResolver>())).Returns(controllerTypes);
            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver.Object);

            var modelCreated = new Mock <Action <ODataModelBuilder, IEdmModel> >();
            var apiVersion   = new ApiVersion(1, 0);
            var builder      = new VersionedODataModelBuilder(configuration)
            {
                DefaultModelConfiguration = (builder, version, prefix) => builder.EntitySet <TestEntity>("Tests"),
                OnModelCreated            = modelCreated.Object
            };

            // act
            var model = builder.GetEdmModels().Single();

            // assert
            model.GetAnnotationValue <ApiVersionAnnotation>(model).ApiVersion.Should().Be(apiVersion);
            modelCreated.Verify(f => f(It.IsAny <ODataModelBuilder>(), model), Times.Once());
        }
Beispiel #4
0
        public void get_edm_models_should_return_expected_results()
        {
            // arrange
            var actionDescriptorCollectionProvider = NewActionDescriptorCollectionProvider();
            var apiVersion = new ApiVersion(1, 0);
            var options    = Options.Create(new ApiVersioningOptions()
            {
                DefaultApiVersion = apiVersion
            });
            var defaultConfiguration = new Mock <Action <ODataModelBuilder, ApiVersion> >();
            var modelCreated         = new Mock <Action <ODataModelBuilder, IEdmModel> >();
            var builder = new VersionedODataModelBuilder(actionDescriptorCollectionProvider, options)
            {
                DefaultModelConfiguration = defaultConfiguration.Object,
                OnModelCreated            = modelCreated.Object
            };

            // act
            var model = builder.GetEdmModels().Single();

            // assert
            model.GetAnnotationValue <ApiVersionAnnotation>(model).ApiVersion.Should().Be(apiVersion);
            defaultConfiguration.Verify(f => f(It.IsAny <ODataModelBuilder>(), apiVersion), Once());
            modelCreated.Verify(f => f(It.IsAny <ODataModelBuilder>(), model), Once());
        }