Exemplo n.º 1
0
        public void apply_should_apply_configured_conventions()
        {
            // arrange
            var controller  = new HttpControllerDescriptor(new HttpConfiguration(), "Stub", typeof(StubController));
            var action      = new ReflectedHttpActionDescriptor(controller, typeof(StubController).GetMethod(nameof(StubController.Get)));
            var description = new VersionedApiDescription()
            {
                ActionDescriptor    = action,
                HttpMethod          = HttpMethod.Get,
                ResponseDescription = new ResponseDescription()
                {
                    ResponseType = typeof(object),
                },
                Properties =
                {
                    [typeof(IEdmModel)] = new EdmModel(),
                }
            };
            var builder  = new ODataQueryOptionsConventionBuilder();
            var settings = new ODataQueryOptionSettings()
            {
                DescriptionProvider = builder.DescriptionProvider
            };
            var convention = new Mock <IODataQueryOptionsConvention>();

            convention.Setup(c => c.ApplyTo(It.IsAny <ApiDescription>()));
            builder.Add(convention.Object);

            // act
            builder.ApplyTo(new[] { description }, settings);

            // assert
            convention.Verify(c => c.ApplyTo(description), Once());
        }
Exemplo n.º 2
0
        public void apply_should_apply_configured_conventions()
        {
            // arrange
            var description = new ApiDescription()
            {
                ActionDescriptor = new ControllerActionDescriptor()
                {
                    ControllerTypeInfo = typeof(StubController).GetTypeInfo(),
                    MethodInfo         = typeof(StubController).GetTypeInfo().GetRuntimeMethod(nameof(StubController.Get), Type.EmptyTypes),
                },
                HttpMethod = "GET",
            };
            var builder  = new ODataQueryOptionsConventionBuilder();
            var settings = new ODataQueryOptionSettings()
            {
                DescriptionProvider   = builder.DescriptionProvider,
                DefaultQuerySettings  = new DefaultQuerySettings(),
                ModelMetadataProvider = Mock.Of <IModelMetadataProvider>(),
            };
            var convention = new Mock <IODataQueryOptionsConvention>();

            convention.Setup(c => c.ApplyTo(It.IsAny <ApiDescription>()));
            builder.Add(convention.Object);

            // act
            builder.ApplyTo(new[] { description }, settings);

            // assert
            convention.Verify(c => c.ApplyTo(description), Once());
        }
Exemplo n.º 3
0
        public void controller_should_return_existing_controller_builder_conventions_for_type()
        {
            // arrange
            var builder = new ODataQueryOptionsConventionBuilder();
            var originalControllerBuilder = builder.Controller(typeof(StubController));

            // act
            var controllerBuilder = builder.Controller(typeof(StubController));

            // assert
            controllerBuilder.Should().BeSameAs(originalControllerBuilder);
        }
Exemplo n.º 4
0
        public void controller_for_type_should_not_allow_both_compileX2Dtime_and_runX2Dtime_conventions()
        {
            // arrange
            var builder = new ODataQueryOptionsConventionBuilder();

            builder.Controller(typeof(StubController));

            // act
            Action controllerConvention = () => builder.Controller <StubController>();

            // assert
            controllerConvention.Should().Throw <InvalidOperationException>();
        }