9using System.Collections.Generic;
13using System.Data.SqlClient;
19using TestClass = NUnit.Framework.TestFixtureAttribute;
20using TestInitialize = NUnit.Framework.SetUpAttribute;
21using TestCleanup = NUnit.Framework.TearDownAttribute;
22using TestMethod = NUnit.Framework.TestAttribute;
23using TestSetup = NUnit.Framework.SetUpAttribute;
25using Microsoft.VisualStudio.TestTools.UnitTesting;
38 _testDIContext = TestDIContextFactory.CreateDefaultContext();
44 SqlConnection cn =
new SqlConnection(CONNECTION_STRING);
45 SqlCommand cm =
new SqlCommand(
"DELETE FROM Table2", cn);
65 public void TestTransactionScopeUpdate()
71 tr.LastName =
"Johnson";
74 tr.SmallColumn =
"abc";
79 SqlConnection cn =
new SqlConnection(CONNECTION_STRING);
80 SqlCommand cm =
new SqlCommand(
"SELECT * FROM Table2", cn);
85 SqlDataReader dr = cm.ExecuteReader();
88 Assert.AreEqual(
true, dr.HasRows);
104 tr2.LastName =
"Smith";
107 tr2.SmallColumn =
"this will cause a sql exception";
116 Assert.IsTrue(ex.Message.StartsWith(
"DataPortal.Update failed"),
"Invalid exception message");
124 SqlDataReader dr = cm.ExecuteReader();
127 Assert.AreEqual(
false, dr.HasRows);
153 Assert.AreEqual(
"fetched existing data", root.Data);
154 Assert.AreEqual(456, root.Id);
161 Assert.AreEqual(
"new default data", root2.Data);
162 Assert.AreEqual(56, root2.Id);
176 var obj = dataPortal.
Fetch();
180 Assert.IsInstanceOfType(ex.InnerException, typeof(InvalidOperationException));
183 Assert.Fail(
"Expected exception");
193 var obj = dataPortal.
Fetch();
197 Assert.IsInstanceOfType(ex.InnerException, typeof(InvalidOperationException));
200 Assert.Fail(
"Expected exception");
223 Assert.AreEqual(
"true",
TestResults.
GetResult(
"dpinvokecomplete"),
"DataPortalInvokeComplete not called");
224 Assert.AreEqual(
"true",
TestResults.
GetResult(
"serverinvoke"),
"Server DataPortalInvoke not called");
225 Assert.AreEqual(
"true",
TestResults.
GetResult(
"serverinvokecomplete"),
"Server DataPortalInvokeComplete not called");
240 var dps = _testDIContext.
ServiceProvider.GetRequiredService<Server.DataPortalSelector>();
245 DataPortalTest.Single single = NewSingle();
259 single = GetSingle(1);
293 parent.
Data =
"something";
295 Assert.AreEqual(
false, parent.IsDeleted);
296 Assert.AreEqual(
true, parent.IsValid);
297 Assert.AreEqual(
true, parent.IsNew);
298 Assert.AreEqual(
true, parent.
IsDirty);
299 Assert.AreEqual(
true, parent.IsSavable);
301 parent = parent.
Save();
305 Assert.AreEqual(
false, parent.IsDeleted);
306 Assert.AreEqual(
true, parent.IsValid);
307 Assert.AreEqual(
false, parent.IsNew);
308 Assert.AreEqual(
false, parent.
IsDirty);
309 Assert.AreEqual(
false, parent.IsSavable);
311 parent.
Data =
"something new";
313 Assert.AreEqual(
false, parent.IsDeleted);
314 Assert.AreEqual(
true, parent.IsValid);
315 Assert.AreEqual(
false, parent.IsNew);
316 Assert.AreEqual(
true, parent.
IsDirty);
317 Assert.AreEqual(
true, parent.IsSavable);
319 parent = parent.
Save();
324 Assert.AreEqual(
true, parent.IsDeleted);
325 parent = parent.
Save();
330 Assert.AreEqual(
false, parent.IsDeleted);
331 Assert.AreEqual(
true, parent.IsValid);
332 Assert.AreEqual(
true, parent.IsNew);
333 Assert.AreEqual(
true, parent.
IsDirty);
334 Assert.AreEqual(
true, parent.IsSavable);
350 private DataPortalTest.Single NewSingle()
352 IDataPortal<DataPortalTest.Single> dataPortal = _testDIContext.CreateDataPortal<DataPortalTest.Single>();
354 return dataPortal.
Create();
357 private DataPortalTest.Single GetSingle(
int id)
359 IDataPortal<DataPortalTest.Single> dataPortal = _testDIContext.CreateDataPortal<DataPortalTest.Single>();
361 return dataPortal.
Fetch(
id);
364 private void DeleteSingle(
int id)
366 IDataPortal<DataPortalTest.Single> dataPortal = _testDIContext.CreateDataPortal<DataPortalTest.Single>();
379 BusinessRules.CheckRules();
383 private void DataPortal_Fetch()
409 obj.MarkObjectBusy();
Provides consistent context information between the client and server DataPortal objects.
This is the base class from which most business objects will be derived.
T Save()
Saves the object to the database.
Provides information about the DataPortal call.
This exception is returned for any errors occurring during the server-side DataPortal invocation.
Allows the Data Portal call to be intercepted by a custom IDataPortalServer implementation.
static IDataPortalServer DataPortalServer
Gets or sets a reference to a implementation of IDataPortalServer to be used.
Base class to be used when creating a data portal factory object.
void MarkOld(object obj)
Calls the MarkOld method on the specified object, if possible.
static ParentEntity NewParentEntity(IDataPortal< ParentEntity > dataPortal)
static ParentEntity GetParentEntity(int ID, IDataPortal< ParentEntity > dataPortal)
static void DeleteParentEntity(int ID, IDataPortal< ParentEntity > dataPortal)
static void ClassInitialize(TestContext context)
void CallDataPortalOverrides()
void FactoryIsBusyFails()
void StronglyTypedDataPortalMethods()
void EncapsulatedIsBusyFails()
void DataPortalBrokerTests()
FactoryBusyFactory(ApplicationContext applicationContext)
static StronglyTypedDP NewStronglyTypedDP(IDataPortal< StronglyTypedDP > dataPortal)
static void DeleteStronglyTypedDP(int id, IDataPortal< StronglyTypedDP > dataPortal)
static StronglyTypedDP GetStronglyTypedDP(int id, IDataPortal< StronglyTypedDP > dataPortal)
static TransactionalRoot NewTransactionalRoot(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
static void Add(string key, string value)
Add an item to the test results, to indicate an outcome of a particular operation
static string DataPortalTestDatabase
Type to carry context information for DI in unit tests
IServiceProvider ServiceProvider
The service provider used to perform DI operations
Interface defining the members of the data portal type.
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...
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Create
Create operation.