Beispiel #1
0
        public void FailFetchContext()
        {
            IDataPortal <ExceptionRoot> dataPortal = _testDIContext.CreateDataPortal <ExceptionRoot>();

            TestResults.Reinitialise();
            ExceptionRoot root = null;

            try
            {
                root = dataPortal.Fetch(new ExceptionRoot.Criteria("fail"));
                Assert.Fail("Exception didn't occur");
            }
            catch (DataPortalException ex)
            {
                Assert.IsNull(ex.BusinessObject, "Business object shouldn't be returned");
                Assert.AreEqual("Fail fetch", ex.GetBaseException().Message, "Base exception message incorrect");
                Assert.IsTrue(ex.Message.StartsWith("DataPortal.Fetch failed"), "Exception message incorrect");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected exception: " + ex.ToString());
            }

            Assert.AreEqual("create", TestResults.GetResult("create"), "GlobalContext not preserved");
        }
Beispiel #2
0
        public void FailUpdateContext()
        {
            try
            {
                ApplicationContext.GlobalContext.Clear();
                ApplicationContext.DataPortalReturnObjectOnException = true;

                ExceptionRoot root;
                try
                {
                    root = ExceptionRoot.NewExceptionRoot();
                    Assert.Fail("Create exception didn't occur");
                }
                catch (DataPortalException ex)
                {
                    root = (ExceptionRoot)ex.BusinessObject;
                    Assert.AreEqual("Fail create", ex.GetBaseException().Message, "Base exception message incorrect");
                    Assert.IsTrue(ex.Message.StartsWith("DataPortal.Create failed"), "Exception message incorrect");
                }

                root.Data = "boom";
                try
                {
                    root = root.Save();

                    Assert.Fail("Insert exception didn't occur");
                }
                catch (DataPortalException ex)
                {
                    root = (ExceptionRoot)ex.BusinessObject;
                    Assert.AreEqual("Fail insert", ex.GetBaseException().Message, "Base exception message incorrect");
                    Assert.IsTrue(ex.Message.StartsWith("DataPortal.Update failed"), "Exception message incorrect");
                }

                Assert.AreEqual("boom", root.Data, "Business object not returned");
                Assert.AreEqual("create", ApplicationContext.GlobalContext["create"], "GlobalContext not preserved");
            }
            finally
            {
                ApplicationContext.DataPortalReturnObjectOnException = false;
            }
        }
Beispiel #3
0
        public void FailDeleteContext()
        {
            ApplicationContext.GlobalContext.Clear();
            ApplicationContext.Clear();

            ExceptionRoot root = null;

            try
            {
                ExceptionRoot.DeleteExceptionRoot("fail");
                Assert.Fail("Exception didn't occur");
            }
            catch (DataPortalException ex)
            {
                root = (ExceptionRoot)ex.BusinessObject;
                Assert.AreEqual("Fail delete", ex.GetBaseException().Message, "Base exception message incorrect");
                Assert.IsTrue(ex.Message.StartsWith("DataPortal.Delete failed"), "Exception message incorrect");
            }
            Assert.IsNull(root, "Business object returned");
            Assert.AreEqual("create", ApplicationContext.GlobalContext["create"], "GlobalContext not preserved");
        }
Beispiel #4
0
        public void FailCreateContext()
        {
            ApplicationContext.GlobalContext.Clear();
            ApplicationContext.Clear();

            ExceptionRoot root;

            try
            {
                root = ExceptionRoot.NewExceptionRoot();
                Assert.Fail("Exception didn't occur");
            }
            catch (DataPortalException ex)
            {
                Assert.IsNull(ex.BusinessObject, "Business object shouldn't be returned");
                Assert.AreEqual("Fail create", ex.GetBaseException().Message, "Base exception message incorrect");
                Assert.IsTrue(ex.Message.StartsWith("DataPortal.Create failed"), "Exception message incorrect");
            }

            Assert.AreEqual("create", ApplicationContext.GlobalContext["create"], "GlobalContext not preserved");
        }
Beispiel #5
0
        public void FailDeleteContext()
        {
            IDataPortal <ExceptionRoot> dataPortal = _testDIContext.CreateDataPortal <ExceptionRoot>();

            TestResults.Reinitialise();

            ExceptionRoot root = null;

            try
            {
                dataPortal.Delete("fail");
                Assert.Fail("Exception didn't occur");
            }
            catch (DataPortalException ex)
            {
                root = (ExceptionRoot)ex.BusinessObject;
                Assert.AreEqual("Fail delete", ex.GetBaseException().Message, "Base exception message incorrect");
                Assert.IsTrue(ex.Message.StartsWith("DataPortal.Delete failed"), "Exception message incorrect");
            }
            Assert.IsNull(root, "Business object returned");
            Assert.AreEqual("create", TestResults.GetResult("create"), "GlobalContext not preserved");
        }
Beispiel #6
0
        public void FailFetchContext()
        {
            ApplicationContext.GlobalContext.Clear();
            ExceptionRoot root = null;

            try
            {
                root = ExceptionRoot.GetExceptionRoot("fail");
                Assert.Fail("Exception didn't occur");
            }
            catch (DataPortalException ex)
            {
                Assert.IsNull(ex.BusinessObject, "Business object shouldn't be returned");
                Assert.AreEqual("Fail fetch", ex.GetBaseException().Message, "Base exception message incorrect");
                Assert.IsTrue(ex.Message.StartsWith("DataPortal.Fetch failed"), "Exception message incorrect");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected exception: " + ex.ToString());
            }

            Assert.AreEqual("create", ApplicationContext.GlobalContext["create"], "GlobalContext not preserved");
        }