public void SingletonQueryUpdateNavigationCollectionPropertyClientTest()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            var queryCompany = this.testClientContext.Company as DataServiceQuerySingle<Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);

            //Load Navigation Property
            var loadDeparments = this.testClientContext.BeginLoadProperty(company, "Departments", null, null).EnqueueWait(this);
            this.testClientContext.EndLoadProperty(loadDeparments);
            Assert.True(company.Departments.Count > 0);

            //Add Navigation Property - Collection
            Random rand = new Random();
            int tmpDepartmentId = rand.Next();
            Department department = new Department()
            {
                DepartmentID = tmpDepartmentId,
                Name = "ID" + tmpDepartmentId
            };
            this.testClientContext.AddToDepartments(department);
            this.testClientContext.AddLink(company, "Departments", department);
            var addDepartmentsLink = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(addDepartmentsLink);

            //Projection with Navigation properties - Select
            var selectCompany = this.testClientContext.Company.Select(c => new Company { CompanyID = c.CompanyID, Departments = c.Departments });
            var selectCompanyAr = selectCompany.BeginGetValue(null, null).EnqueueWait(this);
            var projectedCompany = selectCompany.EndGetValue(selectCompanyAr);
            Assert.True(projectedCompany.Departments.Any(c => c.DepartmentID == tmpDepartmentId));

            //Update EntitySet's Navigation Property - Singleton 
            this.testClientContext.SetLink(department, "Company", company);
            var ar4 = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(ar4);

            //Query(Expand) EntitySet's Navigation Property - Singleton
            var queryDepartment = this.testClientContext.Departments.Expand(d => d.Company).Where(d => d.DepartmentID == tmpDepartmentId) as DataServiceQuery<Department>;
            var queryDepartmentAr = queryDepartment.BeginExecute(null, null).EnqueueWait(this);
            department = queryDepartment.EndExecute(queryDepartmentAr).SingleOrDefault();
            Assert.True(department.Company.CompanyID == company.CompanyID);

            //Delete Navigation Property - EntitySet
            this.testClientContext.DeleteLink(company, "Departments", department);
            var deleteLinkAr = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(deleteLinkAr);

            //Expand Navigation Property - EntitySet
            queryCompany = this.testClientContext.Company.Expand("Departments");
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.Departments.All(c => c.DepartmentID != tmpDepartmentId));

            this.EnqueueTestComplete();
        }
        public async Task DelayQueryOnEntitySetNet45()
        {
            this.testClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

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

            this.testClientContext.AddToProducts(product);
            await this.testClientContext.SaveChangesAsync();

            //Action Bound on EntitySet
            var discountAction = this.testClientContext.Products.Discount(50);

            Assert.True(discountAction.RequestUri.OriginalString.EndsWith("/Products/Microsoft.Test.OData.Services.ODataWCFService.Discount"));
            await discountAction.ExecuteAsync();

            //ByKey
            var queryProduct = this.testClientContext.Products.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }
            });

            Assert.True(queryProduct.RequestUri.OriginalString.EndsWith("/Products(10001)"));
            product = await queryProduct.GetValueAsync();

            Assert.Equal(1, product.UnitPrice);

            //Action Bound on Entity
            var expectedAccessLevel = AccessLevel.ReadWrite | AccessLevel.Execute;
            var accessLevelAction   = this.testClientContext.Products.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }
            }).AddAccessRight(expectedAccessLevel);

            Assert.True(accessLevelAction.RequestUri.OriginalString.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight"));
            var accessLevel = await accessLevelAction.GetValueAsync();

            Assert.True(accessLevel.Value.HasFlag(expectedAccessLevel));

            //Function Bound on Entity and return Collection of Entity
            //Won't execute since ODL doesn't support it now.
            var getProductDetailsAction = this.testClientContext.Products.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }
            }).GetProductDetails(1);
            var getRelatedProductAction = getProductDetailsAction.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }, { "ProductDetailID", 10001 }
            }).GetRelatedProduct();

            Assert.True(getProductDetailsAction.RequestUri.OriginalString.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails(count=1)"));
            Assert.True(getRelatedProductAction.RequestUri.OriginalString.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails(count=1)(ProductID=10001,ProductDetailID=10001)/Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct()"));

            foreach (var pd in await getProductDetailsAction.ExecuteAsync())
            {
                //Check whether GetEnumerator works
                Assert.Equal(5, pd.ProductID);
            }
        }
        public async Task FunctionBoundOnContainedSingleNavigation()
        {
            this.testClientContext = this.CreateWrappedContext <InMemoryEntities>().Context;
            var getActualAmountFunction = this.testClientContext.Accounts.ByKey(new Dictionary <string, object> {
                { "AccountID", 101 }
            }).MyGiftCard.GetActualAmount(1);
            var amount = await getActualAmountFunction.GetValueAsync();

            Assert.True(getActualAmountFunction.RequestUri.OriginalString.EndsWith("/Accounts(101)/MyGiftCard/Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount(bonusRate=1.0)"));
        }
Ejemplo n.º 4
0
        public void UpdateDerivedTypeNavigationOfContainedCollection()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany   = TestClientContext.PublicCompany as DataServiceQuerySingle <Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            //Load Navigation Property
            //Collection
            var loadAssetsAr = TestClientContext.BeginLoadProperty(company, "Assets", null, null).EnqueueWait(this);

            TestClientContext.EndLoadProperty(loadAssetsAr);
            Assert.True((company as PublicCompany).Assets != null);

            //Add Contained Navigation Property - Collection of derived type
            Random rand        = new Random();
            int    tmpAssertId = rand.Next();
            Asset  tmpAssert   = new Asset()
            {
                AssetID = tmpAssertId,
                Name    = tmpAssertId + "Name",
                Number  = tmpAssertId
            };

            TestClientContext.AddRelatedObject(company, "Assets", tmpAssert);
            var addRelatedObjectAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(addRelatedObjectAr);

            //Query contained Navigation Property - Collection of derived type
            queryCompany = TestClientContext.PublicCompany.Expand(c => (c as PublicCompany).Assets) as DataServiceQuerySingle <Company>;
            var queryCompanyAr1 = queryCompany.BeginGetValue(null, null).EnqueueWait(this);

            company = queryCompany.EndGetValue(queryCompanyAr1);
            Assert.True((company as PublicCompany).Assets.Any(a => a.AssetID == tmpAssertId));

            //Delete contained Navigation Property - Collection of derived type
            TestClientContext.DeleteObject(tmpAssert);
            var deleteObjectAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(deleteObjectAr);

            //Expand contained Navigation property - Collection of derived type
            queryCompany   = TestClientContext.PublicCompany.Expand(c => (c as PublicCompany).Assets) as DataServiceQuerySingle <Company>;
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company        = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(!(company as PublicCompany).Assets.Any(a => a.AssetID == tmpAssertId));

            this.EnqueueTestComplete();
        }
