示例#1
0
        private static System.Web.Http.HttpServer CreateServer(string customersEntitySet)
#endif
        {
            // We need to do this to avoid controllers with incorrect attribute
            // routing configuration in this assembly that cause an exception to
            // be thrown at runtime. With this, we restrict the test to the following
            // set of controllers.
            Type[] controllers = new Type[]
            {
                typeof(OnlyFilterAllowedCustomersController),
                typeof(OnlyFilterAndEqualsAllowedCustomersController),
                typeof(FilterDisabledCustomersController),
                typeof(EverythingAllowedCustomersController),
                typeof(OtherLimitationsCustomersController),
            };

            ODataModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            builder.EntitySet <EnableQueryCustomer>(customersEntitySet);
            builder.EntityType <PremiumEnableQueryCustomer>();

            builder.EntitySet <EnableQueryCategory>("EnableQueryCategories");
            builder.EntityType <PremiumEnableQueryCategory>();

            builder.EntitySet <EnableQueryOrder>("EnableQueryOrders");
            builder.EntityType <DiscountedEnableQueryOrder>();

            builder.EntitySet <EnableQueryOrderLine>("EnableQueryOrderLines");

            builder.ComplexType <EnableQueryAddress>();

            IEdmModel model = builder.GetEdmModel();

            return(TestServerFactory.Create(controllers, (config) =>
            {
                config.MapODataServiceRoute("odata", "odata", model);
                config.Count().OrderBy().Filter().Expand().MaxTop(null).Select();
            }));
        }
        private static IEdmModel GetEdmModel()
        {
            var builder = ODataConventionModelBuilderFactory.Create();

            builder.EntitySet <Account>("Accounts");
            builder.EntitySet <PaymentInstrument>("Payments");

            builder.EntityType <Account>().Collection.Action("Clear").Parameter <int>("p1");
            builder.EntityType <Account>()
            .Collection.Function("MyCollectionFunction")
            .Returns <string>()
            .Parameter <int>("land");

            builder.EntityType <PreminumAccount>().Collection.Function("MyCollectionFunction")
            .Returns <string>()
            .Parameter <int>("land");

            builder.EntityType <Account>().Action("ClearSingle").Parameter <string>("pa");

            builder.EntityType <Account>().Function("MyFunction").Returns <string>().Parameter <string>("p1");
            return(builder.GetEdmModel());
        }
        public void GetETag_Returns_ETagInHeader_ForInteger(byte byteValue, short shortValue, long longValue)
        {
            // Arrange
            Dictionary<string, object> properties = new Dictionary<string, object>
            {
                { "ByteVal", byteValue },
                { "LongVal", longValue },
                { "ShortVal", shortValue }
            };
            EntityTagHeaderValue etagHeaderValue = new DefaultODataETagHandler().CreateETag(properties);

            var builder = ODataConventionModelBuilderFactory.Create();
            builder.EntitySet<MyEtagOrder>("Orders");
            IEdmModel model = builder.GetEdmModel();
            IEdmEntitySet orders = model.FindDeclaredEntitySet("Orders");
            ODataPath odataPath = new ODataPath(new EntitySetSegment(orders));
            HttpRequestMessage request = new HttpRequestMessage();
            request.EnableHttpDependencyInjectionSupport(model);
            request.ODataProperties().Path = odataPath;

            // Act
            ETag result = request.GetETag(etagHeaderValue);
            dynamic dynamicResult = result;

            // Assert
            byte actualByte = Assert.IsType<byte>(result["ByteVal"]);
            Assert.Equal(actualByte, dynamicResult.ByteVal);
            Assert.Equal(byteValue, actualByte);

            short actualShort = Assert.IsType<short>(result["ShortVal"]);
            Assert.Equal(actualShort, dynamicResult.ShortVal);
            Assert.Equal(shortValue, actualShort);

            long actualLong = Assert.IsType<long>(result["LongVal"]);
            Assert.Equal(actualLong, dynamicResult.LongVal);
            Assert.Equal(longValue, actualLong);

        }
        private static IEdmModel SetupModel()
        {
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            // Different types of navigation sources and navigation properties.
            builder.EntitySet <ETagCustomer>("Customers");
            builder.EntitySet <ETagOrder>("Orders");
            builder.EntityType <ETagSpecialOrder>().DerivesFrom <ETagOrder>();
            builder.Singleton <ETagOrder>("BestOrder");
            builder.EntitySet <ETagAddress>("Addresses");

            // Entity without ETag to test that we only write entities with ETag.
            builder.EntitySet <NonEtagEntity>("NonEtagEntity");

            // Just a simplification for referencing the types in cast segments.
            foreach (var type in builder.StructuralTypes)
            {
                type.Namespace = "Test";
            }

            IEdmModel model = builder.GetEdmModel();

            return(model);
        }