9using System.Collections.Generic;
13using System.Data.SqlClient;
18using Microsoft.VisualStudio.TestTools.UnitTesting;
22using TestClass = NUnit.Framework.TestFixtureAttribute;
23using TestInitialize = NUnit.Framework.SetUpAttribute;
24using TestCleanup = NUnit.Framework.TearDownAttribute;
25using TestMethod = NUnit.Framework.TestAttribute;
38 _testDIContext = TestDIContextFactory.CreateDefaultContext();
44 public void CheckInnerExceptionsOnSave()
49 DataPortal.TransactionalRoot root =
DataPortal.TransactionalRoot.NewTransactionalRoot(dataPortal);
50 root.FirstName =
"Billy";
51 root.LastName =
"lastname";
52 root.SmallColumn =
"too long for the database";
54 string baseException =
string.Empty;
55 string baseInnerException =
string.Empty;
56 string baseInnerInnerException =
string.Empty;
57 string exceptionSource =
string.Empty;
65 baseException = ex.Message;
66 baseInnerException = ex.InnerException.Message;
67 baseInnerInnerException = ex.InnerException.InnerException?.Message;
68 exceptionSource = ex.InnerException.InnerException?.Source;
69 Assert.IsNull(ex.BusinessObject,
"Business object shouldn't be returned");
73 Assert.IsTrue(baseException.StartsWith(
"DataPortal.Update failed"),
"Exception should start with 'DataPortal.Update failed'");
74 Assert.IsTrue(baseException.Contains(
"String or binary data would be truncated."),
75 "Exception should contain 'String or binary data would be truncated.'");
77 Assert.AreEqual(
"TransactionalRoot.DataPortal_Insert method call failed", baseInnerException);
79 Assert.AreEqual(
"String or binary data would be truncated.\r\nThe statement has been terminated.", baseInnerInnerException);
83 Assert.AreEqual(
".Net SqlClient Data Provider", exceptionSource);
85 Assert.AreEqual(
"Core .Net SqlClient Data Provider", exceptionSource);
90 Assert.AreEqual(
"Called", TestResults.GetResult(
"OnDataPortalException"));
100 string baseException =
string.Empty;
101 string baseInnerException =
string.Empty;
102 string baseInnerInnerException =
string.Empty;
111 baseException = ex.Message;
112 baseInnerException = ex.InnerException.Message;
113 baseInnerInnerException = ex.InnerException.InnerException.Message;
116 Assert.IsTrue(baseException.StartsWith(
"DataPortal.Delete failed"),
"Should start with 'DataPortal.Delete failed'");
117 Assert.IsTrue(baseException.Contains(
"DataPortal_Delete: you chose an unlucky number"));
118 Assert.AreEqual(
"TransactionalRoot.DataPortal_Delete method call failed", baseInnerException);
119 Assert.AreEqual(
"DataPortal_Delete: you chose an unlucky number", baseInnerInnerException);
132 string baseException =
string.Empty;
133 string baseInnerException =
string.Empty;
134 string baseInnerInnerException =
string.Empty;
144 baseException = ex.Message;
145 baseInnerException = ex.InnerException.Message;
146 baseInnerInnerException = ex.InnerException.InnerException.Message;
149 Assert.IsTrue(baseException.StartsWith(
"DataPortal.Fetch failed"),
"Should start with 'DataPortal.Fetch failed'");
150 Assert.IsTrue(baseException.Contains(
"DataPortal_Fetch: you chose an unlucky number"),
151 "Should contain with 'DataPortal_Fetch: you chose an unlucky number'");
152 Assert.AreEqual(
"TransactionalRoot.DataPortal_Fetch method call failed", baseInnerException);
153 Assert.AreEqual(
"DataPortal_Fetch: you chose an unlucky number", baseInnerInnerException);
This exception is returned for any errors occurring during the server-side DataPortal invocation.
Client side data portal used for making asynchronous data portal calls in .NET.
static void ClassInitialize(TestContext context)
void CheckInnerExceptionsOnDelete()
void CheckInnerExceptionsOnFetch()
static void DeleteTransactionalRoot(int ID, IDataPortal< TransactionalRoot > dataPortal)
static TransactionalRoot GetTransactionalRoot(int ID, IDataPortal< TransactionalRoot > dataPortal)
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
static void Reinitialise()
Reinitialise the dictionary, clearing any existing results, ready for the next test
static string GetResult(string key)
Get a result of an operation from the underlying results dictionary
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.