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.
DPMethodOverloadTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DPMethodOverloadTests.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;
12using Csla.TestHelpers;
13
14#if !NUNIT
15using Microsoft.VisualStudio.TestTools.UnitTesting;
16#else
17using NUnit.Framework;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
22#endif
23
24namespace Csla.Test.IO
25{
26 [TestClass]
28 {
29 private static TestDIContext _testDIContext;
30
32 public static void ClassInitialize(TestContext context)
33 {
34 _testDIContext = TestDIContextFactory.CreateDefaultContext();
35 }
36
37 [TestMethod]
38 [TestCategory("SkipWhenLiveUnitTesting")]
39 public void CreateNoCriteria()
40 {
41 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
42
44
45 TestBizObj obj;
46
47 obj = TestBizObj.NewNoCriteria(dataPortal);
48 Assert.IsNotNull(obj, "Failed to get object with no criteria");
49 Assert.AreEqual("No criteria", TestResults.GetResult("Create"), "No criteria expected");
50 }
51
52 [TestMethod]
53 [TestCategory("SkipWhenLiveUnitTesting")]
54 public void CreateWithCriteria()
55 {
56 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
57
59
60 TestBizObj obj;
61
62 obj = TestBizObj.NewCriteria(dataPortal);
63 Assert.IsNotNull(obj, "Failed to get object with criteria");
64 Assert.AreEqual("Criteria", TestResults.GetResult("Create"), "Criteria expected");
65 }
66
67 [TestMethod]
68 [TestCategory("SkipWhenLiveUnitTesting")]
70 {
71 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
72
74
75 TestBizObj obj;
76
77 obj = TestBizObj.NewOtherCriteria(dataPortal);
78 Assert.IsNotNull(obj, "Failed to get object with other criteria");
79 Assert.AreEqual("Other criteria", TestResults.GetResult("Create"), "Other criteria expected");
80 }
81
82 [TestMethod]
83 [TestCategory("SkipWhenLiveUnitTesting")]
84 public void FetchNullCriteria()
85 {
86 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
87
89
90 TestBizObj obj;
91
92 obj = TestBizObj.GetNullCriteria(dataPortal);
93 Assert.IsNotNull(obj, "Failed to get object with null criteria");
94 Assert.AreEqual("Null criteria", TestResults.GetResult("Fetch"), "Null criteria expected");
95 }
96
97 [TestMethod]
98 [TestCategory("SkipWhenLiveUnitTesting")]
99 public void FetchNoCriteria()
100 {
101 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
102
104
105 TestBizObj obj;
106
107 obj = TestBizObj.GetNoCriteria(dataPortal);
108 Assert.IsNotNull(obj, "Failed to get object with no criteria");
109 Assert.AreEqual("No criteria", TestResults.GetResult("Fetch"), "No criteria expected");
110 }
111
112 [TestMethod]
113 [TestCategory("SkipWhenLiveUnitTesting")]
114 public void FetchWithCriteria()
115 {
116 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
117
119
120 TestBizObj obj;
121
122 obj = TestBizObj.GetCriteria(dataPortal);
123 Assert.IsNotNull(obj, "Failed to get object with criteria");
124 Assert.AreEqual("Criteria", TestResults.GetResult("Fetch"), "Criteria expected");
125 }
126
127 [TestMethod]
128 [TestCategory("SkipWhenLiveUnitTesting")]
130 {
131 IDataPortal<TestBizObj> dataPortal = _testDIContext.CreateDataPortal<TestBizObj>();
132
134
135 TestBizObj obj;
136
137 obj = TestBizObj.GetOtherCriteria(dataPortal);
138 Assert.IsNotNull(obj, "Failed to get object with other criteria");
139 Assert.AreEqual("Other criteria", TestResults.GetResult("Fetch"), "Other criteria expected");
140 }
141 }
142
144 public class TestBizObj : Csla.BusinessBase<TestBizObj>
145 {
146 protected override object GetIdValue()
147 {
148 return 0;
149 }
150
152 {
153 return dataPortal.Create();
154 }
155
157 {
158 return dataPortal.Create(new Criteria());
159 }
160
162 {
163 return dataPortal.Create(new OtherCriteria());
164 }
165
167 {
168 return dataPortal.Fetch();
169 }
170
172 {
173 return dataPortal.Fetch(null);
174 }
175
177 {
178 return dataPortal.Fetch(new Criteria());
179 }
180
182 {
183 return dataPortal.Fetch(new OtherCriteria());
184 }
185
187 private class Criteria
188 {
189 }
190
192 private class OtherCriteria
193 {
194 }
195
196 [Create]
197 protected void DataPortal_Create()
198 {
199 TestResults.Add("Create", "No criteria");
200 BusinessRules.CheckRules();
201 }
202
203 [Create]
204 private void DataPortal_Create(object criteria)
205 {
206 if (criteria == null)
207 TestResults.Add("Create", "null criteria");
208 else
209 TestResults.Add("Create", "Other criteria");
210
211 BusinessRules.CheckRules();
212 }
213
214 [Create]
215 private void DataPortal_Create(Criteria criteria)
216 {
217 TestResults.Add("Create", "Criteria");
218 BusinessRules.CheckRules();
219 }
220
221 private void DataPortal_Fetch()
222 {
223 TestResults.Add("Fetch", "No criteria");
224 }
225
226 protected void DataPortal_Fetch(object criteria)
227 {
228 if (criteria == null)
229 TestResults.Add("Fetch", "Null criteria");
230 else
231 TestResults.Add("Fetch", "Other criteria");
232 }
233
234 private void DataPortal_Fetch(Criteria criteria)
235 {
236 TestResults.Add("Fetch", "Criteria");
237 }
238 }
239}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
static void ClassInitialize(TestContext context)
static TestBizObj NewNoCriteria(IDataPortal< TestBizObj > dataPortal)
static TestBizObj GetNullCriteria(IDataPortal< TestBizObj > dataPortal)
override object GetIdValue()
Override this method to return a unique identifying value for this object.
void DataPortal_Fetch(object criteria)
static TestBizObj NewOtherCriteria(IDataPortal< TestBizObj > dataPortal)
static TestBizObj GetCriteria(IDataPortal< TestBizObj > dataPortal)
static TestBizObj NewCriteria(IDataPortal< TestBizObj > dataPortal)
static TestBizObj GetNoCriteria(IDataPortal< TestBizObj > dataPortal)
static TestBizObj GetOtherCriteria(IDataPortal< TestBizObj > dataPortal)
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
static void Add(string key, string value)
Add an item to the test results, to indicate an outcome of a particular operation
Definition: TestResults.cs:29
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
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.