9using System.Configuration;
10using System.Collections.Generic;
18using Microsoft.VisualStudio.TestTools.UnitTesting;
21using TestClass = NUnit.Framework.TestFixtureAttribute;
22using TestInitialize = NUnit.Framework.SetUpAttribute;
23using TestCleanup = NUnit.Framework.TearDownAttribute;
24using TestMethod = NUnit.Framework.TestAttribute;
37 _testDIContext = TestDIContextFactory.CreateContext(
38 options => options.DataPortal(dp => dp.AddServerSideDataPortal(
56 [TestCategory(
"SkipWhenLiveUnitTesting")]
59 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
62 opts => opts.DataPortal(
64 new System.Security.Claims.ClaimsPrincipal());
68 var root = dataPortal.
Create();
69 Assert.AreEqual(
"Create", root.Data,
"Data should match");
71 Assert.IsTrue(root.IsNew,
"Should be new");
72 Assert.IsTrue(root.IsDirty,
"Should be dirty");
82 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
88 var root = dataPortal.
Create(
"abc");
89 Assert.AreEqual(
"Create abc", root.Data,
"Data should match");
91 Assert.IsTrue(root.IsNew,
"Should be new");
92 Assert.IsTrue(root.IsDirty,
"Should be dirty");
98 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
102 new System.Security.Claims.ClaimsPrincipal());
106 var root = dataPortal.
Create(
"abc");
107 Assert.AreEqual(
"Create abc", root.Data,
"Data should match");
109 Assert.IsTrue(root.IsNew,
"Should be new");
110 Assert.IsTrue(root.IsDirty,
"Should be dirty");
116 [ExpectedException(typeof(MissingMethodException))]
119 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
123 new System.Security.Claims.ClaimsPrincipal()
130 var root = dataPortal.
Create(
"abc", 123);
143 var root = dataPortal.
Fetch();
144 Assert.AreEqual(
"Fetch", root.Data,
"Data should match");
145 Assert.IsFalse(root.IsNew,
"Should not be new");
146 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
154 var root = dataPortal.
Fetch(
"abc");
155 Assert.AreEqual(
"abc", root.Data,
"Data should match");
156 Assert.IsFalse(root.IsNew,
"Should not be new");
157 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
165 var root = dataPortal.
Fetch();
168 root = dataPortal.
Update(root);
169 Assert.AreEqual(
TransactionalTypes.Manual, root.TransactionalType,
"Transactional type should match");
170 Assert.AreEqual(
"Update", root.Data,
"Data should match");
171 Assert.IsFalse(root.IsNew,
"Should not be new");
172 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
178 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
183 var root = dataPortal.
Fetch();
186 root = dataPortal.
Update(root);
187 Assert.AreEqual(
TransactionalTypes.TransactionScope, root.TransactionalType,
"Transactional type should match");
188 Assert.AreEqual(
"Serializable", root.IsolationLevel,
"Transactional isolation should match");
189 Assert.AreEqual(30, root.TransactionTimeout,
"Transactional timeout should match");
191 Assert.AreEqual(
"Update", root.Data,
"Data should match");
192 Assert.IsFalse(root.IsNew,
"Should not be new");
193 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
199 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
204 .DefaultTransactionTimeoutInSeconds(45)
212 var root = dataPortal.
Create();
216 root = dataPortal.
Update(root);
217 Assert.AreEqual(
TransactionalTypes.TransactionScope, root.TransactionalType,
"Transactional type should match");
218 Assert.AreEqual(
"ReadCommitted", root.IsolationLevel,
"Transactional isolation should match");
219 Assert.AreEqual(100, root.TransactionTimeout,
"Transactional timeout should match");
221 Assert.AreEqual(
"Update", root.Data,
"Data should match");
222 Assert.IsFalse(root.IsNew,
"Should not be new");
223 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
230 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
235 .DefaultTransactionTimeoutInSeconds(45)
242 var root = dataPortal.
Create();
246 root = dataPortal.
Update(root);
247 Assert.AreEqual(
TransactionalTypes.TransactionScope, root.TransactionalType,
"Transactional type should match");
248 Assert.AreEqual(
"RepeatableRead", root.IsolationLevel,
"Transactional isolation should match");
249 Assert.AreEqual(45, root.TransactionTimeout,
"Transactional timeout should match");
251 Assert.AreEqual(
"Update", root.Data,
"Data should match");
252 Assert.IsFalse(root.IsNew,
"Should not be new");
253 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
271 TestDIContext testDIContext = TestDIContextFactory.CreateContext(
272 options => options.DataPortal(
277 var root = dataPortal.
Fetch();
278 Assert.AreEqual(
"Fetch", root.Data,
"Data should match");
279 Assert.IsFalse(root.IsNew,
"Should not be new");
280 Assert.IsFalse(root.IsDirty,
"Should not be dirty");
286 TestDIContext testDIContext = TestDIContextFactory.CreateDefaultContext();
300 TestDIContext testDIContext = TestDIContextFactory.CreateDefaultContext();
312 Assert.AreEqual(typeof(System.NotImplementedException), ex.InnerException.GetType());
313 Assert.IsTrue(ex.InnerException.Message.Contains(
"ExecuteMissingMethod"));
317 Assert.Fail(
"Should throw exception");
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
This exception is returned for any errors occurring during the server-side DataPortal invocation.
Exception BusinessException
Gets the original server-side exception.
static bool Execute(IDataPortal< CommandObject > dataPortal)
static bool Execute(IDataPortal< CommandObjectMissingFactoryMethod > dataPortal)
static void ClassInitialize(TestContext context)
void DataPortalExecute_OnCommandObjectWithFalseExecuteMethod_ThrowsExeptionMehodNotFound()
void UpdateTransactionScope()
void Cleanup()
Always make sure to cleanup after each test
void DataPortalExecute_OnCommandObjectWithLocalProxy_CallsFactoryExecute()
void UpdateTransactionScopeUsingDefaultTransactionLevelAndTimeout()
void UpdateTransactionScopeUsingCustomTransactionLevelAndTimeout()
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.
object Update(object obj)
Insert, update or delete an object in the database.
void Delete(params object[] criteria)
Called by a Shared (static in C#) method in the business class to cause immediate deletion of a speci...
object Fetch(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
TransactionalTypes
Provides a list of possible transactional technologies to be used by the server-side DataPortal.
TransactionIsolationLevel
Specifies an isolation level for transactions controlled by TransactionalAttribute