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.
CorerseValueTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="CorerseValueTests.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 Csla;
11using System;
12using UnitDriven;
13
14#if NUNIT
15using NUnit.Framework;
16using TestClass = NUnit.Framework.TestFixtureAttribute;
17using TestInitialize = NUnit.Framework.SetUpAttribute;
18using TestCleanup = NUnit.Framework.TearDownAttribute;
19using TestMethod = NUnit.Framework.TestAttribute;
20using TestSetup = NUnit.Framework.SetUpAttribute;
21#elif MSTEST
22using Microsoft.VisualStudio.TestTools.UnitTesting;
23#endif
24
26{
27 [TestClass]
29 {
30 [TestMethod]
31 public void TestCoerseValue()
32 {
33 UnitTestContext context = GetContext();
35
36 helper.IntProperty = 0;
37 helper.StringProperty = "1";
38 helper.IntProperty = (int)Csla.Utilities.CoerceValue(typeof(int), typeof(string), null, helper.StringProperty);
39 context.Assert.AreEqual(1, helper.IntProperty, "Should have converted to int");
40
41 helper.IntProperty = 2;
42 helper.StringProperty = "";
43 helper.StringProperty = (string)Csla.Utilities.CoerceValue(typeof(string), typeof(int), null, helper.IntProperty);
44 context.Assert.AreEqual("2", helper.StringProperty, "Should have converted to string");
45
46
47 helper.StringProperty = "1";
48 helper.NullableStringProperty = null;
49 object convertedValue = Csla.Utilities.CoerceValue(typeof(string), typeof(string), null, helper.NullableStringProperty);
50 context.Assert.IsNull(helper.NullableStringProperty);
51 context.Assert.IsNull(convertedValue);
52
53 context.Assert.AreEqual(UtilitiesTestHelper.ToStringValue, (string)Csla.Utilities.CoerceValue(typeof(string), typeof(UtilitiesTestHelper), null, helper), "Should have issued ToString()");
54 context.Assert.Success();
55 context.Complete();
56 }
57
58 [TestMethod]
60 {
61 UnitTestContext context = GetContext();
62
63 var date = DateTime.Now;
64 var smart = Csla.Utilities.CoerceValue<Csla.SmartDate>(typeof(DateTime), new Csla.SmartDate(), date);
65 context.Assert.AreEqual(date, smart.Date, "Dates should be equal");
66 context.Assert.Success();
67 context.Complete();
68 }
69 }
70}
UnitTestContext GetContext()
Definition: TestBase.cs:12
Provides a date data type that understands the concept of an empty date value.
Definition: SmartDate.cs:32