9using System.Collections.Generic;
12using System.Threading.Tasks;
19using Microsoft.VisualStudio.TestTools.UnitTesting;
22using TestClass = NUnit.Framework.TestFixtureAttribute;
23using TestInitialize = NUnit.Framework.SetUpAttribute;
24using TestCleanup = NUnit.Framework.TearDownAttribute;
25using TestMethod = NUnit.Framework.TestAttribute;
42 ServiceProvider serviceProvider;
45 var services =
new ServiceCollection();
47 serviceProvider = services.BuildServiceProvider();
64 [TestCategory(
"SkipWhenLiveUnitTesting")]
67 IServiceProvider serviceProvider = InitialiseServiceProviderUsingRealDashboard();
68 var dashboard = serviceProvider.GetRequiredService<
IDashboard>();
70 var obj = CreateSimpleType(serviceProvider);
72 await Task.Delay(500);
74 Assert.IsTrue(dashboard.FirstCall.Ticks > 0);
75 Assert.AreEqual(1, dashboard.TotalCalls,
"total");
76 Assert.AreEqual(0, dashboard.FailedCalls,
"failed");
77 Assert.AreEqual(1, dashboard.CompletedCalls,
"completed");
84 [TestCategory(
"SkipWhenLiveUnitTesting")]
87 IServiceProvider serviceProvider = InitialiseServiceProviderUsingRealDashboard();
88 var dashboard = serviceProvider.GetRequiredService<
IDashboard>();
92 var obj = FetchSimpleType(serviceProvider,
"123");
96 await Task.Delay(500);
98 Assert.IsTrue(dashboard.FirstCall.Ticks > 0);
99 Assert.AreEqual(1, dashboard.TotalCalls,
"total");
100 Assert.AreEqual(1, dashboard.FailedCalls,
"failed");
101 Assert.AreEqual(0, dashboard.CompletedCalls,
"completed");
108 [TestCategory(
"SkipWhenLiveUnitTesting")]
111 IServiceProvider serviceProvider = InitialiseServiceProviderUsingRealDashboard();
112 var dashboard = serviceProvider.GetRequiredService<
IDashboard>();
114 var obj = FetchSimpleType(serviceProvider, 123);
117 obj = FetchSimpleType(serviceProvider,
"123");
121 await Task.Delay(500);
123 var activity = dashboard.GetRecentActivity();
124 Assert.AreEqual(2, activity.Count,
"count");
125 Assert.IsTrue(activity.Average(r => r.Runtime.TotalMilliseconds) > 0,
"runtime");
126 Assert.AreEqual(typeof(
SimpleType).AssemblyQualifiedName, activity.Select(r => r.ObjectType).First().AssemblyQualifiedName);
130 private SimpleType CreateSimpleType(IServiceProvider serviceProvider)
133 return dataPortal.
Create();
136 private SimpleType FetchSimpleType(IServiceProvider serviceProvider,
int id)
139 return dataPortal.
Fetch(
id);
142 private SimpleType FetchSimpleType(IServiceProvider serviceProvider,
string idString)
145 return dataPortal.
Fetch(idString);
148 private IServiceProvider InitialiseServiceProviderUsingRealDashboard()
150 ServiceProvider serviceProvider;
153 var services =
new ServiceCollection();
154 services.AddCslaTesting();
159 serviceProvider = services.BuildServiceProvider();
161 return serviceProvider;
177 private void DataPortal_Create()
179 BusinessRules.CheckRules();
183 private void DataPortal_Fetch(
int id)
186 System.Threading.Thread.Sleep(10);
208 private void DataPortal_Delete(
int id)
This is the base class from which most business objects will be derived.
Maintains metadata about a property.
Data portal server dashboard.
Data portal server dashboard that records no data and consumes no meaningful overhead.
async Task DashboardRecentActivity()
async Task DashboardFailureCounter()
async Task DashboardSuccessCounter()
void DashboardDefaultIsNullDashboard()
static readonly PropertyInfo< int > IdProperty
void DataPortal_DeleteSelf()
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 Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
Data portal server dashboard.
@ Serializable
Prevents updating or inserting until the transaction is complete.
DataPortalOperations
List of data portal operations.
@ Update
Update operation (includes insert, update and delete self).
@ Create
Create operation.
@ Delete
Delete operation.