CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
IOTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="IOTests.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using Csla.TestHelpers;
12
13#if !NUNIT
14using Microsoft.VisualStudio.TestTools.UnitTesting;
15#else
16using NUnit.Framework;
17using TestClass = NUnit.Framework.TestFixtureAttribute;
18using TestInitialize = NUnit.Framework.SetUpAttribute;
19using TestCleanup = NUnit.Framework.TearDownAttribute;
20using TestMethod = NUnit.Framework.TestAttribute;
21#endif
22
23namespace Csla.Test.IO
24{
25 [TestClass]
26 public class IOTests
27 {
28 private static TestDIContext _testDIContext;
29
31 public static void ClassInitialize(TestContext context)
32 {
33 _testDIContext = TestDIContextFactory.CreateDefaultContext();
34 }
35
36 [TestMethod]
37 [TestCategory("SkipWhenLiveUnitTesting")]
38 public void SaveNewRoot()
39 {
41 Csla.Test.Basic.Root root = NewRoot();
42
43 root.Data = "saved";
44 Assert.AreEqual("saved", root.Data);
45 Assert.AreEqual(true, root.IsDirty);
46 Assert.AreEqual(true, root.IsValid);
47
49 root = root.Save();
50
51 Assert.IsNotNull(root);
52 //fails because no call is being made to DataPortal_Insert in Root.DataPortal_Update if IsDeleted == false and IsNew == true
53 Assert.AreEqual("Inserted", TestResults.GetResult("Root"));
54 Assert.AreEqual("saved", root.Data);
55 Assert.AreEqual(false, root.IsNew, "IsNew");
56 Assert.AreEqual(false, root.IsDeleted, "IsDeleted");
57 Assert.AreEqual(false, root.IsDirty, "IsDirty");
58 }
59
60 [TestMethod]
61 [TestCategory("SkipWhenLiveUnitTesting")]
62 public void SaveOldRoot()
63 {
65 Csla.Test.Basic.Root root = GetRoot("old");
66
67 root.Data = "saved";
68 Assert.AreEqual("saved", root.Data);
69 Assert.AreEqual(true, root.IsDirty, "IsDirty");
70 Assert.AreEqual(true, root.IsValid, "IsValid");
71
73 root = root.Save();
74
75 Assert.IsNotNull(root);
76 Assert.AreEqual("Updated", TestResults.GetResult("Root"));
77 Assert.AreEqual("saved", root.Data);
78 Assert.AreEqual(false, root.IsNew, "IsNew");
79 Assert.AreEqual(false, root.IsDeleted, "IsDeleted");
80 Assert.AreEqual(false, root.IsDirty, "IsDirty");
81 }
82
83 [TestMethod]
84 [TestCategory("SkipWhenLiveUnitTesting")]
85 public void LoadRoot()
86 {
88 Csla.Test.Basic.Root root = GetRoot("loaded");
89 Assert.IsNotNull(root);
90 Assert.AreEqual("Fetched", TestResults.GetResult("Root"));
91 Assert.AreEqual("loaded", root.Data);
92 Assert.AreEqual(false, root.IsNew);
93 Assert.AreEqual(false, root.IsDeleted);
94 Assert.AreEqual(false, root.IsDirty);
95 Assert.AreEqual(true, root.IsValid);
96 }
97
98 [TestMethod]
99 [TestCategory("SkipWhenLiveUnitTesting")]
100 public void DeleteNewRoot()
101 {
103 Csla.Test.Basic.Root root = NewRoot();
104
106 root.Delete();
107 Assert.AreEqual(true, root.IsNew);
108 Assert.AreEqual(true, root.IsDeleted);
109 Assert.AreEqual(true, root.IsDirty);
110
111 root = root.Save();
112 Assert.IsNotNull(root);
113 Assert.AreEqual("", TestResults.GetResult("Root"));
114 Assert.AreEqual(true, root.IsNew);
115 Assert.AreEqual(false, root.IsDeleted);
116 Assert.AreEqual(true, root.IsDirty);
117 }
118
119 [TestMethod]
120 [TestCategory("SkipWhenLiveUnitTesting")]
121 public void DeleteOldRoot()
122 {
124 Csla.Test.Basic.Root root = GetRoot("old");
125
127 root.Delete();
128 Assert.AreEqual(false, root.IsNew);
129 Assert.AreEqual(true, root.IsDeleted);
130 Assert.AreEqual(true, root.IsDirty);
131
132 root = root.Save();
133 Assert.IsNotNull(root);
134 Assert.AreEqual("Deleted self", TestResults.GetResult("Root"));
135 Assert.AreEqual(true, root.IsNew);
136 Assert.AreEqual(false, root.IsDeleted);
137 Assert.AreEqual(true, root.IsDirty);
138 }
139
140 [TestMethod]
141 [TestCategory("SkipWhenLiveUnitTesting")]
143 {
145 DeleteRoot("test");
146 Assert.AreEqual("Deleted", TestResults.GetResult("Root"));
147 }
148
149 [TestCleanup]
151 {
153 }
154
155 private Basic.Root NewRoot()
156 {
157 IDataPortal<Basic.Root> dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();
158
159 return dataPortal.Create(new Basic.Root.Criteria());
160 }
161
162 private Basic.Root GetRoot(string data)
163 {
164 IDataPortal<Basic.Root> dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();
165
166 return dataPortal.Fetch(new Basic.Root.Criteria(data));
167 }
168
169 private void DeleteRoot(string data)
170 {
171 IDataPortal<Basic.Root> dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();
172
173 dataPortal.Delete(new Basic.Root.Criteria(data));
174 }
175 }
176}
void DeleteNewRoot()
Definition: IOTests.cs:100
void SaveNewRoot()
Definition: IOTests.cs:38
void ClearContextsAfterEachTest()
Definition: IOTests.cs:150
void DeleteRootImmediate()
Definition: IOTests.cs:142
void SaveOldRoot()
Definition: IOTests.cs:62
static void ClassInitialize(TestContext context)
Definition: IOTests.cs:31
void DeleteOldRoot()
Definition: IOTests.cs:121
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
Definition: TestResults.cs:21
static void Reinitialise()
Reinitialise the dictionary, clearing any existing results, ready for the next test
Definition: TestResults.cs:69
static string GetResult(string key)
Get a result of an operation from the underlying results dictionary
Definition: TestResults.cs:49
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17