コード例 #1
0
        /// <summary>
        /// Complete the submit operation with the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        internal new void Complete(Exception error)
        {
            if (typeof(DomainException).IsAssignableFrom(error.GetType()))
            {
                // DomainExceptions should not be modified
                base.Complete(error);
                return;
            }

            string message = string.Format(CultureInfo.CurrentCulture,
                                           Resource.DomainContext_SubmitOperationFailed, error.Message);

            DomainOperationException domainOperationException = error as DomainOperationException;

            if (domainOperationException != null)
            {
                error = new SubmitOperationException(ChangeSet, message, domainOperationException);
            }
            else
            {
                error = new SubmitOperationException(ChangeSet, message, error);
            }

            base.Complete(error);
        }
コード例 #2
0
        /// <summary>
        /// Completes the invoke operation with validation errors.
        /// </summary>
        /// <param name="validationErrors">The validation errors.</param>
        internal void Complete(IEnumerable <ValidationResult> validationErrors)
        {
            this._validationErrors = validationErrors;
            this.RaisePropertyChanged("ValidationErrors");

            string message = string.Format(CultureInfo.CurrentCulture,
                                           Resource.DomainContext_InvokeOperationFailed_Validation,
                                           this.OperationName);
            DomainOperationException error = new DomainOperationException(message, validationErrors);

            base.Complete(error);
        }
コード例 #3
0
        internal void Complete(OperationErrorStatus errorStatus)
        {
            DomainOperationException error = null;

            if (errorStatus == OperationErrorStatus.ValidationFailed)
            {
                error = new DomainOperationException(Resource.DomainContext_SubmitOperationFailed_Validation, OperationErrorStatus.ValidationFailed);
            }
            else if (errorStatus == OperationErrorStatus.Conflicts)
            {
                error = new DomainOperationException(Resource.DomainContext_SubmitOperationFailed_Conflicts, OperationErrorStatus.Conflicts);
            }

            base.Complete(error);
        }