Ejemplo n.º 5
0
        public void SingletonQueryUpdatePropertyClientTest()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany   = TestClientContext.Company as DataServiceQuerySingle <Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            Assert.True(company != null);

            //Update Singleton Property and Verify
            company.CompanyCategory = CompanyCategory.Communication;
            company.Name            = "UpdatedName";
            company.Address.City    = "UpdatedCity";
            TestClientContext.UpdateObject(company);
            var updateCompanyAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(updateCompanyAr);

            //Query Singleton Property - Select
            var             queryCompanyCategory   = TestClientContext.Company.Select(c => c.CompanyCategory) as DataServiceQuerySingle <CompanyCategory?>;
            CompanyCategory?companyCategory        = CompanyCategory.Others;
            var             queryCompanyCategoryAr = queryCompanyCategory.BeginGetValue(null, null).EnqueueWait(this);

            companyCategory = queryCompanyCategory.EndGetValue(queryCompanyCategoryAr);
            Assert.True(companyCategory == CompanyCategory.Communication);

            var queryCity   = TestClientContext.CreateQuery <string>("Company/Address/City");
            var queryCityAr = queryCity.BeginExecute(null, null);
            var city        = queryCity.EndExecute(queryCityAr).Single();

            this.EnqueueCallback(() => Assert.True(city == "UpdatedCity"));

            var queryNameAr = TestClientContext.BeginExecute <string>(new Uri("Company/Name", UriKind.Relative), null, null).EnqueueWait(this);
            var name        = TestClientContext.EndExecute <string>(queryNameAr).Single();

            Assert.True(name == "UpdatedName");

            //Projection with properties - Select
            this.TestCompleted = false;
            queryCompany       = TestClientContext.Company.Select(c => new Company {
                CompanyID = c.CompanyID, Address = c.Address, Name = c.Name
            }) as DataServiceQuerySingle <Company>;
            queryCompanyAr = queryCompany.BeginGetValue(null, null);
            company        = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.Name == "UpdatedName");
            Assert.True(company.Departments.Count == 0);
            this.EnqueueTestComplete();
        }
Ejemplo n.º 6
0
        public void UpdateDerivedTypePropertyClientTest()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany   = TestClientContext.PublicCompany;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            //Update DerivedType Property and Verify
            PublicCompany publicCompany = company as PublicCompany;

            publicCompany.Name          = "UpdatedName";
            publicCompany.StockExchange = "Updated StockExchange";
            TestClientContext.UpdateObject(publicCompany);
            var updateCompanyAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(updateCompanyAr);

            //Query Singleton Property - Select
            var queryName   = TestClientContext.PublicCompany.Select(c => c.Name) as DataServiceQuerySingle <string>;
            var queryNameAr = queryName.BeginGetValue(null, null).EnqueueWait(this);
            var name        = queryName.EndGetValue(queryNameAr);

            Assert.True(name == "UpdatedName");

            //Projection with properties of DerivedType
            var queryStockExchange   = TestClientContext.PublicCompany.Select(c => (c as PublicCompany).StockExchange) as DataServiceQuerySingle <string>;
            var queryStockExchangeAr = queryStockExchange.BeginGetValue(null, null).EnqueueWait(this);
            var stockExchange        = queryStockExchange.EndGetValue(queryStockExchangeAr);

            Assert.True(stockExchange == "Updated StockExchange");

            //Projection with properties - Select
            var queryPublicCompany = TestClientContext.PublicCompany.Select(c =>
                                                                            new PublicCompany
            {
                CompanyID     = c.CompanyID,
                Name          = c.Name,
                StockExchange = (c as PublicCompany).StockExchange
            }) as DataServiceQuerySingle <PublicCompany>;
            var queryPublicCompanyAr = queryPublicCompany.BeginGetValue(null, null).EnqueueWait(this);

            publicCompany = queryPublicCompany.EndGetValue(queryPublicCompanyAr);
            Assert.True(publicCompany.Name == "UpdatedName");
            Assert.True(publicCompany.StockExchange == "Updated StockExchange");

            this.EnqueueTestComplete();
        }
