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.
ArrayTests.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Text;
6using System.Threading.Tasks;
7using Csla.TestHelpers;
8using Microsoft.VisualStudio.TestTools.UnitTesting;
9
11{
12 [TestClass]
13 public class ArrayTests
14 {
15 private static TestDIContext _testDIContext;
16
18 public static void ClassInitialize(TestContext context)
19 {
20 _testDIContext = TestDIContextFactory.CreateDefaultContext();
21 }
22
23 [TestMethod]
25 {
26 IDataPortal<ArrayDataPortalClass> dataPortal = _testDIContext.CreateDataPortal<ArrayDataPortalClass>();
27
29 _ = ArrayDataPortalClass.Get(dataPortal, new int[] { 1, 2, 3 });
30 Assert.AreEqual("Fetch(int[] values)", TestResults.GetResult("Method"));
31
33 _ = ArrayDataPortalClass.Get(dataPortal, new string[] { "a", "b", "c" });
34 Assert.AreEqual("Fetch(string[] values)", TestResults.GetResult("Method"));
35 }
36
37 [TestMethod]
39 {
40 IDataPortal<ArrayDataPortalClass> dataPortal = _testDIContext.CreateDataPortal<ArrayDataPortalClass>();
41
43 _ = ArrayDataPortalClass.GetParams(dataPortal, 1, 2, 3);
44 Assert.AreEqual("Fetch(int[] values)", TestResults.GetResult("Method"));
45
47 _ = ArrayDataPortalClass.GetParams(dataPortal, "a", "b", "c");
48 Assert.AreEqual("Fetch(string[] values)", TestResults.GetResult("Method"));
49 }
50
51 [TestMethod]
52 [ExpectedException(typeof(AmbiguousMatchException))]
54 {
55 IDataPortal<ArrayDataPortalClass> dataPortal = _testDIContext.CreateDataPortal<ArrayDataPortalClass>();
57
58 try
59 {
60 _ = ArrayDataPortalClass.Get(dataPortal, default(int[]));
61 }
62 catch (DataPortalException ex)
63 {
64 if (ex.InnerException != null)
65 throw ex.InnerException;
66 else
67 throw ex;
68 }
69 }
70
71 [TestMethod]
72 [ExpectedException(typeof(AmbiguousMatchException))]
74 {
75 IDataPortal<ArrayDataPortalClass> dataPortal = _testDIContext.CreateDataPortal<ArrayDataPortalClass>();
77
78 try
79 {
80 _ = ArrayDataPortalClass.Get(dataPortal, default(string[]));
81 }
82 catch (DataPortalException ex)
83 {
84 if (ex.InnerException != null)
85 throw ex.InnerException;
86 else
87 throw ex;
88 }
89 }
90
91 [TestMethod]
93 {
94 IChildDataPortal<ArrayDataPortalClass> childDataPortal = _testDIContext.CreateChildDataPortal<ArrayDataPortalClass>();
95
97 _ = ArrayDataPortalClass.GetChild(childDataPortal, new int[] { 1, 2, 3 });
98 Assert.AreEqual("FetchChild(int[] values)", TestResults.GetResult("Method"));
99
101 _ = ArrayDataPortalClass.GetChild(childDataPortal, new string[] { "a", "b", "c" });
102 Assert.AreEqual("FetchChild(string[] values)", TestResults.GetResult("Method"));
103 }
104
105 [TestMethod]
107 {
108 IChildDataPortal<ArrayDataPortalClass> childDataPortal = _testDIContext.CreateChildDataPortal<ArrayDataPortalClass>();
109
111 _ = ArrayDataPortalClass.GetChildParams(childDataPortal, 1, 2, 3);
112 Assert.AreEqual("FetchChild(int[] values)", TestResults.GetResult("Method"));
113
115 _ = ArrayDataPortalClass.GetChildParams(childDataPortal, "a", "b", "c");
116 Assert.AreEqual("FetchChild(string[] values)", TestResults.GetResult("Method"));
117 }
118
119 }
120
123 : BusinessBase<ArrayDataPortalClass>
124 {
125
126 public static ArrayDataPortalClass Get(IDataPortal<ArrayDataPortalClass> dataPortal, int[] values)
127 {
128 return dataPortal.Fetch(values);
129 }
130
131 public static ArrayDataPortalClass Get(IDataPortal<ArrayDataPortalClass> dataPortal, string[] values)
132 {
133 return dataPortal.Fetch(values);
134 }
135
136 public static ArrayDataPortalClass GetParams(IDataPortal<ArrayDataPortalClass> dataPortal, params int[] values)
137 {
138 return dataPortal.Fetch(values);
139 }
140
141 public static ArrayDataPortalClass GetParams(IDataPortal<ArrayDataPortalClass> dataPortal, params string[] values)
142 {
143 return dataPortal.Fetch(values);
144 }
145
147 {
148 return dataPortal.FetchChild(values);
149 }
150
152 {
153 return dataPortal.FetchChild(values);
154 }
155
157 {
158 return dataPortal.FetchChild(values);
159 }
160
161 public static ArrayDataPortalClass GetChildParams(IChildDataPortal<ArrayDataPortalClass> dataPortal, params string[] values)
162 {
163 return dataPortal.FetchChild(values);
164 }
165
166 [Fetch]
167 private void Fetch(int[] values)
168 {
169 TestResults.Add("Method", "Fetch(int[] values)");
170 }
171
172 [Fetch]
173 private void Fetch(string[] values)
174 {
175 TestResults.Add("Method", "Fetch(string[] values)");
176 }
177
178 [FetchChild]
179 private void FetchChild(int[] values)
180 {
181 TestResults.Add("Method", "FetchChild(int[] values)");
182 }
183
184 [FetchChild]
185 private void FetchChild(string[] values)
186 {
187 TestResults.Add("Method", "FetchChild(string[] values)");
188 }
189 }
190
191}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
This exception is returned for any errors occurring during the server-side DataPortal invocation.
static ArrayDataPortalClass GetParams(IDataPortal< ArrayDataPortalClass > dataPortal, params string[] values)
Definition: ArrayTests.cs:141
static ArrayDataPortalClass GetChildParams(IChildDataPortal< ArrayDataPortalClass > dataPortal, params int[] values)
Definition: ArrayTests.cs:156
static ArrayDataPortalClass GetChildParams(IChildDataPortal< ArrayDataPortalClass > dataPortal, params string[] values)
Definition: ArrayTests.cs:161
static ArrayDataPortalClass Get(IDataPortal< ArrayDataPortalClass > dataPortal, int[] values)
Definition: ArrayTests.cs:126
static ArrayDataPortalClass Get(IDataPortal< ArrayDataPortalClass > dataPortal, string[] values)
Definition: ArrayTests.cs:131
static ArrayDataPortalClass GetChild(IChildDataPortal< ArrayDataPortalClass > dataPortal, int[] values)
Definition: ArrayTests.cs:146
static ArrayDataPortalClass GetParams(IDataPortal< ArrayDataPortalClass > dataPortal, params int[] values)
Definition: ArrayTests.cs:136
static ArrayDataPortalClass GetChild(IChildDataPortal< ArrayDataPortalClass > dataPortal, string[] values)
Definition: ArrayTests.cs:151
static void ClassInitialize(TestContext context)
Definition: ArrayTests.cs:18
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 child data portal type.
object FetchChild(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
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...
@ Serializable
Prevents updating or inserting until the transaction is complete.