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.
IdentityTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="IdentityTests.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 System.Threading.Tasks;
13using Csla.Core;
14using Csla.TestHelpers;
15
16#if NUNIT
17using NUnit.Framework;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
22#else
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24#endif
25
27{
28 [TestClass()]
29 public class IdentityTests
30 {
31 private static TestDIContext _testDIContext;
32
34 public static void ClassInitialize(TestContext context)
35 {
36 _testDIContext = TestDIContextFactory.CreateDefaultContext();
37 }
38
39 [TestMethod]
41 {
42 IDataPortal<Foo> dataPortal = _testDIContext.CreateDataPortal<Foo>();
43
44 var obj = dataPortal.Create();
45 Assert.IsTrue(((IBusinessObject)obj).Identity >= 0);
46 }
47
48 [TestMethod]
50 {
51 IDataPortal<Foo> dataPortal = _testDIContext.CreateDataPortal<Foo>();
52
53 var obj = dataPortal.Create();
54 obj.AddChild(dataPortal);
55 Assert.IsTrue(((IBusinessObject)obj.Child).Identity >= 0);
56 Assert.IsTrue(((IBusinessObject)obj).Identity != ((IBusinessObject)obj.Child).Identity);
57 }
58
59 [TestMethod]
60 public void IdentityBaseClone()
61 {
62 IDataPortal<Foo> dataPortal = _testDIContext.CreateDataPortal<Foo>();
63
64 var obj = dataPortal.Create();
65 obj.AddChild(dataPortal);
66 obj.Child.Name = "child";
67 var cloned = obj.Clone();
68 Assert.AreEqual(((IBusinessObject)obj).Identity, ((IBusinessObject)cloned).Identity, "root");
69 Assert.AreEqual(((IBusinessObject)obj.Child).Identity, ((IBusinessObject)cloned.Child).Identity, "child");
70 }
71
72 [TestMethod]
73
75 {
76 IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
77
78 var obj = dataPortal.Create();
79 Assert.IsTrue(((IBusinessObject)obj).Identity >= 0);
80 }
81
82 [TestMethod]
84 {
85 IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
86
87 var obj = dataPortal.Create();
88 obj.AddNew();
89 Assert.IsTrue(((IBusinessObject)obj[0]).Identity >= 0);
90 Assert.IsTrue(((IBusinessObject)obj).Identity != ((IBusinessObject)obj[0]).Identity);
91 }
92
93 [TestMethod]
94
95 public void IdentityListClone()
96 {
97 IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
98
99 var obj = dataPortal.Create();
100 obj.AddNew();
101 var cloned = obj.Clone();
102 Assert.AreEqual(((IBusinessObject)obj).Identity, ((IBusinessObject)cloned).Identity, "root");
103 Assert.AreEqual(((IBusinessObject)obj[0]).Identity, ((IBusinessObject)cloned[0]).Identity, "child");
104 }
105
106 [TestMethod]
107
109 {
110 IDataPortal<FooList> dataPortal = _testDIContext.CreateDataPortal<FooList>();
111
112 var obj = dataPortal.Create();
113 obj.AddNew();
114 var cloned = obj.Clone();
115 cloned.AddNew();
116 Assert.IsTrue(((IBusinessObject)cloned[1]).Identity > -1);
117 var identities = new List<int>();
118 identities.Add(((IBusinessObject)cloned).Identity);
119 identities.Add(((IBusinessObject)cloned[0]).Identity);
120 Assert.IsFalse(identities.Contains(((IBusinessObject)cloned[1]).Identity), "new identity a repeat");
121 }
122
123 [TestMethod]
124
126 {
127 IDataPortal<FooBindingList> dataPortal = _testDIContext.CreateDataPortal<FooBindingList>();
128
129 var obj = dataPortal.Create();
130 Assert.IsTrue(((IBusinessObject)obj).Identity >= 0);
131 }
132
133 [TestMethod]
134
136 {
137 IDataPortal<FooDynamicList> dataPortal = _testDIContext.CreateDataPortal<FooDynamicList>();
138
139 var obj = dataPortal.Create();
140 Assert.IsTrue(((IBusinessObject)obj).Identity >= 0);
141 }
142
143 [TestMethod]
144
146 {
147 IDataPortal<FooDynamicBindingList> dataPortal = _testDIContext.CreateDataPortal<FooDynamicBindingList>();
148
149 var obj = dataPortal.Create();
150 Assert.IsTrue(((IBusinessObject)obj).Identity >= 0);
151 }
152 }
153}
static void ClassInitialize(TestContext context)
Type to carry context information for DI in unit tests
This is the core interface implemented by all CSLA .NET base classes.
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
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...