コード例 #1
0
        public async Task SendAsync_ReturnsNotFoundForNullEntityResponse()
        {
            // Arrange
            Mock <MediaTypeFormatter> formatter = new Mock <MediaTypeFormatter>();

            formatter.Setup(f => f.CanWriteType(It.IsAny <Type>())).Returns(true);

            HttpResponseMessage originalResponse = new HttpResponseMessage(HttpStatusCode.OK);

            originalResponse.Content = new ObjectContent(typeof(string), null, formatter.Object);

            ODataNullValueMessageHandler handler = new ODataNullValueMessageHandler
            {
                InnerHandler = new TestMessageHandler(originalResponse)
            };

            var                configuration = RoutingConfigurationFactory.Create();
            ODataPath          path          = new DefaultODataPathHandler().Parse(BuildModel(), "http://localhost/any", "Customers(3)");
            HttpRequestMessage request       = RequestFactory.Create(HttpMethod.Get, "http://localhost/any", configuration);

            request.ODataContext().Path = path;

            // Act
            HttpResponseMessage response = await handler.SendAsync(request);

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
コード例 #2
0
ファイル: MockContainer.cs プロジェクト: droyad/OData.WebApi
        private void InitializeConfiguration(Action <IContainerBuilder> action)
        {
            var    configuration = RoutingConfigurationFactory.Create();
            string routeName     = HttpRouteCollectionExtensions.RouteName;

            _rootContainer = configuration.CreateODataRootContainer(routeName, action);
        }
コード例 #3
0
ファイル: MockContainer.cs プロジェクト: droyad/OData.WebApi
        private void InitializeConfiguration(Action <IContainerBuilder> action)
        {
            var                        configuration     = RoutingConfigurationFactory.Create();
            string                     routeName         = HttpRouteCollectionExtensions.RouteName;
            IPerRouteContainer         perRouteContainer = configuration.ServiceProvider.GetRequiredService <IPerRouteContainer>();
            Action <IContainerBuilder> builderAction     = ODataRouteBuilderExtensions.ConfigureDefaultServices(configuration, action);

            _rootContainer = perRouteContainer.CreateODataRootContainer(routeName, builderAction);
        }
コード例 #4
0
        public void GetBinding_DoesnotThrowForNonPrimitives()
        {
            var  config        = RoutingConfigurationFactory.Create();
            Type parameterType = typeof(FormatterOrder);
            Mock <ParameterInfo> parameterInfoMock = new Mock <ParameterInfo>();

            parameterInfoMock.Setup(info => info.ParameterType).Returns(parameterType);
            ReflectedHttpParameterDescriptor parameter = new ReflectedHttpParameterDescriptor();

            parameter.Configuration = config;
            parameter.ParameterInfo = parameterInfoMock.Object;

            ExceptionAssert.DoesNotThrow(() => new FromODataUriAttribute().GetBinding(parameter));
        }
コード例 #5
0
ファイル: RequestFactory.cs プロジェクト: droyad/OData.WebApi
        /// <summary>
        /// Initializes a new instance of the routing configuration class.
        /// </summary>
        /// <returns>A new instance of the routing configuration class.</returns>
        public static HttpRequestMessage CreateFromModel(IEdmModel model, string uri = "http://localhost", string routeName = "Route", ODataPath path = null)
        {
            var configuration = RoutingConfigurationFactory.Create();

            configuration.MapODataServiceRoute(routeName, null, model);

            var request = RequestFactory.Create(HttpMethod.Get, uri, configuration, routeName);

            if (path != null)
            {
                request.ODataProperties().Path = path;
            }

            return(request);
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the routing configuration class.
        /// </summary>
        /// <returns>A new instance of the routing configuration class.</returns>
        internal static IWebApiAssembliesResolver Create(MockAssembly assembly = null)
        {
            IRouteBuilder builder = RoutingConfigurationFactory.Create();

            ApplicationPartManager applicationPartManager = builder.ApplicationBuilder.ApplicationServices.GetRequiredService <ApplicationPartManager>();

            applicationPartManager.ApplicationParts.Clear();

            if (assembly != null)
            {
                AssemblyPart part = new AssemblyPart(assembly);
                applicationPartManager.ApplicationParts.Add(part);
            }

            return(new WebApiAssembliesResolver(applicationPartManager));
        }
コード例 #7
0
        public void GetBinding_ReturnsSameBindingTypeAsODataModelBinderProvider()
        {
            var  config        = RoutingConfigurationFactory.Create();
            Type parameterType = typeof(Guid);
            Mock <ParameterInfo> parameterInfoMock = new Mock <ParameterInfo>();

            parameterInfoMock.Setup(info => info.ParameterType).Returns(parameterType);

            ReflectedHttpParameterDescriptor parameter = new ReflectedHttpParameterDescriptor();

            parameter.Configuration = config;
            parameter.ParameterInfo = parameterInfoMock.Object;

            HttpParameterBinding binding = new FromODataUriAttribute().GetBinding(parameter);

            ModelBinderParameterBinding modelBinding = Assert.IsType <ModelBinderParameterBinding>(binding);

            Assert.Equal(new ODataModelBinderProvider().GetBinder(config, parameterType).GetType(), modelBinding.Binder.GetType());
        }