Ejemplo 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());
        }
Ejemplo 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());
        }