Ejemplo n.º 7
0
        public async Task DelayQueryOnEntitySetNet35()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Post a Product
            var product = Product.CreateProduct(10001, "10001", "2", 2.0f, 2, true);
            this.testClientContext.AddToProducts(product);
            await this.testClientContext.SaveChangesAsync();

            //Action Bound on EntitySet and return an EntitySet
            var discountAction = this.testClientContext.Products.Discount(50);
            Assert.True(discountAction.RequestUri.OriginalString.EndsWith("/Products/Microsoft.Test.OData.Services.ODataWCFService.Discount"));
            var ar = discountAction.BeginExecute(null, null).EnqueueWait(this);
            discountAction.EndExecute(ar);

            //Query an Entity
            var queryProduct = this.testClientContext.Products.ByKey(new Dictionary<string, object> { { "ProductID", 10001 } });
            Assert.True(queryProduct.RequestUri.OriginalString.EndsWith("/Products(10001)"));
            queryProduct.BeginGetValue(
                ar1 =>
                {
                    product = queryProduct.EndGetValue(ar1);
                    Assert.Equal(1, product.UnitPrice);
                }, queryProduct).EnqueueWait(this);

            //Action Bound on Entity and return an Enum
            var expectedAccessLevel = AccessLevel.ReadWrite | AccessLevel.Execute;
            var accessLevelAction = this.testClientContext.Products.ByKey(new Dictionary<string, object> { { "ProductID", 10001 } }).AddAccessRight(expectedAccessLevel);
            Assert.True(accessLevelAction.RequestUri.OriginalString.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight"));
            var ar2 = accessLevelAction.BeginGetValue(null, null).EnqueueWait(this);
            var accessLevel = accessLevelAction.EndGetValue(ar2);
            Assert.True(accessLevel.Value.HasFlag(expectedAccessLevel));

            //Function Bound on Entity and return Collection of Entity
            //Won't execute since ODL doesn't support it now.
            var getProductDetailsFunction = this.testClientContext.Products.ByKey(new Dictionary<string, object> { { "ProductID", 10001 } }).GetProductDetails(1);
            var getRelatedProductAction = getProductDetailsFunction.ByKey(new Dictionary<string, object> { { "ProductID", 10001 }, { "ProductDetailID", 10001 } }).GetRelatedProduct();
            Assert.True(getProductDetailsFunction.RequestUri.OriginalString.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails(count=1)"));
            Assert.True(getRelatedProductAction.RequestUri.OriginalString.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails(count=1)(ProductID=10001,ProductDetailID=10001)/Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct()"));

            var ar3 = getProductDetailsFunction.BeginExecute(null, null).EnqueueWait(this);
            var productDetails = getProductDetailsFunction.EndExecute(ar3);
            foreach (var pd in productDetails)
            {
                //Check whether GetEnumerator works
                Assert.Equal(5, pd.ProductID);
            }
        }
Ejemplo n.º 8
0
        public void SingletonQueryUpdateNavigationSingleEntityPropertyClientTest()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            Company company        = null;
            var     queryCompany   = TestClientContext.Company.Expand("CoreDepartment");
            var     queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);

            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.CoreDepartment != null);

            //Single Entity
            company.CoreDepartment = null;
            var ar15 = TestClientContext.BeginLoadProperty(company, "CoreDepartment", null, null).EnqueueWait(this);

            TestClientContext.EndLoadProperty(ar15);
            Assert.True(company.CoreDepartment != null);

            Random     rand = new Random();
            int        tmpCoreDepartmentID = rand.Next();
            Department coreDepartment      = new Department()
            {
                DepartmentID = tmpCoreDepartmentID,
                Name         = "ID" + tmpCoreDepartmentID
            };

            TestClientContext.AddToDepartments(coreDepartment);
            TestClientContext.AddLink(company, "Departments", coreDepartment);
            var ar1 = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(ar1);

            //Update Navigation Property - Single Entity
            TestClientContext.SetLink(company, "CoreDepartment", coreDepartment);
            var ar3 = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(ar3);

            //Projection with Navigation properties - Select
            queryCompany = TestClientContext.Company.Select(c => new Company {
                CompanyID = c.CompanyID, CoreDepartment = c.CoreDepartment
            }) as DataServiceQuerySingle <Company>;
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company        = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.CoreDepartment.DepartmentID == tmpCoreDepartmentID);
            this.EnqueueTestComplete();
        }
        public void SingletonQueryUpdatePropertyClientTest()
        {
            TestClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            //Query Singleton            
            var queryCompany = TestClientContext.Company as DataServiceQuerySingle<Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.IsTrue(company != null);

            //Update Singleton Property and Verify
            company.CompanyCategory = CompanyCategory.Communication;
            company.Name = "UpdatedName";
            company.Address.City = "UpdatedCity";
            TestClientContext.UpdateObject(company);
            var updateCompanyAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            TestClientContext.EndSaveChanges(updateCompanyAr);

            //Query Singleton Property - Select
            var queryCompanyCategory = TestClientContext.Company.Select(c => c.CompanyCategory) as DataServiceQuerySingle<CompanyCategory?>;
            CompanyCategory? companyCategory = CompanyCategory.Others;
            var queryCompanyCategoryAr = queryCompanyCategory.BeginGetValue(null, null).EnqueueWait(this);
            companyCategory = queryCompanyCategory.EndGetValue(queryCompanyCategoryAr);
            Assert.IsTrue(companyCategory == CompanyCategory.Communication);

            var queryCity = TestClientContext.CreateQuery<string>("Company/Address/City");
            var queryCityAr = queryCity.BeginExecute(null, null);
            var city = queryCity.EndExecute(queryCityAr).Single();
            this.EnqueueCallback(() => Assert.IsTrue(city == "UpdatedCity"));

            var queryNameAr = TestClientContext.BeginExecute<string>(new Uri("Company/Name", UriKind.Relative), null, null).EnqueueWait(this);
            var name = TestClientContext.EndExecute<string>(queryNameAr).Single();
            Assert.IsTrue(name == "UpdatedName");

            //Projection with properties - Select
            this.TestCompleted = false;
            queryCompany = TestClientContext.Company.Select(c => new Company { CompanyID = c.CompanyID, Address = c.Address, Name = c.Name }) as DataServiceQuerySingle<Company>;
            queryCompanyAr = queryCompany.BeginGetValue(null, null);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.IsTrue(company.Name == "UpdatedName");
            Assert.IsTrue(company.Departments.Count == 0);
            this.EnqueueTestComplete();
        }
Ejemplo n.º 10
0
        public void DerivedTypeSingletonClientTest()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany   = TestClientContext.PublicCompany as DataServiceQuerySingle <Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            //Singleton
            var loadLabourUnionAr = TestClientContext.BeginLoadProperty(company, "LabourUnion", null, null).EnqueueWait(this);

            TestClientContext.EndLoadProperty(loadLabourUnionAr);
            Assert.True((company as PublicCompany).LabourUnion != null);

            //Expand Navigation Property - Singleton
            queryCompany   = TestClientContext.PublicCompany.Expand(c => (c as PublicCompany).Club) as DataServiceQuerySingle <Company>;
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company        = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True((company as PublicCompany).Club != null);

            //Update Navigation property of derived Type - Singleton
            var labourUnion = (company as PublicCompany).LabourUnion;

            labourUnion.Name = "UpdatedLabourUnionName";
            TestClientContext.UpdateRelatedObject(company, "LabourUnion", labourUnion);
            var updateRelatedObjectAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(updateRelatedObjectAr);

            //Projecton with Navigation property - singletonof derived type.
            var queryPublicCompany = TestClientContext.PublicCompany.Select(c =>
                                                                            new PublicCompany {
                CompanyID = c.CompanyID, LabourUnion = (c as PublicCompany).LabourUnion
            }) as DataServiceQuerySingle <PublicCompany>;
            var queryPublicCompanyAr = queryPublicCompany.BeginGetValue(null, null).EnqueueWait(this);
            var publicCompany        = queryPublicCompany.EndGetValue(queryPublicCompanyAr);

            Assert.True(publicCompany.LabourUnion != null);

            this.EnqueueTestComplete();
        }
