9using System.Collections.Generic;
11using System.ComponentModel;
15using Microsoft.VisualStudio.TestTools.UnitTesting;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
34 _testDIContext = TestDIContextFactory.CreateDefaultContext();
40 int[] intArr = { 45, 23, 57, 56, 11, 87, 94, 44 };
44 Assert.AreEqual(
false, sortedList.
IsSorted);
45 Assert.AreEqual(56, intArr[3]);
46 sortedList.
ApplySort(
"", ListSortDirection.Ascending);
47 Assert.AreEqual(44, sortedList[2]);
48 Assert.AreEqual(8, sortedList.
Count);
49 Assert.AreEqual(
true, sortedList.
Contains(56));
50 Assert.AreEqual(4, sortedList.
IndexOf(56));
52 Assert.AreEqual(
true, sortedList.
IsSorted);
54 foreach (
int item
in sortedList)
56 Console.WriteLine(item.ToString());
59 sortedList.RemoveSort();
60 Assert.AreEqual(
false, sortedList.IsSorted);
61 Assert.AreEqual(56, sortedList[3]);
64 Assert.IsFalse(sortedList.SupportsSearching);
66 Assert.AreEqual(-1, sortedList.Find(
"", 56));
72 Console.WriteLine(
"list changed");
78 string[] strArr = {
"zandy",
"alex",
"Chris",
"bert",
"alfred",
"Bert",
"Jimmy",
"chris",
"chris",
"mobbit",
"myper",
"Corey",
"Monkey" };
81 Assert.AreEqual(
"Bert", sortedList[5]);
83 sortedList.
ApplySort(
"", ListSortDirection.Descending);
85 foreach (
string item
in sortedList)
87 Console.WriteLine(item);
90 for (
int i = 0; i < sortedList.Count; i++)
92 Console.WriteLine(
"regular loop: " + sortedList[i]);
95 Assert.AreEqual(
"Corey", sortedList[5]);
98 Console.WriteLine(sortedList.Count);
134 int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
137 int[] intArray2 = { 3, 75, 1222, 3333, 511, 443, 332 };
139 Assert.AreEqual(1222, intArray2[2]);
141 sortedList.
ApplySort(
"", ListSortDirection.Descending);
142 Assert.AreEqual(44, sortedList[0],
"Sorted values incorrect");
144 sortedList.
CopyTo(intArray2, 0);
146 Assert.AreEqual(44, intArray2[0],
"Copied values incorrect");
147 Assert.AreEqual(7, intArray2[2],
"Copied values incorrect");
149 foreach (
int item
in intArray2)
151 Console.WriteLine(item.ToString());
158 List<string> list =
new List<string>();
160 string barney =
"Barney";
161 string charlie =
"Charlie";
162 string zeke =
"Zeke";
164 list.AddRange(
new string[] { charlie, barney, zeke });
168 Assert.AreEqual(1, sortedList.
IndexOf(barney),
"Unsorted index should be 1");
170 sortedList.
ApplySort(
string.Empty, System.ComponentModel.ListSortDirection.Ascending);
172 Assert.AreEqual(1, sortedList.
IndexOf(charlie),
"Sorted index should be 1");
178 List<string> list =
new List<string>();
180 string barney =
"Barney";
181 string charlie =
"Charlie";
182 string zeke =
"Zeke";
184 list.AddRange(
new string[] { charlie, barney, zeke });
188 Assert.IsTrue(ReferenceEquals(list, sortedList.
SourceList),
"List references should match");
192 [ExpectedException(typeof(ArgumentException))]
195 int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
197 sortedList.
ApplySort(
"NotAProperty", ListSortDirection.Ascending);
201 [ExpectedException(typeof(ArgumentException))]
204 int[] intArray = { 5, 7, 1, 3, 5, 44, 32 };
206 sortedList.
Find(
"NotAProperty", 7);
214 var source = dataPortal.
Create();
218 var current = source.AddNew();
220 current.CancelEdit();
230 private void Create()
246 private void CreateChild()
248 using (BypassPropertyChecks)
250 Name = Guid.NewGuid().ToString();
This is the base class from which most business objects will be derived.
This is the base class from which most business collections or lists will be derived.
Maintains metadata about a property.
Provides a sorted view into an existing IList(Of T).
void ApplySort(string propertyName, ListSortDirection direction)
Applies a sort to the view.
int Find(string propertyName, object key)
Finds an item in the view
bool IsReadOnly
Implemented by IList source object.
bool IsSorted
Gets a value indicating whether the view is currently sorted.
ListChangedEventHandler ListChanged
Raised to indicate that the list's data has changed.
IList< T > SourceList
Gets the source list over which this SortedBindingList is a view.
int Count
Implemented by IList source object.
bool Contains(T item)
Implemented by IList source object.
int IndexOf(T item)
Implemented by IList source object.
void CopyTo(T[] array, int arrayIndex)
Implemented by IList source object.
static readonly PropertyInfo< string > NameProperty
static void ClassInitialize(TestContext context)
void ApplySort_ThrowException_WhenPropertyNameNotFound()
void sortedList_ListChanged(object sender, ListChangedEventArgs e)
void Find_ThrowException_WhenPropertyNameNotFound()
void SimulateDataBindingAdd()
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
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.