public void DomainContext_Submit_DomainMethodsThrow_EntityValidationError()
        {
            List<string>[] propChanged = new List<string>[] { new List<string>(), new List<string>(), new List<string>() };
            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 some domain methods
            EnqueueConditional(() => lo.IsComplete);
            EnqueueCallback(delegate
            {
                // invoke methods that cause exception
                Zip[] zips = citiesProvider.Zips.ToArray();
                citiesProvider.ThrowException(zips[0], "EntityValidationException");
                citiesProvider.ThrowException(zips[1], "EntityValidationException");

                // invoke method that does not cause exception
                zips[2].ReassignZipCode(1, true);
                refZip = zips[2].Code;

                zips[0].PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                {
                    propChanged[0].Add(e.PropertyName);
                };
                zips[1].PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                {
                    propChanged[1].Add(e.PropertyName);
                };
                zips[2].PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                {
                    propChanged[2].Add(e.PropertyName);
                };

                so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });
            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                Assert.IsNotNull(so.Error);
                DomainOperationException ex = so.Error as DomainOperationException;

                // this is a case where method invocations causes a ValidationException.
                Assert.AreEqual(OperationErrorStatus.ValidationFailed, ex.Status);
                Assert.AreEqual(Resource.DomainContext_SubmitOperationFailed_Validation, ex.Message);

                // verify ValidationError collection is correct
                Zip[] zips = citiesProvider.Zips.ToArray();
                IEnumerable<ValidationResult> errors = zips[0].ValidationErrors;
                LogErrorListContents("citiesProvider.Zips[0].ValidationErrors", errors);
                Assert.AreEqual(1, errors.Count());
                ValidationResult vr = errors.First();
                Assert.AreEqual("Invalid Zip properties!", vr.ErrorMessage);
                Assert.AreEqual(2, vr.MemberNames.Count());
                Assert.IsTrue(vr.MemberNames.Contains("CityName"));
                Assert.IsTrue(vr.MemberNames.Contains("CountyName"));

                errors = zips[1].ValidationErrors;
                LogErrorListContents("citiesProvider.Zips[0].ValidationErrors", errors);
                Assert.AreEqual(1, errors.Count());
                vr = errors.First();
                Assert.AreEqual("Invalid Zip properties!", vr.ErrorMessage);
                Assert.AreEqual(2, vr.MemberNames.Count());
                Assert.IsTrue(vr.MemberNames.Contains("CityName"));
                Assert.IsTrue(vr.MemberNames.Contains("CountyName"));

                // verify the Entity.ValidationErrors collection is populated as expected
                Assert.IsTrue(propChanged[0].Contains("HasValidationErrors"));
                Assert.IsTrue(propChanged[1].Contains("HasValidationErrors"));

                // verify entities are not auto-synced back to the client because there were errors
                Assert.IsFalse(propChanged[2].Contains("Code"));
                Assert.IsFalse(propChanged[2].Contains("FourDigit"));
                Assert.IsFalse(propChanged[2].Contains("HasValidationErrors"));
                Assert.AreEqual(0, zips[2].ValidationErrors.Count());
                Assert.AreEqual(refZip, zips[2].Code);
            });

            EnqueueTestComplete();
        }