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(); }
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.IsTrue((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.IsTrue((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.IsTrue(!(company as PublicCompany).Assets.Any(a => a.AssetID == tmpAssertId)); this.EnqueueTestComplete(); }