Exemple #1
0
        public void TestNonDomainService()
        {
            TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-NonDomainService.svc"));
            LoadOperation   lo   = ctxt.Load(ctxt.CreateQuery <Product>("GetProducts", null), false);

            EnqueueConditional(delegate
            {
                return(lo.IsComplete);
            });
            EnqueueCallback(delegate
            {
                Assert.IsNotNull(lo.Error);
                // TODO: Assert proper error message... Note: WCF error messages differ between desktop and Silverlight.
                //Assert.IsTrue(lo.Error.InnerException.Message.StartsWith("There was no endpoint listening"));
                //Assert.AreEqual(OperationErrorStatus.NotFound, ex.Status);
                //Assert.AreEqual(Resource.DomainClient_ResourceNotFound, ex.Message);
            });
            EnqueueTestComplete();
        }
Exemple #2
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, false);

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

            try
            {
                lo.SetError(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.AreSame(ex, expectedException);

            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, false);
            ex = new DomainOperationException("expected", validationErrors);

            try
            {
                lo.SetError(ex);
            }
            catch (DomainOperationException e)
            {
                expectedException = e;
            }

            // verify the exception properties
            Assert.AreSame(expectedException, ex);
            CollectionAssert.AreEqual(validationErrors, (ICollection)lo.ValidationErrors);
        }
        public void TestL2SProviderConstructorThrows()
        {
            // Test for a provider that derives from LinqToSqlDomainService, since LinqToSqlDomainService is instantiated differently
            TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-ThrowingDomainServiceL2S.svc"));
            LoadOperation   lo   = ctxt.Load(ctxt.CreateQuery <Product>("GetProducts", null), false);

            EnqueueConditional(delegate
            {
                return(lo.IsComplete);
            });
            EnqueueCallback(delegate
            {
                DomainOperationException ex = (DomainOperationException)lo.Error;
                Assert.IsNotNull(ex);
                Assert.AreEqual(OperationErrorStatus.NotSupported, ex.Status);
                Assert.AreEqual(string.Format(Resource.DomainContext_LoadOperationFailed, "GetProducts", "Couldn't construct this type."), ex.Message);
            });

            EnqueueTestComplete();
        }
Exemple #4
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);
        }