public void Inherit_Run_CUD_Delete_Derived() { // Inheritance is City <-- CityWithEditHistory <-- CityWithInfo CityDomainContext citiesContext = new CityDomainContext(TestURIs.Cities); DateTime priorLastUpdated = DateTime.Now; LoadOperation lo = null; SubmitOperation so = null; CityWithInfo cityWithInfo = null; string originalName = null; string originalStateName = null; string originalCountyName = null; // Invoke service operation to clear out all static data // (we rely on static data for deleted cities so that it // survives across queries) InvokeOperation invoke = citiesContext.ResetData(null, null); EnqueueConditional(delegate { return invoke.IsComplete; }); EnqueueCallback(delegate { if (invoke.Error != null) { Assert.Fail("Failed on invoke of ResetData: " + invoke.Error.Message); } }); EnqueueCallback(delegate { // Load all cities, not just derived ones lo = citiesContext.Load(citiesContext.GetCitiesQuery()); }); // wait for Load to complete EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { cityWithInfo = citiesContext.Cities.OfType<CityWithInfo>().FirstOrDefault(); Assert.IsNotNull(cityWithInfo, "expected to find at least one CityWithInfo entity"); Assert.IsFalse(cityWithInfo.EditHistory.Contains("update"), "Did not expect edit history to be set yet."); originalName = cityWithInfo.Name; originalStateName = cityWithInfo.StateName; originalCountyName = cityWithInfo.CountyName; // Delete it. Note that the delete CUD method in the CityDomainService // moves the deleted city over into DeletedCities so it can still be found citiesContext.Cities.Remove(cityWithInfo); so = citiesContext.SubmitChanges(); }); // wait for submit to complete EnqueueConditional(() => so.IsComplete); EnqueueCallback(delegate { if (so.Error != null) { Assert.Fail("Unexpected error on submit: " + so.Error.Message); } // verify entities are auto-synced back to the client as a result of the domain method execution on server CityWithInfo deletedCity = citiesContext.Cities.OfType<CityWithInfo>().SingleOrDefault<CityWithInfo> (c => (c.Name == originalName && c.StateName == originalStateName && c.CountyName == originalCountyName)); Assert.IsNull(deletedCity, "Did not expect to find deleted City after the submit"); // Load the deleted cities (it was tombstoned) citiesContext.Cities.Clear(); lo = citiesContext.Load(citiesContext.GetDeletedCitiesQuery()); }); // Wait for deleted city query to complete EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { if (lo.Error != null) { Assert.Fail("Unexpected error on load of deleted queries: " + lo.Error.Message); } // verify entities are auto-synced back to the client as a result of the domain method execution on server CityWithInfo deletedCity = citiesContext.Cities.OfType<CityWithInfo>().SingleOrDefault<CityWithInfo> (c => (c.Name == originalName && c.StateName == originalStateName && c.CountyName == originalCountyName)); Assert.IsNotNull(deletedCity, "Expected to find deleted City in the tombstone list"); Assert.IsTrue(deletedCity.EditHistory.Contains("delete"), "Expected edit history to show delete but it only shows: " + deletedCity.EditHistory); }); EnqueueTestComplete(); }