Ejemplo n.º 11
0
        public void UpdateDerivedTypeNavigationOfContainedSingleEntity()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany   = TestClientContext.PublicCompany;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            //Load Navigation Property
            //Single Enity
            var loadClubAr = TestClientContext.BeginLoadProperty(company, "Club", null, null).EnqueueWait(this);

            TestClientContext.EndLoadProperty(loadClubAr);
            Assert.True((company as PublicCompany).Club != null);

            //Updated Conatined Navigation Property - SingleEntity of derived type
            var club = (company as PublicCompany).Club;

            club.Name = "UpdatedClubName";
            TestClientContext.UpdateRelatedObject(company, "Club", club);
            var updateRelatedObjectAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(updateRelatedObjectAr);

            //Projecton with Contained Navigation Property - Single Entity of derived type
            var queryPublicCompany = TestClientContext.PublicCompany.Select(c =>
                                                                            new PublicCompany {
                CompanyID = c.CompanyID, Club = (c as PublicCompany).Club
            }) as DataServiceQuerySingle <PublicCompany>;
            var queryPublicCompany2Ar = queryPublicCompany.BeginGetValue(null, null).EnqueueWait(this);
            var publicCompany         = queryPublicCompany.EndGetValue(queryPublicCompany2Ar);

            Assert.True(publicCompany.Club.Name == "UpdatedClubName");

            this.EnqueueTestComplete();
        }
        public void UpdateDerivedTypeNavigationOfContainedSingleEntity()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany = this.testClientContext.PublicCompany;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);

            //Load Navigation Property 
            //Single Enity
            var loadClubAr = this.testClientContext.BeginLoadProperty(company, "Club", null, null).EnqueueWait(this);
            this.testClientContext.EndLoadProperty(loadClubAr);
            Assert.True((company as PublicCompany).Club != null);

            //Updated Conatined Navigation Property - SingleEntity of derived type
            var club = (company as PublicCompany).Club;
            club.Name = "UpdatedClubName";
            this.testClientContext.UpdateRelatedObject(company, "Club", club);
            var updateRelatedObjectAr = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(updateRelatedObjectAr);

            //Projecton with Contained Navigation Property - Single Entity of derived type
            var queryPublicCompany = this.testClientContext.PublicCompany.Select(c =>
                new PublicCompany { CompanyID = c.CompanyID, Club = (c as PublicCompany).Club });
            var queryPublicCompany2Ar = queryPublicCompany.BeginGetValue(null, null).EnqueueWait(this);
            var publicCompany = queryPublicCompany.EndGetValue(queryPublicCompany2Ar);
            Assert.True(publicCompany.Club.Name == "UpdatedClubName");

            this.EnqueueTestComplete();
        }
Ejemplo n.º 13
0
        public async Task DelayQueryOnEntitySetNet35()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Post a Product
            var product = Product.CreateProduct(10001, "10001", "2", 2.0f, 2, true);

            TestClientContext.AddToProducts(product);
            await TestClientContext.SaveChangesAsync();

            //Action Bound on EntitySet and return an EntitySet
            var discountAction = TestClientContext.Products.Discount(50);

            Assert.EndsWith("/Products/Microsoft.Test.OData.Services.ODataWCFService.Discount", discountAction.RequestUri.OriginalString);
            var ar = discountAction.BeginExecute(null, null).EnqueueWait(this);

            discountAction.EndExecute(ar);

            //Query an Entity
            var queryProduct = TestClientContext.Products.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }
            });

            Assert.EndsWith("/Products(10001)", queryProduct.RequestUri.OriginalString);
            queryProduct.BeginGetValue(
                (ar1) =>
            {
                product = queryProduct.EndGetValue(ar1);
                Assert.Equal(1, product.UnitPrice);
            }, queryProduct).EnqueueWait(this);

            //Action Bound on Entity and return an Enum
            var expectedAccessLevel = AccessLevel.ReadWrite | AccessLevel.Execute;
            var accessLevelAction   = TestClientContext.Products.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }
            }).AddAccessRight(expectedAccessLevel);

            Assert.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight", accessLevelAction.RequestUri.OriginalString);
            var ar2         = accessLevelAction.BeginGetValue(null, null).EnqueueWait(this);
            var accessLevel = accessLevelAction.EndGetValue(ar2);

            Assert.True(accessLevel.Value.HasFlag(expectedAccessLevel));

            //Function Bound on Entity and return Collection of Entity
            //Won't execute since ODL doesn't support it now.
            var getProductDetailsFunction = TestClientContext.Products.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }
            }).GetProductDetails(1);
            var getRelatedProductAction = getProductDetailsFunction.ByKey(new Dictionary <string, object> {
                { "ProductID", 10001 }, { "ProductDetailID", 10001 }
            }).GetRelatedProduct();

            Assert.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails(count=1)", getProductDetailsFunction.RequestUri.OriginalString);
            Assert.EndsWith("/Products(10001)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails(count=1)(ProductID=10001,ProductDetailID=10001)/Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct()", getRelatedProductAction.RequestUri.OriginalString);

            var ar3            = getProductDetailsFunction.BeginExecute(null, null).EnqueueWait(this);
            var productDetails = getProductDetailsFunction.EndExecute(ar3);

            foreach (var pd in productDetails)
            {
                //Check whether GetEnumerator works
                Assert.Equal(5, pd.ProductID);
            }
        }
