public async Task DelayQueryOnFunctionImport()
        {
            this.testClientContext             = this.CreateWrappedContext <InMemoryEntitiesPlus>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Post an Product
            var product = ProductPlus.CreateProductPlus(10001, "10001", "2", 2.0f, 2, true);

            product.SkinColorPlus  = ColorPlus.RedPlus;
            product.UserAccessPlus = AccessLevelPlus.ExecutePlus | AccessLevelPlus.ReadPlus;
            this.testClientContext.AddToProductsPlus(product);
            await this.testClientContext.SaveChangesAsync();

            //Composable FunctionImport, return collection of entitySet
            var getAllProductsFunction = this.testClientContext.GetAllProductsPlus();
            var products = (await getAllProductsFunction.ExecuteAsync()).ToList();

            Assert.True(products.Any());
            Assert.True(getAllProductsFunction.RequestUri.OriginalString.EndsWith("/GetAllProducts()"));
            double unitPrice = products.First().UnitPricePlus;

            //GetEnumerator
            var discountAction = getAllProductsFunction.DiscountPlus(50);

            foreach (var p in await discountAction.ExecuteAsync())
            {
                Assert.Equal(unitPrice * 50 / 100, p.UnitPricePlus);
                break;
            }
            Assert.True(discountAction.RequestUri.OriginalString.EndsWith("/GetAllProducts()/Microsoft.Test.OData.Services.ODataWCFService.Discount"));

            //Filter after Bound FunctionImport
            var filterAllProducts = getAllProductsFunction.Where(p => p.SkinColorPlus == ColorPlus.RedPlus) as DataServiceQuery <ProductPlus>;

            foreach (var p in await filterAllProducts.ExecuteAsync())
            {
                Assert.Equal(ColorPlus.RedPlus, p.SkinColorPlus);
            }
            Assert.True(filterAllProducts.RequestUri.OriginalString.EndsWith("/GetAllProducts()?$filter=SkinColor eq Microsoft.Test.OData.Services.ODataWCFService.Color'Red'"));

            //FunctionImport, return collection of primitivetype
            var getBossEmailsFunction = this.testClientContext.GetBossEmailsPlus(0, 10);
            var emails = await getBossEmailsFunction.ExecuteAsync();

            Assert.True(getBossEmailsFunction.RequestUri.OriginalString.EndsWith("/GetBossEmails(start=0,count=10)"));

            //FunctionImport, return Collection of primitivetype with enum parameter
            //Fail now
            var productsNameQuery = this.testClientContext.GetProductsByAccessLevelPlus(AccessLevelPlus.ReadPlus | AccessLevelPlus.ExecutePlus);
            var productsName      = await productsNameQuery.ExecuteAsync();

            Assert.True(Uri.UnescapeDataString(productsNameQuery.RequestUri.OriginalString).EndsWith("/GetProductsByAccessLevel(accessLevel=Microsoft.Test.OData.Services.ODataWCFService.AccessLevel'Read,Execute')"));
            Assert.True(productsName.Any());
        }
Exemple #2
0
        public void DelayQueryOnFunctionImport()
        {
            TestClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Post an Product
            var product = ProductPlus.CreateProductPlus(10001, "10001", "2", 2.0f, 2, true);

            product.SkinColorPlus  = ColorPlus.RedPlus;
            product.UserAccessPlus = AccessLevelPlus.ExecutePlus | AccessLevelPlus.ReadPlus;
            TestClientContext.AddToProductsPlus(product);
            TestClientContext.SaveChanges();

            //FunctionImport
            var getAllProductsFunction = TestClientContext.GetAllProductsPlus();
            var products = getAllProductsFunction.ToList();

            Assert.IsTrue(products.Count() > 0);
            Assert.IsTrue(getAllProductsFunction.RequestUri.OriginalString.EndsWith("/GetAllProducts()"));
            double unitPrice = products.First().UnitPricePlus;

            //GetEnumerator
            var discountAction = getAllProductsFunction.DiscountPlus(50);

            foreach (var p in discountAction)
            {
                Assert.AreEqual(unitPrice * 50 / 100, p.UnitPricePlus);
                break;
            }
            Assert.IsTrue(discountAction.RequestUri.OriginalString.EndsWith("/GetAllProducts()/Microsoft.Test.OData.Services.ODataWCFService.Discount"));

            //Filter after FunctionImport
            var filterAllProducts = getAllProductsFunction.Where(p => p.SkinColorPlus == ColorPlus.RedPlus) as DataServiceQuery <ProductPlus>;

            foreach (var p in filterAllProducts)
            {
                Assert.AreEqual(ColorPlus.RedPlus, p.SkinColorPlus);
            }
            Assert.IsTrue(filterAllProducts.RequestUri.OriginalString.EndsWith("/GetAllProducts()?$filter=SkinColor eq Microsoft.Test.OData.Services.ODataWCFService.Color'Red'"));

            //FunctionImport, return collection of primitivetype
            var getBossEmailsFunction = TestClientContext.GetBossEmailsPlus(0, 10);
            var emails = getBossEmailsFunction.Execute();

            Assert.IsTrue(getBossEmailsFunction.RequestUri.OriginalString.EndsWith("/GetBossEmails(start=0,count=10)"));

            //FunctionImport, return Collection of primitivetype with enum parameter
            var productsNameQuery = TestClientContext.GetProductsByAccessLevelPlus(AccessLevelPlus.ReadPlus | AccessLevelPlus.ExecutePlus);
            var productsName      = productsNameQuery.Execute();

            Assert.IsTrue(Uri.UnescapeDataString(productsNameQuery.RequestUri.OriginalString).EndsWith("/GetProductsByAccessLevel(accessLevel=Microsoft.Test.OData.Services.ODataWCFService.AccessLevel'Read,Execute')"));
            Assert.IsTrue(productsName.Count() > 0);
        }