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.
FieldTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="FieldTests.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.Linq;
11using System.Text;
12using UnitDriven;
13#if !NUNIT
14using Microsoft.VisualStudio.TestTools.UnitTesting;
15using System.IO;
16using Csla.Reflection;
17#else
18using NUnit.Framework;
19using TestClass = NUnit.Framework.TestFixtureAttribute;
20using TestInitialize = NUnit.Framework.SetUpAttribute;
21using TestCleanup = NUnit.Framework.TearDownAttribute;
22using TestMethod = NUnit.Framework.TestAttribute;
23#endif
24
26{
27 [TestClass]
28 public class FieldTests
29 {
30
31 private class Test1 {
32#pragma warning disable CS0414
33 private string _f1 = "private"; // accessed by tests via reflection
34#pragma warning restore CS0414
35 public string _f2 = "public";
36 }
37
38 [TestMethod]
40 {
41 var instance = new Test1();
42 var expected = "private";
43 var actual = Csla.Data.DataMapper.GetFieldValue(instance, "_f1");
44 Assert.AreEqual(expected, actual);
45 }
46
47 [TestMethod]
48 public void PrivateFieldSetFail()
49 {
50 var instance = new Test1();
51 var expected = "success";
52 Csla.Data.DataMapper.SetFieldValue(instance, "_f1", expected);
53 var actual = Csla.Data.DataMapper.GetFieldValue(instance, "_f1");
54 Assert.AreEqual(expected, actual);
55 }
56
57 [TestMethod]
59 {
60 var instance = new Test1();
61 var expected = "public";
62 var actual = Csla.Data.DataMapper.GetFieldValue(instance, "_f2");
63 Assert.AreEqual(expected, actual);
64 }
65
66 [TestMethod]
68 {
69 var instance = new Test1();
70 var expected = "one";
71 Csla.Data.DataMapper.SetFieldValue(instance, "_f2", expected);
72
73 var actual = instance._f2;
74 Assert.AreEqual(expected, actual);
75 }
76 }
77}