Ejemplo n.º 14
0
 public async Task FunctionBoundOnContainedSingleNavigation()
 {
     this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
     var getActualAmountFunction = this.testClientContext.Accounts.ByKey(new Dictionary<string, object> { { "AccountID", 101 } }).MyGiftCard.GetActualAmount(1);
     var amount = await getActualAmountFunction.GetValueAsync();
     Assert.True(getActualAmountFunction.RequestUri.OriginalString.EndsWith("/Accounts(101)/MyGiftCard/Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount(bonusRate=1.0)"));
 }
        public void SingletonQueryUpdateNavigationSingletonPropertyClientTest()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            var queryCompany = this.testClientContext.Company as DataServiceQuerySingle<Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);

            //Query Singleton again with Execute
            var queryVipCustomerAr = this.testClientContext.BeginExecute<Customer>(new Uri("VipCustomer", UriKind.Relative), null, null).EnqueueWait(this);
            var vipCustomer = this.testClientContext.EndExecute<Customer>(queryVipCustomerAr).Single();
            Assert.True(vipCustomer != null);

            //Update Singleton's Navigation property - Singleton
            vipCustomer.City = "UpdatedCity";
            this.testClientContext.UpdateRelatedObject(company, "VipCustomer", vipCustomer);
            var ar6 = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(ar6);

            //Expand Navigation Property - Singleton
            company.VipCustomer = null;
            queryCompany = this.testClientContext.Company.Expand(c => c.VipCustomer);
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer.City == "UpdatedCity");

            //Update Navigation Property - Delete the Singleton navigation
            this.testClientContext.SetLink(company, "VipCustomer", null);
            var ar7 = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(ar7);

            //Expand Navigation Property using name- Singleton
            company.VipCustomer = null;
            queryCompany = this.testClientContext.Company.Expand("VipCustomer");
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer == null);

            //Update Navigation Property - Singleton
            this.testClientContext.SetLink(company, "VipCustomer", vipCustomer);
            var ar8 = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(ar8);

            //LoadProperty Navigation Property - Singleton
            company.VipCustomer = null;
            var ar13 = this.testClientContext.BeginLoadProperty(company, "VipCustomer", null, null).EnqueueWait(this);
            this.testClientContext.EndLoadProperty(ar13);
            Assert.True(company.VipCustomer != null);

            //Expand Navigation Property - Singleton
            company.VipCustomer = null;
            queryCompany = this.testClientContext.Company.Expand(c => c.VipCustomer);
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer != null);

            //Query Singleton's Navigation Property - Singleton
            queryCompany = this.testClientContext.Company.Select(c => new Company { CompanyID = c.CompanyID, VipCustomer = c.VipCustomer });
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer != null);

            this.EnqueueTestComplete();
        }
        public void SingletonQueryUpdateNavigationSingleEntityPropertyClientTest()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            var queryCompany = this.testClientContext.Company.Expand("CoreDepartment");
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            Company company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.CoreDepartment != null);

            //Single Entity
            company.CoreDepartment = null;
            var ar15 = this.testClientContext.BeginLoadProperty(company, "CoreDepartment", null, null).EnqueueWait(this);
            this.testClientContext.EndLoadProperty(ar15);
            Assert.True(company.CoreDepartment != null);

            Random rand = new Random();
            int tmpCoreDepartmentId = rand.Next();
            Department coreDepartment = new Department()
            {
                DepartmentID = tmpCoreDepartmentId,
                Name = "ID" + tmpCoreDepartmentId
            };

            this.testClientContext.AddToDepartments(coreDepartment);
            this.testClientContext.AddLink(company, "Departments", coreDepartment);
            var ar1 = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(ar1);

            //Update Navigation Property - Single Entity
            this.testClientContext.SetLink(company, "CoreDepartment", coreDepartment);
            var ar3 = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(ar3);

            //Projection with Navigation properties - Select
            queryCompany = this.testClientContext.Company.Select(c => new Company { CompanyID = c.CompanyID, CoreDepartment = c.CoreDepartment });
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.CoreDepartment.DepartmentID == tmpCoreDepartmentId);
            this.EnqueueTestComplete();
        }
        public void UpdateDerivedTypePropertyClientTest()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany = this.testClientContext.PublicCompany;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);

            //Update DerivedType Property and Verify
            PublicCompany publicCompany = company as PublicCompany;
            publicCompany.Name = "UpdatedName";
            publicCompany.StockExchange = "Updated StockExchange";
            this.testClientContext.UpdateObject(publicCompany);
            var updateCompanyAr = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(updateCompanyAr);

            //Query Singleton Property - Select            
            var queryName = this.testClientContext.PublicCompany.Select(c => c.Name);
            var queryNameAr = queryName.BeginGetValue(null, null).EnqueueWait(this);
            var name = queryName.EndGetValue(queryNameAr);
            Assert.True(name == "UpdatedName");

            //Projection with properties of DerivedType
            var queryStockExchange = this.testClientContext.PublicCompany.Select(c => (c as PublicCompany).StockExchange);
            var queryStockExchangeAr = queryStockExchange.BeginGetValue(null, null).EnqueueWait(this);
            var stockExchange = queryStockExchange.EndGetValue(queryStockExchangeAr);
            Assert.True(stockExchange == "Updated StockExchange");

            //Projection with properties - Select
            var queryPublicCompany = this.testClientContext.PublicCompany.Select(c =>
                new PublicCompany
                {
                    CompanyID = c.CompanyID,
                    Name = c.Name,
                    StockExchange = (c as PublicCompany).StockExchange
                });
            var queryPublicCompanyAr = queryPublicCompany.BeginGetValue(null, null).EnqueueWait(this);
            publicCompany = queryPublicCompany.EndGetValue(queryPublicCompanyAr);
            Assert.True(publicCompany.Name == "UpdatedName");
            Assert.True(publicCompany.StockExchange == "Updated StockExchange");

            this.EnqueueTestComplete();
        }
        public void UpdateDerivedTypeNavigationOfContainedCollection()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany = this.testClientContext.PublicCompany as DataServiceQuerySingle<Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);

            //Load Navigation Property
            //Collection            
            var loadAssetsAr = this.testClientContext.BeginLoadProperty(company, "Assets", null, null).EnqueueWait(this);
            this.testClientContext.EndLoadProperty(loadAssetsAr);
            Assert.True((company as PublicCompany).Assets != null);

            //Add Contained Navigation Property - Collection of derived type
            Random rand = new Random();
            int tmpAssertId = rand.Next();
            Asset tmpAssert = new Asset()
            {
                AssetID = tmpAssertId,
                Name = tmpAssertId + "Name",
                Number = tmpAssertId
            };
            this.testClientContext.AddRelatedObject(company, "Assets", tmpAssert);
            var addRelatedObjectAr = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(addRelatedObjectAr);

            //Query contained Navigation Property - Collection of derived type
            queryCompany = this.testClientContext.PublicCompany.Expand(c => (c as PublicCompany).Assets);
            var queryCompanyAr1 = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr1);
            Assert.True((company as PublicCompany).Assets.Any(a => a.AssetID == tmpAssertId));

            //Delete contained Navigation Property - Collection of derived type
            this.testClientContext.DeleteObject(tmpAssert);
            var deleteObjectAr = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(deleteObjectAr);

            //Expand contained Navigation property - Collection of derived type
            queryCompany = this.testClientContext.PublicCompany.Expand(c => (c as PublicCompany).Assets);
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True((company as PublicCompany).Assets.All(a => a.AssetID != tmpAssertId));

            this.EnqueueTestComplete();
        }
        public void DelayQueryOnSingletonNet35()
        {
            this.testClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany1 = this.testClientContext.Company;
            var ar            = queryCompany1.BeginGetValue(null, null).EnqueueWait(this);
            var company       = queryCompany1.EndGetValue(ar);

            Assert.NotNull(company);

            //LoadProperty
            var ar2 = this.testClientContext.BeginLoadProperty(company, "Departments", null, null);

            this.testClientContext.EndLoadProperty(ar2);
            Assert.NotNull(company.Departments);

            //Query Property
            var queryName = this.testClientContext.Company.Select(c => c.Name);
            var ar3       = queryName.BeginGetValue(null, null).EnqueueWait(this);
            var name      = queryName.EndGetValue(ar3);

            Assert.Equal(company.Name, name);

            //Projection
            var companyQuery = this.testClientContext.Company.Select(c => new Company()
            {
                Name = c.Name, Address = c.Address
            });
            var ar4      = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company2 = companyQuery.EndGetValue(ar4);

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$select=Name,Address"));
            Assert.NotNull(company2.Address);

            //Expand
            companyQuery = this.testClientContext.Company.Expand(c => c.VipCustomer.Company);
            var ar5      = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company3 = companyQuery.EndGetValue(ar5);

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=VipCustomer($expand=Company)"));
            Assert.NotNull(company);

            //Projection with Navigation
            companyQuery = this.testClientContext.Company.Select(c => new Company()
            {
                Name = c.Name, Address = c.Address, Departments = c.Departments
            });
            var ar6      = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company4 = companyQuery.EndGetValue(ar6);

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=Departments&$select=Name,Address"));
            Assert.NotNull(company4.Address);

            //Query navigation property which is an collection
            var employeesQuery = this.testClientContext.Company.Employees;
            var ar7            = employeesQuery.BeginExecute(null, null).EnqueueWait(this);
            var employees      = employeesQuery.EndExecute(ar7);

            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees"));
            Assert.NotNull(employees);

            //Query Navigation Property which is an single entity
            companyQuery = this.testClientContext.Company.VipCustomer.Company;
            var ar8      = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company5 = companyQuery.EndGetValue(ar8);

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Company"));
            Assert.NotNull(company5);

            //Query navigation property which is from a singleton
            var coreDepartmentQuery = this.testClientContext.Company.CoreDepartment;
            var ar9            = coreDepartmentQuery.BeginGetValue(null, null).EnqueueWait(this);
            var coreDepartment = coreDepartmentQuery.EndGetValue(ar9);

            Assert.True(coreDepartmentQuery.RequestUri.OriginalString.EndsWith("/Company/CoreDepartment"));
            Assert.NotNull(coreDepartment);

            //QueryOption on navigation property
            employeesQuery = this.testClientContext.Company.Employees.Where(e => e.PersonID > 0) as DataServiceQuery <Employee>;
            var ar10 = employeesQuery.BeginExecute(null, null).EnqueueWait(this);

            employees = employeesQuery.EndExecute(ar10);
            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees?$filter=PersonID gt 0"));
            Assert.NotNull(employees);

            //Function Bound on Singleton
            var getEmployeesCountQuery = this.testClientContext.Company.GetEmployeesCount();
            var ar11  = getEmployeesCountQuery.BeginGetValue(null, null).EnqueueWait(this);
            var count = getEmployeesCountQuery.EndGetValue(ar11);

            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Function Bound on Singleton
            queryCompany1 = this.testClientContext.Company;
            var ar12 = queryCompany1.BeginGetValue(null, null).EnqueueWait(this);

            company = queryCompany1.EndGetValue(ar12);

            getEmployeesCountQuery = company.GetEmployeesCount();
            var ar13 = getEmployeesCountQuery.BeginGetValue(null, null).EnqueueWait(this);

            count = getEmployeesCountQuery.EndGetValue(ar13);
            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Query Action bound on Navigation Property
            var getHomeAddressQuery = this.testClientContext.Company.VipCustomer.GetHomeAddress();
            var ar14 = getHomeAddressQuery.BeginGetValue(null, null).EnqueueWait(this);

            getHomeAddressQuery.EndGetValue(ar14);
            Assert.True(getHomeAddressQuery.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress()"));
        }
Ejemplo n.º 20
0
        public void SingletonQueryUpdateNavigationCollectionPropertyClientTest()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            var queryCompany   = TestClientContext.Company as DataServiceQuerySingle <Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            //Load Navigation Property
            var loadDeparments = TestClientContext.BeginLoadProperty(company, "Departments", null, null).EnqueueWait(this);

            TestClientContext.EndLoadProperty(loadDeparments);
            Assert.True(company.Departments.Count > 0);

            //Add Navigation Property - Collection
            Random     rand            = new Random();
            int        tmpDepartmentID = rand.Next();
            Department department      = new Department()
            {
                DepartmentID = tmpDepartmentID,
                Name         = "ID" + tmpDepartmentID
            };

            TestClientContext.AddToDepartments(department);
            TestClientContext.AddLink(company, "Departments", department);
            var addDepartmentsLink = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(addDepartmentsLink);

            //Projection with Navigation properties - Select
            var selectCompany = TestClientContext.Company.Select(c => new Company {
                CompanyID = c.CompanyID, Departments = c.Departments
            }) as DataServiceQuerySingle <Company>;
            var selectCompanyAr  = selectCompany.BeginGetValue(null, null).EnqueueWait(this);
            var projectedCompany = selectCompany.EndGetValue(selectCompanyAr);

            Assert.True(projectedCompany.Departments.Any(c => c.DepartmentID == tmpDepartmentID));

            //Update EntitySet's Navigation Property - Singleton
            TestClientContext.SetLink(department, "Company", company);
            var ar4 = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(ar4);

            //Query(Expand) EntitySet's Navigation Property - Singleton
            var queryDepartment   = TestClientContext.Departments.Expand(d => d.Company).Where(d => d.DepartmentID == tmpDepartmentID) as DataServiceQuery <Department>;
            var queryDepartmentAr = queryDepartment.BeginExecute(null, null).EnqueueWait(this);

            department = queryDepartment.EndExecute(queryDepartmentAr).SingleOrDefault();
            Assert.True(department.Company.CompanyID == company.CompanyID);

            //Delete Navigation Property - EntitySet
            TestClientContext.DeleteLink(company, "Departments", department);
            var deleteLinkAr = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(deleteLinkAr);

            //Expand Navigation Property - EntitySet
            queryCompany   = TestClientContext.Company.Expand("Departments");
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company        = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(!company.Departments.Any(c => c.DepartmentID == tmpDepartmentID));

            this.EnqueueTestComplete();
        }
        public void DerivedTypeSingletonClientTest()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany = this.testClientContext.PublicCompany as DataServiceQuerySingle<Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany.EndGetValue(queryCompanyAr);

            //Singleton
            var loadLabourUnionAr = this.testClientContext.BeginLoadProperty(company, "LabourUnion", null, null).EnqueueWait(this);
            this.testClientContext.EndLoadProperty(loadLabourUnionAr);
            Assert.True((company as PublicCompany).LabourUnion != null);

            //Expand Navigation Property - Singleton
            queryCompany = this.testClientContext.PublicCompany.Expand(c => (c as PublicCompany).Club);
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True((company as PublicCompany).Club != null);

            //Update Navigation property of derived Type - Singleton
            var labourUnion = (company as PublicCompany).LabourUnion;
            labourUnion.Name = "UpdatedLabourUnionName";
            this.testClientContext.UpdateRelatedObject(company, "LabourUnion", labourUnion);
            var updateRelatedObjectAr = this.testClientContext.BeginSaveChanges(null, null).EnqueueWait(this);
            this.testClientContext.EndSaveChanges(updateRelatedObjectAr);

            //Projecton with Navigation property - singletonof derived type.            
            var queryPublicCompany = this.testClientContext.PublicCompany.Select(c =>
                new PublicCompany { CompanyID = c.CompanyID, LabourUnion = (c as PublicCompany).LabourUnion });
            var queryPublicCompanyAr = queryPublicCompany.BeginGetValue(null, null).EnqueueWait(this);
            var publicCompany = queryPublicCompany.EndGetValue(queryPublicCompanyAr);
            Assert.True(publicCompany.LabourUnion != null);

            this.EnqueueTestComplete();
        }
        public async Task DelayQueryOnSingletonNet45()
        {
            this.testClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            var company = await this.testClientContext.Company.GetValueAsync();

            Assert.NotNull(company);

            //LoadProperty
            await this.testClientContext.LoadPropertyAsync(company, "Departments");

            Assert.NotNull(company.Departments);

            //Query Property
            var name = await this.testClientContext.Company.Select(c => c.Name).GetValueAsync();

            Assert.Equal(company.Name, name);

            //Projection
            var companyQuery = this.testClientContext.Company.Select(c => new Company()
            {
                Name = c.Name, Address = c.Address
            });
            var company2 = await companyQuery.GetValueAsync();

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$select=Name,Address"));
            Assert.NotNull(company2.Address);

            //Expand
            companyQuery = this.testClientContext.Company.Expand(c => c.VipCustomer.Company);
            var company3 = await companyQuery.GetValueAsync();

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=VipCustomer($expand=Company)"));
            Assert.NotNull(company);

            //Projection with Navigation
            companyQuery = this.testClientContext.Company.Select(c => new Company()
            {
                Name = c.Name, Address = c.Address, Departments = c.Departments
            });
            await companyQuery.GetValueAsync();

            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=Departments&$select=Name,Address"));
            Assert.NotNull(company2.Address);

            //Query navigation property which is an collection
            var employeesQuery = this.testClientContext.Company.Employees;
            var employees      = await employeesQuery.ExecuteAsync();

            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees"));
            Assert.NotNull(employees);

            //Query Navigation Property which is an single entity
            var company4Query = this.testClientContext.Company.VipCustomer.Company;
            var company4      = await company4Query.GetValueAsync();

            Assert.True(company4Query.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Company"));
            Assert.NotNull(company4Query);

            //Query navigation property which is from a singleton
            var coreDepartmentQuery = this.testClientContext.Company.CoreDepartment;
            var coreDepartment      = await coreDepartmentQuery.GetValueAsync();

            Assert.True(coreDepartmentQuery.RequestUri.OriginalString.EndsWith("/Company/CoreDepartment"));
            Assert.NotNull(coreDepartment);

            //QueryOption on navigation property
            employeesQuery = this.testClientContext.Company.Employees.Where(e => e.PersonID > 0) as DataServiceQuery <Employee>;
            employees      = await employeesQuery.ExecuteAsync();

            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees?$filter=PersonID gt 0"));
            Assert.NotNull(employees);

            //Function Bound on Singleton
            var getEmployeesCountQuery = this.testClientContext.Company.GetEmployeesCount();
            var count = await getEmployeesCountQuery.GetValueAsync();

            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Function Bound on Singleton
            var company5 = await this.testClientContext.Company.GetValueAsync();

            getEmployeesCountQuery = company5.GetEmployeesCount();
            count = await getEmployeesCountQuery.GetValueAsync();

            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Query Action bound on Navigation Property, also on baseType
            var getHomeAddressQuery = this.testClientContext.Company.VipCustomer.GetHomeAddress();
            var homeAddress         = await getHomeAddressQuery.GetValueAsync();

            Assert.True(getHomeAddressQuery.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress()"));
            Assert.NotNull(homeAddress);
        }
Ejemplo n.º 23
0
        public void DelayQueryOnSingletonNet35()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            //Query Singleton
            var queryCompany1 = this.testClientContext.Company;
            var ar = queryCompany1.BeginGetValue(null, null).EnqueueWait(this);
            var company = queryCompany1.EndGetValue(ar);
            Assert.NotNull(company);

            //LoadProperty
            var ar2 = this.testClientContext.BeginLoadProperty(company, "Departments", null, null);
            this.testClientContext.EndLoadProperty(ar2);
            Assert.NotNull(company.Departments);

            //Query Property
            var queryName = this.testClientContext.Company.Select(c => c.Name);
            var ar3 = queryName.BeginGetValue(null, null).EnqueueWait(this);
            var name = queryName.EndGetValue(ar3);
            Assert.Equal(company.Name, name);

            //Projection
            var companyQuery = this.testClientContext.Company.Select(c => new Company() { Name = c.Name, Address = c.Address });
            var ar4 = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company2 = companyQuery.EndGetValue(ar4);
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$select=Name,Address"));
            Assert.NotNull(company2.Address);

            //Expand
            companyQuery = this.testClientContext.Company.Expand(c => c.VipCustomer.Company);
            var ar5 = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company3 = companyQuery.EndGetValue(ar5);
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=VipCustomer($expand=Company)"));
            Assert.NotNull(company);

            //Projection with Navigation
            companyQuery = this.testClientContext.Company.Select(c => new Company() { Name = c.Name, Address = c.Address, Departments = c.Departments });
            var ar6 = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company4 = companyQuery.EndGetValue(ar6);
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=Departments&$select=Name,Address"));
            Assert.NotNull(company4.Address);

            //Query navigation property which is an collection
            var employeesQuery = this.testClientContext.Company.Employees;
            var ar7 = employeesQuery.BeginExecute(null, null).EnqueueWait(this);
            var employees = employeesQuery.EndExecute(ar7);
            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees"));
            Assert.NotNull(employees);

            //Query Navigation Property which is an single entity
            companyQuery = this.testClientContext.Company.VipCustomer.Company;
            var ar8 = companyQuery.BeginGetValue(null, null).EnqueueWait(this);
            var company5 = companyQuery.EndGetValue(ar8);
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Company"));
            Assert.NotNull(company5);

            //Query navigation property which is from a singleton
            var coreDepartmentQuery = this.testClientContext.Company.CoreDepartment;
            var ar9 = coreDepartmentQuery.BeginGetValue(null, null).EnqueueWait(this);
            var coreDepartment = coreDepartmentQuery.EndGetValue(ar9);
            Assert.True(coreDepartmentQuery.RequestUri.OriginalString.EndsWith("/Company/CoreDepartment"));
            Assert.NotNull(coreDepartment);

            //QueryOption on navigation property
            employeesQuery = this.testClientContext.Company.Employees.Where(e => e.PersonID > 0) as DataServiceQuery<Employee>;
            var ar10 = employeesQuery.BeginExecute(null, null).EnqueueWait(this);
            employees = employeesQuery.EndExecute(ar10);
            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees?$filter=PersonID gt 0"));
            Assert.NotNull(employees);

            //Function Bound on Singleton
            var getEmployeesCountQuery = this.testClientContext.Company.GetEmployeesCount();
            var ar11 = getEmployeesCountQuery.BeginGetValue(null, null).EnqueueWait(this);
            var count = getEmployeesCountQuery.EndGetValue(ar11);
            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Function Bound on Singleton
            queryCompany1 = this.testClientContext.Company;
            var ar12 = queryCompany1.BeginGetValue(null, null).EnqueueWait(this);
            company = queryCompany1.EndGetValue(ar12);

            getEmployeesCountQuery = company.GetEmployeesCount();
            var ar13 = getEmployeesCountQuery.BeginGetValue(null, null).EnqueueWait(this);
            count = getEmployeesCountQuery.EndGetValue(ar13);
            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Query Action bound on Navigation Property
            var getHomeAddressQuery = this.testClientContext.Company.VipCustomer.GetHomeAddress();
            var ar14 = getHomeAddressQuery.BeginGetValue(null, null).EnqueueWait(this);
            getHomeAddressQuery.EndGetValue(ar14);
            Assert.True(getHomeAddressQuery.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress()"));
        }
Ejemplo n.º 24
0
        public void SingletonQueryUpdateNavigationSingletonPropertyClientTest()
        {
            TestClientContext             = this.CreateWrappedContext <InMemoryEntities>().Context;
            TestClientContext.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;

            var queryCompany   = TestClientContext.Company as DataServiceQuerySingle <Company>;
            var queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            var company        = queryCompany.EndGetValue(queryCompanyAr);

            //Query Singleton again with Execute
            var queryVipCustomerAr = TestClientContext.BeginExecute <Customer>(new Uri("VipCustomer", UriKind.Relative), null, null).EnqueueWait(this);
            var vipCustomer        = TestClientContext.EndExecute <Customer>(queryVipCustomerAr).Single();

            Assert.True(vipCustomer != null);

            //Update Singleton's Navigation property - Singleton
            vipCustomer.City = "UpdatedCity";
            TestClientContext.UpdateRelatedObject(company, "VipCustomer", vipCustomer);
            var ar6 = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(ar6);

            //Expand Navigation Property - Singleton
            company.VipCustomer = null;
            queryCompany        = TestClientContext.Company.Expand(c => c.VipCustomer);
            queryCompanyAr      = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company             = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer.City == "UpdatedCity");

            //Update Navigation Property - Delete the Singleton navigation
            TestClientContext.SetLink(company, "VipCustomer", null);
            var ar7 = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(ar7);

            //Expand Navigation Property using name- Singleton
            company.VipCustomer = null;
            queryCompany        = TestClientContext.Company.Expand("VipCustomer");
            queryCompanyAr      = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company             = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer == null);

            //Update Navigation Property - Singleton
            TestClientContext.SetLink(company, "VipCustomer", vipCustomer);
            var ar8 = TestClientContext.BeginSaveChanges(null, null).EnqueueWait(this);

            TestClientContext.EndSaveChanges(ar8);

            //LoadProperty Navigation Property - Singleton
            company.VipCustomer = null;
            var ar13 = TestClientContext.BeginLoadProperty(company, "VipCustomer", null, null).EnqueueWait(this);

            TestClientContext.EndLoadProperty(ar13);
            Assert.True(company.VipCustomer != null);

            //Expand Navigation Property - Singleton
            company.VipCustomer = null;
            queryCompany        = TestClientContext.Company.Expand(c => c.VipCustomer);
            queryCompanyAr      = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company             = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer != null);

            //Query Singleton's Navigation Property - Singleton
            queryCompany = TestClientContext.Company.Select(c => new Company {
                CompanyID = c.CompanyID, VipCustomer = c.VipCustomer
            }) as DataServiceQuerySingle <Company>;
            queryCompanyAr = queryCompany.BeginGetValue(null, null).EnqueueWait(this);
            company        = queryCompany.EndGetValue(queryCompanyAr);
            Assert.True(company.VipCustomer != null);

            this.EnqueueTestComplete();
        }
