2using System.Collections.Generic;
5using System.Threading.Tasks;
9using Microsoft.VisualStudio.TestTools.UnitTesting;
12using TestClass = NUnit.Framework.TestFixtureAttribute;
13using TestInitialize = NUnit.Framework.SetUpAttribute;
14using TestCleanup = NUnit.Framework.TearDownAttribute;
15using TestMethod = NUnit.Framework.TestAttribute;
28 _testDIContext = TestDIContextFactory.CreateContext(
30 .
DataPortal(dp => dp.AddServerSideDataPortal(config =>
32 config.AddInterceptorProvider<TestInterceptor>();
33 config.RegisterActivator<TestActivator>();
43 var obj = CreateInitializeRoot(
"abc");
44 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InitializeRoot"),
"Initialize should have run");
45 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InitializeRoot"),
"Complete should have run");
46 Assert.AreEqual(
"CreateInstance",
TestResults.
GetResult(
"Activate1+InitializeRoot"),
"CreateInstance should have run");
47 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeRoot"),
"InitializeInstance should have run");
48 Assert.AreEqual(
"ResolveType",
TestResults.
GetResult(
"Activate4+InitializeRoot"),
"ResolveType should have run");
56 var obj = GetInitializeRoot(
"abc");
57 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InitializeRoot"),
"Initialize should have run");
58 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InitializeRoot"),
"Complete should have run");
59 Assert.AreEqual(
"CreateInstance",
TestResults.
GetResult(
"Activate1+InitializeRoot"),
"CreateInstance should have run");
60 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeRoot"),
"InitializeInstance should have run");
68 var obj = GetInitializeListRoot();
69 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InitializeListRoot"),
"Initialize should have run");
70 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InitializeListRoot"),
"Complete should have run");
71 Assert.AreEqual(
"CreateInstance",
TestResults.
GetResult(
"Activate1+InitializeListRoot"),
"CreateInstance (list) should have run");
72 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeListRoot"),
"InitializeInstance (list) should have run");
74 Assert.AreEqual(
"CreateInstance",
TestResults.
GetResult(
"Activate1+InitializeRoot"),
"CreateInstance should have run");
75 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeRoot"),
"InitializeInstance should have run");
85 var obj = GetInitializeRoot(
"boom");
89 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InitializeRoot"),
"Initialize should have run");
90 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InitializeRoot"),
"Complete should have run");
91 Assert.IsTrue(!
string.IsNullOrEmpty(
TestResults.
GetResult(
"InterceptException+InitializeRoot")),
"Complete should have exception");
99 var obj = GetInitializeRoot(
"abc");
105 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InitializeRoot"),
"Initialize should have run");
106 Assert.AreEqual(
"Update",
TestResults.
GetResult(
"InterceptOp1+InitializeRoot"),
"Initialize op should be Update");
107 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InitializeRoot"),
"Complete should have run");
108 Assert.AreEqual(
"Update",
TestResults.
GetResult(
"InterceptOp2+InitializeRoot"),
"Complete op should be Update");
110 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeRoot"),
"InitializeInstance should have run");
118 var obj = GetInitializeListRoot();
124 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InitializeListRoot"),
"Initialize should have run");
125 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InitializeListRoot"),
"Complete should have run");
127 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeListRoot"),
"InitializeInstance (list) should have run");
130 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InitializeRoot"),
"InitializeInstance should have run");
140 var obj = dataPortal.
Create();
144 Assert.AreEqual(
"Execute",
TestResults.
GetResult(
"InterceptorCommand"),
"Execute should have run");
145 Assert.AreEqual(
"Initialize",
TestResults.
GetResult(
"Intercept1+InterceptorCommand"),
"Initialize should have run");
146 Assert.AreEqual(
"Execute",
TestResults.
GetResult(
"InterceptOp1+InterceptorCommand"),
"Initialize op should be Execute");
147 Assert.AreEqual(
"Complete",
TestResults.
GetResult(
"Intercept2+InterceptorCommand"),
"Complete should have run");
148 Assert.AreEqual(
"Execute",
TestResults.
GetResult(
"InterceptOp2+InterceptorCommand"),
"Complete op should be Execute");
150 Assert.AreEqual(
"InitializeInstance",
TestResults.
GetResult(
"Activate2+InterceptorCommand"),
"InitializeInstance should have run");
157 return dataPortal.
Create(ident);
160 private InitializeRoot GetInitializeRoot(
string ident)
164 return dataPortal.
Fetch(ident);
167 private InitializeListRoot GetInitializeListRoot()
171 return dataPortal.
Fetch();
186 private void DataPortal_Create(
string name)
191 private void DataPortal_Fetch(
string name)
196 private void Child_Fetch(
string name)
201 private void Fetch(
string name)
204 throw new Exception(
"boom");
206 using (BypassPropertyChecks)
217 private void Child_Update()
227 using (SuppressListChangedEvents)
229 Add(childDataPortal.FetchChild(
"abc"));
245 private void Create()
260 TestResults.
Add(
"InterceptOp1+" + e.ObjectType.Name, e.Operation.ToString());
266 if (e.Exception !=
null)
268 TestResults.
Add(
"InterceptOp2+" + e.ObjectType.Name, e.Operation.ToString());
276 TestResults.
Add(
"Activate1+" + requestedType.Name,
"CreateInstance");
277 return Activator.CreateInstance(requestedType);
282 TestResults.
Add(
"Activate2+" + obj.GetType().Name,
"InitializeInstance");
287 TestResults.
Add(
"Activate3+" + obj.GetType().Name,
"FinalizeInstance");
292 TestResults.
Add(
"Activate4+" + requestedType.Name,
"ResolveType");
293 return requestedType;
This is the base class from which most business objects will be derived.
This is the base class from which most business collections or lists will be derived.
This is the base class from which command objects will be derived.
Client side data portal used for making asynchronous data portal calls in .NET.
Maintains metadata about a property.
static readonly PropertyInfo< string > NameProperty
void DataPortal_Execute()
void UpdateListWithIntercept()
void InterceptException()
void UpdateWithIntercept()
void CreateWithIntercept()
static void ClassInitialize(TestContext context)
void FetchWithIntercept()
void FetchListWithIntercept()
void ExecuteCommandWithIntercept()
void InitializeInstance(object obj)
Initializes an existing business object instance.
void FinalizeInstance(object obj)
Finalizes an existing business object instance.
Type ResolveType(Type requestedType)
Gets the actual business domain class type based on the requested type (which might be an interface).
object CreateInstance(Type requestedType)
Gets a new instance of the requested type.
void Initialize(Server.InterceptArgs e)
void Complete(Server.InterceptArgs e)
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 AddOrOverwrite(string key, string value)
Overwrite an item in the test results, to indicate an outcome of a particular operation
static bool ContainsResult(string key)
Get the existence of 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
Type to carry context information for DI in unit tests
Interface defining the members of the child data portal type.
Interface defining the members of the data portal type.
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 Execute(object obj)
Called to execute a Command object on the server.
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.
@ Update
Update operation (includes insert, update and delete self).
@ Execute
Execute operation.