public void NumberListColumn_TypeList_Basics() { // Set up column with sample values, roundtrip, re-verify NumberListColumn <int> column = BuildSampleColumn(); // Verify second value is in a shared array, not at index zero, not expandable (yet), not ReadOnly NumberList <int> row1List = column[1]; TypedList <int> row1Typed = new TypedList <int>(row1List, (index) => index, (index) => index); // Test second sample row slice IList members on NumberListConverter CollectionChangeVerifier.VerifyList(row1Typed, (index) => index % 20); // Verify values are re-merged and re-loaded properly string values = string.Join(", ", row1List); column = TreeSerializer.RoundTrip(column, TreeFormat.Binary); Assert.Equal(values, string.Join(", ", column[1])); // TypedList Equality TypedList <int> row1 = new TypedList <int>(column[1], (index) => index, (index) => index); TypedList <int> row0 = new TypedList <int>(column[0], (index) => index, (index) => index); Assert.True(row1.Equals(row1)); Assert.False(row1.Equals(row0)); Assert.False(row1 == row0); Assert.True(row1 != row0); Assert.False(null == row0); Assert.True(null != row0); Assert.Equal(row1.GetHashCode(), row1.GetHashCode()); // TypedList.Indices Assert.Equal(row1.Indices, column[1]); // SetTo(other) TypedList <int> firstRow = new TypedList <int>(column[0], (index) => index, (index) => index); row1Typed.SetTo(firstRow); Assert.Equal(string.Join(", ", firstRow), string.Join(", ", row1Typed)); // SetTo(null) row1Typed.SetTo(null); Assert.Empty(row1Typed); // SetTo(IList) row1Typed.SetTo(new int[] { 2, 3, 4, 5 }); Assert.Equal("2, 3, 4, 5", string.Join(", ", row1Typed)); // SetTo(empty) row1Typed.SetTo(Array.Empty <int>()); Assert.Empty(row1Typed); }
public void TypedList_Basics() { Community c = new Community(); List <Person> people = new List <Person> { new Person(c) { Name = "One" }, new Person(c) { Name = "Two" }, new Person(c) { Name = "Three" } }; // Null by default Assert.Null(c.People); // Settable to Empty c.People = Array.Empty <Person>(); TypedList <Person> list = (TypedList <Person>)c.People; Assert.Empty(list); list.Add(people[0]); Assert.Single(list); list.Add(people[1]); list.Add(people[2]); CollectionReadVerifier.VerifySame(people, list); // SetTo self works properly list.SetTo(list); CollectionReadVerifier.VerifySame(people, list); // SetTo null works list.SetTo(null); Assert.Empty(list); // SetTo other works list.SetTo(people); CollectionReadVerifier.VerifySame(people, list); // Test Equality members CollectionReadVerifier.VerifyEqualityMembers(list, list); // Test equality operators #pragma warning disable CS1718 // Comparison made to same variable Assert.True(list == list); Assert.False(list != list); #pragma warning restore CS1718 // Comparison made to same variable Assert.False(list == null); Assert.True(list != null); Assert.False(null == list); Assert.True(null != list); // SetTo empty works list.SetTo(new List <Person>()); Assert.Empty(list); CollectionChangeVerifier.VerifyList(c.People, (i) => new Person(c) { Age = (byte)i }); // Set null IList <Person> cachedPeople = c.People; c.People = null; Assert.Null(c.People); Assert.Equal(0, cachedPeople.Count); // SetTo TypedList from another DB/Table Community c2 = new Community(); c2.People = new List <Person>(); c2.People.Add(new Person(c2) { Name = "Other" }); list.SetTo(c2.People); Assert.Equal("Other", list[0].Name); }