14using System.Threading.Tasks;
20using TestClass = NUnit.Framework.TestFixtureAttribute;
21using TestInitialize = NUnit.Framework.SetUpAttribute;
22using TestCleanup = NUnit.Framework.TearDownAttribute;
23using TestMethod = NUnit.Framework.TestAttribute;
24using TestSetup = NUnit.Framework.SetUpAttribute;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
41 _testDIContext = TestDIContextFactory.CreateDefaultContext();
42 _noCloneOnUpdateDIContext = TestDIContextFactory.CreateContext(opt => opt.DataPortal(cfg => cfg.AutoCloneOnUpdate(
false)));
53 var item = await dataPortal.
FetchAsync(
"an id");
54 item.RuleField =
"some value";
56 context.
Assert.
IsFalse(item.IsSavable,
"Should not be savable");
70 items[0].RuleField =
"some value";
85 var item = await dataPortal.
FetchAsync(
"an id");
86 item.RuleField =
"some value";
92 await item.SaveAsync();
96 var error = ex as InvalidOperationException;
97 context.
Assert.IsNotNull(error);
98 context.
Assert.
IsTrue(error.Message.ToLower().Contains(
"busy"));
99 context.
Assert.
IsTrue(error.Message.ToLower().Contains(
"save"));
114 items[0].RuleField =
"some value";
124 var error = ex as InvalidOperationException;
125 context.
Assert.IsNotNull(error);
126 context.
Assert.
IsTrue(error.Message.ToLower().Contains(
"busy"));
127 context.
Assert.
IsTrue(error.Message.ToLower().Contains(
"save"));
141 var item = await dataPortal.
FetchAsync(
"an id");
142 item.ValidationComplete += (o2, e2) =>
148 item.RuleField =
"some value";
163 items[0].ValidationComplete += (o2, e2) =>
170 items[0].RuleField =
"some value";
184 items[0].ValidationComplete += async (o2, e2) =>
189 context.
Assert.AreEqual(
"DataPortal_Update", items[0].OperationResult);
193 items[0].RuleField =
"some value";
200 [ExpectedException(typeof(InvalidOperationException))]
208 var item = await dataPortal.
FetchAsync(
"an id");
209 item.RuleField =
"some value";
227 items[0].RuleField =
"some value";
230 bool gotError =
false;
235 catch (InvalidOperationException)
255 var item = await dataPortal.
FetchAsync(
"an id");
256 item.ValidationComplete += (o2, e2) =>
261 context.
Assert.AreEqual(
"DataPortal_Update", item.OperationResult);
264 item.RuleField =
"some value";
282 items[0].ValidationComplete += (o2, e2) =>
286 items = items.
Save();
287 context.
Assert.AreEqual(
"DataPortal_Update", items[0].OperationResult);
291 items[0].RuleField =
"some value";
307 var item = await dataPortal.
FetchAsync(
"an id");
308 item.OperationResult =
"something";
312 context.
Assert.AreEqual(
"DataPortal_Update", item.OperationResult);
328 items[0].OperationResult =
"something";
331 items = items.
Save();
332 context.
Assert.AreEqual(
"DataPortal_Update", items[0].OperationResult);
override bool IsBusy
Gets the busy status for this object and its child objects.
virtual bool IsSavable
Returns true if this object has changes, is valid, the user is authorized and the object is not busy.
T Save()
Saves the object to the database.
async Task< T > SaveAsync()
Saves the object to the database.
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
Type to carry context information for DI in unit tests
static ItemWithAsynchRuleList GetListWithItems(IDataPortal< ItemWithAsynchRuleList > dataPortal)
void IsFalse(bool condition)
void IsTrue(bool condition)
UnitTestContext GetContext()
async Task ListTestSaveWhileBusy()
void ListTestSaveWhileNotBusyNetOnly()
async Task TestSaveWhileBusyNetOnly()
void ListTestSaveWhileNotBusy()
async Task TestSaveWhileBusy()
async Task TestSaveWhileNotBusyNoActiveRuleNetOnly()
static void ClassInitialize(TestContext context)
async Task TestSaveWhileNotBusyNetOnly()
void ListTestSaveWhileNotBusyNoActiveRuleNetOnly()
void ListTestSaveWhileBusyNetOnly()
Interface defining the members of the data portal type.
Task< object > FetchAsync(params object[] criteria)
Starts an asynchronous data portal operation to create a business object.