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; } }
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"); }