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.
LazyLoadTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="LazyLoadTests.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.Text;
11using Csla.TestHelpers;
12
13#if !NUNIT
14using Microsoft.VisualStudio.TestTools.UnitTesting;
15
16#else
17using NUnit.Framework;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
22#endif
23
24namespace Csla.Test.LazyLoad
25{
26 [TestClass]
27 public class LazyLoadTests
28 {
29 private static TestDIContext _testDIContext;
30
32 public static void ClassInitialize(TestContext context)
33 {
34 _testDIContext = TestDIContextFactory.CreateDefaultContext();
35 }
36
37 [TestMethod]
38 public void NullApplyEdit()
39 {
40 AParent parent = CreateAParent();
41 Assert.IsNull(parent.GetChildList(), "GetChildList should be null");
42
43 parent.BeginEdit();
44 AChildList list = parent.ChildList;
45 Assert.IsNotNull(list, "ChildList should not be null");
46 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null");
47
48 parent.ApplyEdit();
49 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null after ApplyEdit");
50 }
51
52 [TestMethod]
53 public void NullCancelEdit()
54 {
55 AParent parent = CreateAParent();
56 Assert.IsNull(parent.GetChildList(), "GetChildList should be null");
57
58 parent.BeginEdit();
59 AChildList list = parent.ChildList;
60 Assert.IsNotNull(list, "ChildList should not be null");
61 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null");
62
63 parent.BeginEdit();
64 list = parent.ChildList;
65 Assert.IsNotNull(list, "ChildList should not be null");
66 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null after 2nd BeginEdit");
67
68 parent.CancelEdit();
69 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null after 1st CancelEdit");
70
71 parent.CancelEdit();
72 Assert.IsNull(parent.GetChildList(), "GetChildList should be null after CancelEdit");
73 }
74
75 [TestMethod]
76 public void NewChildEditLevel()
77 {
78 AParent parent = CreateAParent();
79 Assert.IsNull(parent.GetChildList(), "GetChildList should be null");
80
81 parent.BeginEdit();
82 AChildList list = parent.ChildList;
83 Assert.IsNotNull(list, "ChildList should not be null");
84 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null");
85
86 Assert.AreEqual(1, parent.EditLevel, "Parent edit level should be 1");
87 Assert.AreEqual(1, list.EditLevel, "Child list edit level should be 1");
88 Assert.AreEqual(1, list[0].EditLevel, "Child edit level should be 1");
89
90 parent.BeginEdit();
91 Assert.AreEqual(2, parent.EditLevel, "Parent edit level should be 2");
92 Assert.AreEqual(2, list.EditLevel, "Child list edit level should be 2");
93 Assert.AreEqual(2, list[0].EditLevel, "Child edit level should be 2");
94 }
95
96 [TestMethod]
98 {
99 AParent parent = CreateAParent();
100 Assert.IsNull(parent.GetChildList(), "GetChildList should be null");
101
102 parent.BeginEdit();
103 AChildList list = parent.ChildList;
104 Assert.IsNotNull(list, "ChildList should not be null");
105 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null");
106
107 Assert.AreEqual(1, parent.EditLevel, "Parent edit level should be 1");
108 Assert.AreEqual(1, list.EditLevel, "Child list edit level should be 1");
109 Assert.AreEqual(1, list[0].EditLevel, "Child edit level should be 1");
110
111 parent.CancelEdit();
112 Assert.AreEqual(0, parent.EditLevel, "Parent edit level should be 0");
113 Assert.IsNull(parent.GetChildList(), "GetChildList should be null after CancelEdit");
114 }
115
116 [TestMethod]
118 {
119 AParent parent = CreateAParent();
120 Assert.IsNull(parent.GetChildList(), "GetChildList should be null");
121
122 parent.BeginEdit();
123 AChildList list = parent.ChildList;
124 Assert.IsNotNull(list, "ChildList should not be null");
125 Assert.IsNotNull(parent.GetChildList(), "GetChildList should not be null");
126
127 Assert.AreEqual(1, parent.EditLevel, "Parent edit level should be 1");
128 Assert.AreEqual(1, list.EditLevel, "Child list edit level should be 1");
129 Assert.AreEqual(1, list[0].EditLevel, "Child edit level should be 1");
130
131 parent.ApplyEdit();
132 Assert.AreEqual(0, parent.EditLevel, "Parent edit level should be 0");
133 list = parent.GetChildList();
134 Assert.AreEqual(0, list.EditLevel, "Child list edit level should be 0");
135 Assert.AreEqual(0, list[0].EditLevel, "Child edit level should be 0");
136 }
137
138 private AParent CreateAParent()
139 {
140 IDataPortal<AParent> dataPortal = _testDIContext.CreateDataPortal<AParent>();
141
142 return dataPortal.Create();
143 }
144 }
145}
AChildList GetChildList()
Definition: AParent.cs:34
static void ClassInitialize(TestContext context)
Type to carry context information for DI in unit tests
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...