9using System.Collections.Generic;
14using Microsoft.VisualStudio.TestTools.UnitTesting;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
34 _testDIContext = TestDIContextFactory.CreateDefaultContext();
42 var target = dataPortal.
Create();
43 var source =
new Dictionary<string, object>();
44 source.Add(
"MyInt", 42);
47 Assert.AreEqual(42, target.MyInt,
"Int should match");
57 Assert.AreEqual(42, target.
MyInt,
"Int should match");
60 Assert.AreEqual(24, target.
MyInt,
"Int from string should be 24");
63 Assert.AreEqual(0, target.
MyInt,
"Int from empty string should be 0");
66 Assert.AreEqual(0, target.
MyInt,
"Int from null should be 0");
69 Assert.AreEqual(4.2, target.
MyDouble,
"Double should match");
78 Assert.AreEqual(
true, target.
MyBool,
"Bool should be true");
81 Assert.AreEqual(
false, target.
MyBool,
"Bool should be false");
84 Assert.AreEqual(
false, target.
MyBool,
"Bool from empty string should be false");
87 Assert.AreEqual(
false, target.
MyBool,
"Bool from null should be false");
95 Guid testValue = Guid.NewGuid();
98 Assert.AreEqual(testValue, target.
MyGuid,
"Guid values should match");
101 Assert.AreEqual(Guid.Empty, target.
MyGuid,
"Empty guid values should match");
104 Assert.AreEqual(testValue, target.
MyGuid,
"Guid values from string should match");
113 Assert.AreEqual(42, target.
MyNInt,
"Int should match");
116 Assert.AreEqual(0, target.
MyNInt,
"Int should be 0");
119 Assert.AreEqual(
null, target.
MyNInt,
"Int from string.Empty should be null");
122 Assert.AreEqual(
null, target.
MyNInt,
"Int should be null");
146 Assert.AreEqual(DateTime.Today, target.
MyDate,
"Date should be Today");
149 Assert.AreEqual(
new DateTime(2007, 1, 1), target.
MyDate,
"Date should be 1/1/2007");
152 Assert.AreEqual(
new DateTime(2007, 1, 1), target.
MyDate,
"Date should be 1/1/2007");
169 Csla.
Data.
DataMapper.SetPropertyValue(target,
"MySmartDate",
new DateTimeOffset(
new DateTime(2004, 3, 2)));
174 Csla.
Data.
DataMapper.SetPropertyValue(target,
"MySmartDate", DateTime.Parse(
"1/1/2007"));
184 Assert.AreEqual(42, target.
MyInt,
"Int should match");
187 Assert.AreEqual(4.2, target.
MyDouble,
"Double should match");
190 Assert.AreEqual(
true, target.
MyBool,
"Bool should be true");
193 Assert.AreEqual(
false, target.
MyBool,
"Bool should be false");
201 Csla.
Data.
DataMapper.SetFieldValue(target,
"_smartDate",
new DateTimeOffset(
new DateTime(2004, 3, 2)));
216 var g = Guid.NewGuid();
220 source.
MyDate =
new DateTime(2002, 11, 2);
223 map.AddFieldMapping(
"_int",
"_int");
224 map.AddFieldToPropertyMapping(
"_double",
"MyDouble");
225 map.AddPropertyMapping(
"MyBool",
"MyBool");
226 map.AddPropertyToFieldMapping(
"MyGuid",
"_guid");
227 map.AddPropertyMapping(
"MyEnum",
"MyString");
228 map.AddPropertyMapping(
"MyString",
"MyEnum");
232 Assert.AreEqual(123, target.
MyInt,
"Int should match");
233 Assert.AreEqual(456, target.
MyDouble,
"Double should match");
234 Assert.AreEqual(
true, target.
MyBool,
"bool should match");
235 Assert.AreEqual(g, target.
MyGuid,
"guid should match");
236 Assert.AreEqual(
"Second", target.
MyString,
"string should match (converted enum)");
237 Assert.AreEqual(
DataMapEnum.Third, target.
MyEnum,
"enum should match (parsed enum)");
238 Assert.AreNotEqual(source.
MyDate, target.
MyDate,
"Dates should not match");
260 private void Create()
272 set { _int = value; }
275 private double _double;
279 get {
return _double; }
280 set { _double = value; }
287 get {
return _bool; }
288 set { _bool = value; }
291 private Nullable<int> _nint;
295 get {
return _nint; }
296 set { _nint = value; }
303 get {
return _enum; }
304 set { _enum = value; }
307 private DateTime _date;
311 get {
return _date; }
312 set { _date = value; }
319 get {
return _smartDate; }
320 set { _smartDate = value; }
327 get {
return _guid; }
328 set { _guid = value; }
331 private string _string;
334 get {
return _string; }
335 set { _string = value; }
This is the base class from which most business objects will be derived.
Defines a mapping between two sets of properties/fields for use by DataMapper.
Maintains metadata about a property.
Csla.SmartDate MySmartDate
static void ClassInitialize(TestContext context)
static PropertyInfo< int > MyIntProperty
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
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.
Provides a date data type that understands the concept of an empty date value.
EmptyValue
Indicates the empty value of a SmartDate.
bool EmptyIsMin
Gets a value indicating whether an empty date is the min or max possible date value.