コード例 #4
0
        public void DomainOperationException_Ctors()
        {
            var entities = new List<Entity> {new EntityX()};
            var emtpy = new ReadOnlyCollection<Entity>(entities);
            var changeSet = new EntityChangeSet(emtpy, emtpy, emtpy);

            // ctor(changeSet, message, status)
            var soe = new SubmitOperationException(changeSet, "message", OperationErrorStatus.Unauthorized);
            Assert.AreEqual(changeSet, soe.ChangeSet);
            Assert.AreEqual("message", soe.Message, "ctor(msg) failed");
            Assert.IsNull(soe.InnerException, "InnerException s/b null");
            Assert.IsNull(soe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, soe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.Unauthorized, soe.Status, "ctor(msg, status) failed status");
            Assert.IsFalse(soe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(changeSet, message, innerException)
            var ioe = new InvalidOperationException("ioe");
            soe = new SubmitOperationException(changeSet, "message", ioe);
            Assert.AreEqual(changeSet, soe.ChangeSet);
            Assert.AreEqual("message", soe.Message, "ctor(msg) failed");
            Assert.AreSame(ioe, soe.InnerException, "InnerException failed");
            Assert.IsNull(soe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, soe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.ServerError, soe.Status, "Default status s/b ServerError");
            Assert.IsFalse(soe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(changeSet, message, doe)
            var doe2 = new DomainOperationException("message", OperationErrorStatus.Unauthorized, 5, "stackTrace");
            soe = new SubmitOperationException(changeSet, "mm", doe2);
            Assert.AreEqual(changeSet, soe.ChangeSet); 
            Assert.AreEqual("mm", soe.Message, "ctor(doe) failed message");
            Assert.IsNull(soe.InnerException, "InnerException s/b null");
            Assert.AreEqual("stackTrace", soe.StackTrace, "StackTrace failed");
            Assert.AreEqual(5, soe.ErrorCode, "Error code failed");
            Assert.AreEqual(OperationErrorStatus.Unauthorized, soe.Status, "ctor(msg, status) failed status");
            Assert.IsFalse(soe.ValidationErrors.Any(), "default validationErrors should be empty");
        }
コード例 #5
0
 /// <summary>
 /// Internal "copy" constructor.
 /// </summary>
 /// <param name="changeSet">the changeset being submitted</param>
 /// <param name="message">The new error message to use</param>
 /// <param name="exception">The exception to copy</param>
 internal SubmitOperationException(EntityChangeSet changeSet, string message, DomainOperationException exception)
     : this(changeSet, message, exception.InnerException, exception.Status, exception.ErrorCode, exception.StackTrace)
 {
     _changeSet = changeSet;
 }
コード例 #6
0
 /// <summary>
 /// Internal copy constructor.
 /// </summary>
 /// <param name="message">The new error message to use</param>
 /// <param name="exception">The exception to copy</param>
 internal DomainOperationException(string message, DomainOperationException exception)
     : this(message, exception.InnerException, exception.Status, exception.ErrorCode, exception.StackTrace, exception.ValidationErrors)
 {
 }
コード例 #7
0
        public void DomainOperationException__Properties()
        {
            DomainOperationException doe = new DomainOperationException();

            doe.ErrorCode = 5;
            Assert.AreEqual(5, doe.ErrorCode, "failed to set ErrorCode");

            doe.Status = OperationErrorStatus.ValidationFailed;
            Assert.AreEqual(OperationErrorStatus.ValidationFailed, doe.Status, "failed to set Status");
        }
コード例 #8
0
        public void DomainOperationException_Ctors()
        {
            // Parameterless ctor
            DomainOperationException doe = new DomainOperationException();
            Assert.IsNotNull(doe.Message, "Default msg s/n/b null");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.IsNull(doe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, doe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.ServerError, doe.Status, "Default status s/b ServerError");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message)
            doe = new DomainOperationException("message");
            Assert.AreEqual("message", doe.Message, "ctor(msg) failed");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.IsNull(doe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, doe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.ServerError, doe.Status, "Default status s/b ServerError");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message, status)
            doe = new DomainOperationException("message", OperationErrorStatus.Unauthorized);
            Assert.AreEqual("message", doe.Message, "ctor(msg) failed");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.IsNull(doe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, doe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.Unauthorized, doe.Status, "ctor(msg, status) failed status");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message, status, errCode)
            doe = new DomainOperationException("message", OperationErrorStatus.Unauthorized, 5);
            Assert.AreEqual("message", doe.Message, "ctor(msg) failed");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.IsNull(doe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(5, doe.ErrorCode, "Error code failed");
            Assert.AreEqual(OperationErrorStatus.Unauthorized, doe.Status, "ctor(msg, status) failed status");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message, status, errCode, stackTrace)
            doe = new DomainOperationException("message", OperationErrorStatus.Unauthorized, 5, "stackTrace");
            Assert.AreEqual("message", doe.Message, "ctor(msg) failed");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.AreEqual("stackTrace", doe.StackTrace, "StackTrace failed");
            Assert.AreEqual(5, doe.ErrorCode, "Error code failed");
            Assert.AreEqual(OperationErrorStatus.Unauthorized, doe.Status, "ctor(msg, status) failed status");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message, innerException)
            InvalidOperationException ioe = new InvalidOperationException("ioe");
            doe = new DomainOperationException("message", ioe);
            Assert.AreEqual("message", doe.Message, "ctor(msg) failed");
            Assert.AreSame(ioe, doe.InnerException, "InnerException failed");
            Assert.IsNull(doe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, doe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.ServerError, doe.Status, "Default status s/b ServerError");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message, doe)
            DomainOperationException doe2 = new DomainOperationException("message", OperationErrorStatus.Unauthorized, 5, "stackTrace");
            doe = new DomainOperationException("mm", doe2);
            Assert.AreEqual("mm", doe.Message, "ctor(doe) failed message");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.AreEqual("stackTrace", doe.StackTrace, "StackTrace failed");
            Assert.AreEqual(5, doe.ErrorCode, "Error code failed");
            Assert.AreEqual(OperationErrorStatus.Unauthorized, doe.Status, "ctor(msg, status) failed status");
            Assert.IsFalse(doe.ValidationErrors.Any(), "default validationErrors should be empty");

            // ctor(message, validationerrors)
            var validationErrors = new List<ValidationResult>() {new ValidationResult("validation message")};
            doe = new DomainOperationException("message", validationErrors);
            Assert.AreEqual("message", doe.Message, "ctor(message, validationerrors) failed message");
            Assert.IsNull(doe.InnerException, "InnerException s/b null");
            Assert.IsNull(doe.StackTrace, "Default stack trace s/b null");
            Assert.AreEqual(0, doe.ErrorCode, "Error code s/b 0");
            Assert.AreEqual(OperationErrorStatus.ValidationFailed, doe.Status, "ctor(message, validationerrors) status s/b ValidationFailed");
            CollectionAssert.AreEqual(validationErrors, doe.ValidationErrors.ToList());
        }