Ejemplo n.º 25
0
        public async Task DelayQueryOnSingletonNet45()
        {
            this.testClientContext = this.CreateWrappedContext<InMemoryEntities>().Context;
            this.testClientContext.MergeOption = MergeOption.OverwriteChanges;

            var company = await this.testClientContext.Company.GetValueAsync();
            Assert.NotNull(company);

            //LoadProperty
            await this.testClientContext.LoadPropertyAsync(company, "Departments");
            Assert.NotNull(company.Departments);

            //Query Property
            var name = await this.testClientContext.Company.Select(c => c.Name).GetValueAsync();
            Assert.Equal(company.Name, name);

            //Projection
            var companyQuery = this.testClientContext.Company.Select(c => new Company() { Name = c.Name, Address = c.Address });
            var company2 = await companyQuery.GetValueAsync();
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$select=Name,Address"));
            Assert.NotNull(company2.Address);

            //Expand
            companyQuery = this.testClientContext.Company.Expand(c => c.VipCustomer.Company);
            var company3 = await companyQuery.GetValueAsync();
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=VipCustomer($expand=Company)"));
            Assert.NotNull(company);

            //Projection with Navigation
            companyQuery = this.testClientContext.Company.Select(c => new Company() { Name = c.Name, Address = c.Address, Departments = c.Departments });
            await companyQuery.GetValueAsync();
            Assert.True(companyQuery.RequestUri.OriginalString.EndsWith("/Company?$expand=Departments&$select=Name,Address"));
            Assert.NotNull(company2.Address);

            //Query navigation property which is an collection
            var employeesQuery = this.testClientContext.Company.Employees;
            var employees = await employeesQuery.ExecuteAsync();
            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees"));
            Assert.NotNull(employees);

            //Query Navigation Property which is an single entity
            var company4Query = this.testClientContext.Company.VipCustomer.Company;
            var company4 = await company4Query.GetValueAsync();
            Assert.True(company4Query.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Company"));
            Assert.NotNull(company4Query);

            //Query navigation property which is from a singleton
            var coreDepartmentQuery = this.testClientContext.Company.CoreDepartment;
            var coreDepartment = await coreDepartmentQuery.GetValueAsync();
            Assert.True(coreDepartmentQuery.RequestUri.OriginalString.EndsWith("/Company/CoreDepartment"));
            Assert.NotNull(coreDepartment);

            //QueryOption on navigation property
            employeesQuery = this.testClientContext.Company.Employees.Where(e => e.PersonID > 0) as DataServiceQuery<Employee>;
            employees = await employeesQuery.ExecuteAsync();
            Assert.True(employeesQuery.RequestUri.OriginalString.EndsWith("/Company/Employees?$filter=PersonID gt 0"));
            Assert.NotNull(employees);

            //Function Bound on Singleton
            var getEmployeesCountQuery = this.testClientContext.Company.GetEmployeesCount();
            var count = await getEmployeesCountQuery.GetValueAsync();
            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Function Bound on Singleton
            var company5 = await this.testClientContext.Company.GetValueAsync();
            getEmployeesCountQuery = company5.GetEmployeesCount();
            count = await getEmployeesCountQuery.GetValueAsync();
            Assert.True(getEmployeesCountQuery.RequestUri.OriginalString.EndsWith("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount()"));
            Assert.True(count > 0);

            //Query Action bound on Navigation Property, also on baseType
            var getHomeAddressQuery = this.testClientContext.Company.VipCustomer.GetHomeAddress();
            var homeAddress = await getHomeAddressQuery.GetValueAsync();
            Assert.True(getHomeAddressQuery.RequestUri.OriginalString.EndsWith("/Company/VipCustomer/Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress()"));
            Assert.NotNull(homeAddress);
        }