public void DomainContext_Submit_ErrorsClearOnReject() { int refZip = 0; CityDomainContext citiesProvider = new CityDomainContext(TestURIs.Cities); SubmitOperation so = null; LoadOperation lo = citiesProvider.Load(citiesProvider.GetZipsQuery(), false); // wait for Load to complete, then invoke domain method that throws on server. Submit. EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { // invoke methods that cause exception Zip[] zips = citiesProvider.Zips.ToArray(); zips[0].ThrowException("ValidationException"); so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); // wait for submitted event being fired and verify Entity.ValidationErrors is not empty EnqueueConditional(() => so.IsComplete); EnqueueCallback(delegate { DomainOperationException ex = so.Error as DomainOperationException; Assert.IsNotNull(ex); Zip zip = citiesProvider.Zips.First(); IEnumerable<ValidationResult> errors = zip.ValidationErrors; LogErrorListContents("zips[0].ValidationErrors", errors); Assert.AreEqual(1, errors.Count()); // Verify that failed submission does not clear out the last invocation Assert.IsFalse(zip.CanThrowException); Assert.IsTrue(zip.EntityActions.Any(a => a.Name == "ThrowException")); // Add a custom validation error to ensure it gets cleared zip.ValidationErrors.Add(new ValidationResult("Temporary Error")); // Call RejectChanges and verify ValidationErrors collection is cleared citiesProvider.RejectChanges(); Assert.IsFalse(zip.ValidationErrors.Any()); // Invoke domain method that does not throw on same entity zip.ReassignZipCode(1, true); refZip = zip.Code; so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); // wait for submitted event being fired and verify Entity.ValidationErrors remains empty EnqueueConditional(() => so.IsComplete); EnqueueCallback(delegate { Zip zip = citiesProvider.Zips.First(); Assert.IsNull(so.Error); Assert.IsFalse(zip.ValidationErrors.Any()); Assert.AreEqual(refZip + 1, zip.Code); }); EnqueueTestComplete(); }