コード例 #9
0
 /// <summary>
 /// Internal "copy" constructor.
 /// </summary>
 /// <param name="changeSet">the changeset being submitted</param>
 /// <param name="message">The new error message to use</param>
 /// <param name="exception">The exception to copy</param>
 internal SubmitOperationException(EntityChangeSet changeSet, string message, DomainOperationException exception)
     : this(changeSet, message, exception.InnerException, exception.Status, exception.ErrorCode, exception.StackTrace)
 {
     _changeSet = changeSet;
 }
コード例 #10
0
 /// <summary>
 /// Internal copy constructor.
 /// </summary>
 /// <param name="message">The new error message to use</param>
 /// <param name="exception">The exception to copy</param>
 internal DomainOperationException(string message, DomainOperationException exception)
     : this(message, exception.InnerException, exception.Status, exception.ErrorCode, exception.StackTrace, exception.ValidationErrors)
 {
 }
コード例 #11
0
        /// <summary>
        /// Complete the submit operation with the specified error.
        /// </summary>
        /// <param name="error">The error.</param>
        internal new void Complete(Exception error)
        {
            if (typeof(DomainException).IsAssignableFrom(error.GetType()))
            {
                // DomainExceptions should not be modified
                base.Complete(error);
                return;
            }

            string message = string.Format(CultureInfo.CurrentCulture,
                Resource.DomainContext_SubmitOperationFailed, error.Message);

            DomainOperationException domainOperationException = error as DomainOperationException;
            if (domainOperationException != null)
            {
                error = new DomainOperationException(message, domainOperationException);
            }
            else
            {
                error = new DomainOperationException(message, error);
            }

            base.Complete(error);
        }
コード例 #12
0
        internal void Complete(OperationErrorStatus errorStatus)
        {
            DomainOperationException error = null;
            if (errorStatus == OperationErrorStatus.ValidationFailed)
            {
                error = new DomainOperationException(Resource.DomainContext_SubmitOperationFailed_Validation, OperationErrorStatus.ValidationFailed);
            }
            else if (errorStatus == OperationErrorStatus.Conflicts)
            {
                error = new DomainOperationException(Resource.DomainContext_SubmitOperationFailed_Conflicts, OperationErrorStatus.Conflicts);
            }

            base.Complete(error);
        }
コード例 #13
0
        public void Operation_MarkAsHandled()
        {
            TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc"));

            var query = ctxt.CreateQuery<Product>("ThrowGeneralException", null, false, true);
            LoadOperation lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);

            EventHandler action = (o, e) =>
            {
                LoadOperation loadOperation = (LoadOperation)o;
                if (loadOperation.HasError)
                {
                    loadOperation.MarkErrorAsHandled();
                }
            };
            lo.Completed += action;

            DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");
            lo.Complete(ex);

            // verify that calling MarkAsHandled again is a noop
            lo.MarkErrorAsHandled();
            lo.MarkErrorAsHandled();

            // verify that calling MarkAsHandled on an operation not in error
            // results in an exception
            lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);
            Assert.IsFalse(lo.HasError);
            Assert.IsTrue(lo.IsErrorHandled);
            ExceptionHelper.ExpectInvalidOperationException(delegate
            {
                lo.MarkErrorAsHandled();
            }, Resource.Operation_HasErrorMustBeTrue);
        }
