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.
Csla.test/Basic/CollectionTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="CollectionTests.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 System.Linq;
12using System.Diagnostics;
13using Csla.TestHelpers;
14
15#if !NUNIT
16using Microsoft.VisualStudio.TestTools.UnitTesting;
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
25namespace Csla.Test.Basic
26{
27 [TestClass]
28 public class CollectionTests
29 {
30 private static TestDIContext _testDIContext;
31
33 public static void ClassInitialize(TestContext context)
34 {
35 _testDIContext = TestDIContextFactory.CreateDefaultContext();
36 }
37
38 [TestMethod]
39 public void SetLast()
40 {
41 IDataPortal<TestCollection> dataPortal = _testDIContext.CreateDataPortal<TestCollection>();
42 IDataPortal<TestItem> childDataPortal = _testDIContext.CreateDataPortal<TestItem>();
43 TestCollection list = dataPortal.Create();
44 list.Add(childDataPortal.Create());
45 list.Add(childDataPortal.Create());
46 TestItem oldItem = childDataPortal.Create();
47 list.Add(oldItem);
48 TestItem newItem = childDataPortal.Create();
49 list[2] = newItem;
50 Assert.AreEqual(3, list.Count, "List should have 3 items");
51 Assert.AreEqual(newItem, list[2], "Last item should be newItem");
52 Assert.AreEqual(true, list.ContainsDeleted(oldItem), "Deleted list should have old item");
53 }
54
55 [TestMethod]
57 {
58 RootList list = new RootList();
59 RootListChild child = list.AddNew();
60 string[] rules = child.GetRuleDescriptions();
61 }
62 }
63
65 public class TestCollection : BusinessBindingListBase<TestCollection, TestItem>
66 {
68 {
69 }
70
71 [Create]
72 private void Create()
73 {
74 }
75
76 private void DataPortal_Fetch([Inject] IChildDataPortal<TestItem> childDataPortal)
77 {
78 Add(childDataPortal.FetchChild(123));
79 Add(childDataPortal.FetchChild(2));
80 Add(childDataPortal.FetchChild(13));
81 Add(childDataPortal.FetchChild(23));
82 Add(childDataPortal.FetchChild(3));
83 }
84 }
85
86 [Serializable]
87 public class TestItem : BusinessBase<TestItem>
88 {
89 private static PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
90 public int Id
91 {
92 get { return GetProperty(IdProperty); }
93 set { SetProperty(IdProperty, value); }
94 }
95
96 public bool HasParent()
97 {
98 return (Parent != null);
99 }
100
101 public TestItem()
102 {
103 MarkAsChild();
104 }
105
106 [Create]
107 [CreateChild]
108 protected override void Child_Create()
109 { }
110
111 [Fetch]
112 [FetchChild]
113 private void Child_Fetch(int id)
114 {
115 LoadProperty(IdProperty, id);
116 }
117 }
118}
This is the base class from which most business collections or lists will be derived.
Type to carry context information for DI in unit tests
Interface defining the members of the child data portal type.
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...
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Fetch
Fetch operation.