public void DomainContext_Submit_ValidationErrorOnServer()
        {
            CityDomainContext citiesProvider = new CityDomainContext(TestURIs.Cities);
            Zip newZip = null;

            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
            {
                // Add an entity that will cause a Validation exception on the server (99999 is used as a way to signal failure for our validator)
                newZip = new Zip()
                {
                    Code = 99999,
                    FourDigit = 8625,
                    CityName = "Redmond",
                    CountyName = "King",
                    StateName = "WA"
                };
                citiesProvider.Zips.Add(newZip);
                newZip.ThrowException("InvalidOperationException");

                so = citiesProvider.SubmitChanges(TestHelperMethods.DefaultOperationAction, null);
            });

            EnqueueConditional(() => so.IsComplete);
            EnqueueCallback(delegate
            {
                DomainOperationException ex = so.Error as DomainOperationException;
                Assert.IsNotNull(ex);
                Assert.AreEqual(OperationErrorStatus.ValidationFailed, ex.Status);
                Assert.AreEqual(Resource.DomainContext_SubmitOperationFailed_Validation, ex.Message);

                IEnumerable<ValidationResult> errors = newZip.ValidationErrors;
                LogErrorListContents("newZip.ValidationErrors", errors);
                Assert.AreEqual(1, errors.Count());
                UnitTestHelper.AssertListContains<ValidationResult>(errors, (e => e.ErrorMessage == "Server fails validation"));
            });

            EnqueueTestComplete();
        }
예제 #2
0
 /// <summary>
 /// Invokes the 'ThrowException' method of the specified <see cref="Zip"/> entity.
 /// </summary>
 /// <param name="zip">The <see cref="Zip"/> entity instance.</param>
 /// <param name="scenario">The value for the 'scenario' parameter for this action.</param>
 public void ThrowException(Zip zip, string scenario)
 {
     zip.ThrowException(scenario);
 }