コード例 #14
0
        public void UnhandledSubmitOperationError()
        {
            CityDomainContext cities = new CityDomainContext(TestURIs.Cities);
            CityData data = new CityData();
            cities.Cities.LoadEntities(data.Cities.ToArray());

            City city = cities.Cities.First();
            city.ZoneID = 1;
            Assert.IsTrue(cities.EntityContainer.HasChanges);

            SubmitOperation submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, null);

            DomainOperationException expectedException = null;
            DomainOperationException ex = new DomainOperationException("Submit Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");
            try
            {
                submit.Complete(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed, ex.Message), expectedException.Message);
            Assert.AreEqual(ex.StackTrace, expectedException.StackTrace);
            Assert.AreEqual(ex.Status, expectedException.Status);
            Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode);

            Assert.AreEqual(false, submit.IsErrorHandled);

            // now test again with conflicts
            expectedException = null;
            IEnumerable<ChangeSetEntry> entries = ChangeSetBuilder.Build(cities.EntityContainer.GetChanges());
            ChangeSetEntry entry = entries.First();
            entry.ValidationErrors = new ValidationResultInfo[] { new ValidationResultInfo("Foo", new string[] { "Bar" }) };

            submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, null);

            try
            {
                submit.Complete(OperationErrorStatus.Conflicts);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed_Conflicts), expectedException.Message);

            // now test again with validation errors
            expectedException = null;
            entries = ChangeSetBuilder.Build(cities.EntityContainer.GetChanges());
            entry = entries.First();
            entry.ConflictMembers = new string[] { "ZoneID" };

            submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, null);

            try
            {
                submit.Complete(OperationErrorStatus.ValidationFailed);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed_Validation, ex.Message), expectedException.Message);
        }
コード例 #15
0
        public void UnhandledInvokeOperationError()
        {
            CityDomainContext cities = new CityDomainContext(TestURIs.Cities);

            InvokeOperation invoke = new InvokeOperation("Echo", null, null, null, null);

            DomainOperationException expectedException = null;
            DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");
            try
            {
                invoke.Complete(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_InvokeOperationFailed, "Echo", ex.Message), expectedException.Message);
            Assert.AreEqual(ex.StackTrace, expectedException.StackTrace);
            Assert.AreEqual(ex.Status, expectedException.Status);
            Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode);

            Assert.AreEqual(false, invoke.IsErrorHandled);

            // now test again with validation errors
            expectedException = null;
            ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) };
            invoke = new InvokeOperation("Echo", null, null, null, null);

            try
            {
                invoke.Complete(validationErrors);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_InvokeOperationFailed_Validation, "Echo"), expectedException.Message);
        }
コード例 #16
0
        public void UnhandledLoadOperationError()
        {
            TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc"));

            var query = ctxt.CreateQuery<Product>("ThrowGeneralException", null, false, true);
            LoadOperation lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);

            DomainOperationException expectedException = null;
            DomainOperationException ex = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace");
            try
            {
                lo.Complete(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed, "ThrowGeneralException", ex.Message), expectedException.Message);
            Assert.AreEqual(ex.StackTrace, expectedException.StackTrace);
            Assert.AreEqual(ex.Status, expectedException.Status);
            Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode);

            Assert.AreEqual(false, lo.IsErrorHandled);

            // now test again with validation errors
            expectedException = null;
            ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) };
            lo = new LoadOperation<Product>(query, LoadBehavior.KeepCurrent, null, null, null);

            try
            {
                lo.Complete(validationErrors);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.IsNotNull(expectedException);
            Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed_Validation, "ThrowGeneralException"), expectedException.Message);
        }