/// <summary> /// Resolve the <see cref="OrderedItemList{T}"/> from a <see cref="IEnumerable{OrderedItem}"/> that shall represent an ordered list of <see cref="Guid"/> /// </summary> /// <typeparam name="T">A type of <see cref="Thing"/></typeparam> /// <param name="list">The ordered list to resolve</param> /// <param name="orderedItemList">The source <see cref="IEnumerable{OrderedItem}"/></param> /// <param name="iterationId">The potential <see cref="Iteration"/>'id at the top of the containment tree</param> /// <param name="cache">The cache that stores the <see cref="Thing"/>s</param> internal static void ResolveList <T>(this OrderedItemList <T> list, IEnumerable <OrderedItem> orderedItemList, Guid?iterationId, ConcurrentDictionary <CacheKey, Lazy <CommonData.Thing> > cache) where T : Thing { list.Clear(); var orderedList = new List <OrderedItem>(); foreach (var item in orderedItemList) { if (!Guid.TryParse(item.V.ToString(), out var guid)) { logger.Error("The ordered item does not represent a Thing."); continue; } if (cache.TryGet(guid, iterationId, out T thing)) { var ordereditem = new OrderedItem { K = item.K, V = thing }; orderedList.Add(ordereditem); if (list.IsComposite) { thing.ChangeKind = ChangeKind.None; } } } list.AddOrderedItems(orderedList); }
public void VerifyThatAddWorks_NotCompositeList() { this.testList = new OrderedItemList<Thing>(this.person) { new EmailAddress(Guid.NewGuid(), null, null) }; Assert.AreEqual(1, this.testList.Count); Assert.IsNull(this.testList[0].Container); }
public void VerifyThatArgumentNullExceptionWhenNullIsSet() { var list = new OrderedItemList<Thing>(this.person, false); var email = new EmailAddress(Guid.NewGuid(), null, null); list.Add(email); Assert.Throws<ArgumentNullException>(() => list[0] = null); }
public void VerifyThatGetEnumeratorWork() { this.testList = new OrderedItemList<Thing>(this.person, true) { new EmailAddress(Guid.NewGuid(), null, null) }; foreach (var item in this.testList) { Assert.IsNotNull(item); } }
public void VerifyThatContainsWorks() { this.testList = new OrderedItemList<Thing>(this.person, true); var inserted = new Person(Guid.NewGuid(), null, null); testList.Add(inserted); Assert.IsTrue(this.testList.Contains(inserted)); }
public void VerifyThatOrderedItemWithPrimitiveVTypeMayBeAdded() { var orderedList = new OrderedItemList<int>(container:null); var orderedItem1 = new OrderedItem() { K = 1, V = "2" }; orderedList.AddOrderedItems(new List<OrderedItem>(){orderedItem1}); Assert.AreEqual(1, orderedList.Count); }
public void VerifyThatRemoveWorks() { var email = new EmailAddress(Guid.NewGuid(), null, null); this.testList = new OrderedItemList<Thing>(this.person, true) { email }; this.testList.Remove(email); Assert.AreEqual(0, this.testList.Count); }
public void VerifyThatSameItemCannotBeAddedTwice() { var list = new OrderedItemList<Thing>(this.person, true); var email_0 = new EmailAddress(Guid.NewGuid(), null, null); list.Add(email_0); Assert.Throws<InvalidOperationException>(() => list.Add(email_0)); }
public void VerifyThatClearWorks() { this.testList = new OrderedItemList<Thing>(this.person, true); this.testList.Add(new EmailAddress(Guid.NewGuid(), null, null)); this.testList.Add(new EmailAddress(Guid.NewGuid(), null, null)); this.testList.Clear(); Assert.AreEqual(0, this.testList.Count); }
public void VerifyThatAddWorks_CompositeList() { this.testList = new OrderedItemList<Thing>(this.person, true) { new EmailAddress(Guid.NewGuid(), null, null) }; Assert.AreEqual(1, this.testList.Count); Assert.AreEqual(this.person, this.testList[0].Container); Assert.IsTrue((-20000000L < this.testList.SortedItems.First().Key) && (20000000L > this.testList.SortedItems.First().Key)); }
public void VerifyThatAddRangeWorks() { this.testList = new OrderedItemList<Thing>(this.person, true); var listItemToAdd = new List<Thing>(); listItemToAdd.Add(new EmailAddress(Guid.NewGuid(), null, null)); listItemToAdd.Add(new TelephoneNumber(Guid.NewGuid(), null, null)); this.testList.AddRange(listItemToAdd); Assert.AreEqual(listItemToAdd.Count, this.testList.Count); }
public void VerifyThatAddingWrongOrderedItemTypeThrowsException() { var listOrderedItem = new List<OrderedItem>(); listOrderedItem.Add(new OrderedItem() { K = -2000, V = new EmailAddress(Guid.NewGuid(), null, null) }); listOrderedItem.Add(new OrderedItem() { K = 500000, V = new Person(Guid.NewGuid(), null, null) }); listOrderedItem.Add(new OrderedItem() { K = 10000000, V = "hello" }); this.testList = new OrderedItemList<Thing>(this.person, true); Assert.Throws<NotSupportedException>(() => this.testList.AddOrderedItems(listOrderedItem)); }
public void VerifyThatMoveThrowsException4() { var testlist = new OrderedItemList<Thing>(this.person, true); var email0 = new EmailAddress(Guid.NewGuid(), null, null); var email1 = new EmailAddress(Guid.NewGuid(), null, null); testlist.Add(email0); testlist.Add(email1); Assert.Throws<ArgumentOutOfRangeException>(() => testlist.Move(0, 3)); }
public void VerifyThatAddOrderedItemsWorks() { var listOrderedItem = new List<OrderedItem>(); listOrderedItem.Add(new OrderedItem() { K = -2000, V = new EmailAddress(Guid.NewGuid(), null, null) }); listOrderedItem.Add(new OrderedItem() { K = 500000, V = new Person(Guid.NewGuid(), null, null) }); listOrderedItem.Add(new OrderedItem() { K = 10000000, V = new TelephoneNumber(Guid.NewGuid(), null, null) }); this.testList = new OrderedItemList<Thing>(this.person, true); this.testList.AddOrderedItems(listOrderedItem); Assert.AreEqual(3, this.testList.Count); }
public void VerifyThatCopyToWorks() { this.testList = new OrderedItemList<Thing>(this.person, true); var inserted = new Person(Guid.NewGuid(), null, null); testList.Add(inserted); var array = new Thing[1]; this.testList.CopyTo(array, 0); Assert.IsNotNull(array[0]); }
public void VerifyThatIfInsertAtIndexGreaterThatCountItemIsAppendedToList() { var list = new OrderedItemList<Thing>(this.person, false); var email1 = new EmailAddress(Guid.NewGuid(), null, null); list.Add(email1); var index = list.Count + 1; var email2 = new EmailAddress(Guid.NewGuid(), null, null); list.Insert(index, email2); Assert.AreSame(email1, list[0]); Assert.AreSame(email2, list[1]); }
public void VerifyThatFindIndexWorks() { var testlist = new OrderedItemList<Thing>(this.person, true); var email0 = new EmailAddress(Guid.NewGuid(), null, null); var email1 = new EmailAddress(Guid.NewGuid(), null, null); testlist.Add(email0); testlist.Add(email1); Assert.AreEqual(0, testlist.FindIndex(x => x.Iid == email0.Iid)); Assert.AreEqual(-1, testlist.FindIndex(x => x.Iid == Guid.NewGuid())); Assert.Throws<ArgumentNullException>(() => testlist.FindIndex(null)); }
public void VerifyThatArgumentOutOfRangeIsThrownWhenIndexIsOutOfRange() { var list = new OrderedItemList<Thing>(this.person, false); EmailAddress email; Assert.Throws<ArgumentOutOfRangeException>(() => email = (EmailAddress)list[-1]); email = new EmailAddress(Guid.NewGuid(), null, null); list.Add(email); var invalidIndex = list.Count; Assert.Throws<ArgumentOutOfRangeException>(() => email = (EmailAddress)list[invalidIndex]); Assert.Throws<ArgumentOutOfRangeException>(() => list[-1] = email); Assert.Throws<ArgumentOutOfRangeException>(() => list[invalidIndex] = email); }
public void VerifyThatInsertWorks() { this.testList = new OrderedItemList<Thing>(this.person, true); var listItemToAdd = new List<Thing>(); listItemToAdd.Add(new EmailAddress(Guid.NewGuid(), null, null)); listItemToAdd.Add(new TelephoneNumber(Guid.NewGuid(), null, null)); this.testList.AddRange(listItemToAdd); var inserted = new Person(Guid.NewGuid(), null, null); this.testList.Insert(1, inserted); Assert.AreEqual(inserted, this.testList[1]); Assert.IsTrue(this.testList.SortedItems.Keys[1] > this.testList.SortedItems.Keys[0] && this.testList.SortedItems.Keys[2] > this.testList.SortedItems.Keys[1]); }
public void VerifyThatMoveWorks() { var testlist = new OrderedItemList<Thing>(this.person, true); var email0 = new EmailAddress(Guid.NewGuid(), null, null); var email1 = new EmailAddress(Guid.NewGuid(), null, null); var email2 = new EmailAddress(Guid.NewGuid(), null, null); var email3 = new EmailAddress(Guid.NewGuid(), null, null); var email4 = new EmailAddress(Guid.NewGuid(), null, null); testlist.Add(email0); testlist.Add(email1); testlist.Add(email2); testlist.Add(email3); testlist.Add(email4); Assert.AreSame(email0, testlist[0]); Assert.AreSame(email1, testlist[1]); Assert.AreSame(email2, testlist[2]); Assert.AreSame(email3, testlist[3]); Assert.AreSame(email4, testlist[4]); // move 1st to last testlist.Move(0, 4); Assert.AreSame(email1, testlist[0]); Assert.AreSame(email2, testlist[1]); Assert.AreSame(email3, testlist[2]); Assert.AreSame(email4, testlist[3]); Assert.AreSame(email0, testlist[4]); // move last to first testlist.Move(4, 0); Assert.AreSame(email0, testlist[0]); Assert.AreSame(email1, testlist[1]); Assert.AreSame(email2, testlist[2]); Assert.AreSame(email3, testlist[3]); Assert.AreSame(email4, testlist[4]); // does not do anything testlist.Move(0, 0); Assert.AreSame(email0, testlist[0]); Assert.AreSame(email1, testlist[1]); Assert.AreSame(email2, testlist[2]); Assert.AreSame(email3, testlist[3]); Assert.AreSame(email4, testlist[4]); }
public void VerifyThatToDtoListOrderedItemWorks() { this.testList = new OrderedItemList<Thing>(this.person, true); var email = new EmailAddress(Guid.NewGuid(), null, null); var tel = new TelephoneNumber(Guid.NewGuid(), null, null); this.testList.Add(email); this.testList.Add(tel); var dtoOrderedList = this.testList.ToDtoOrderedItemList().ToList(); Assert.AreEqual(this.testList.Count, dtoOrderedList.Count()); Assert.AreEqual(this.testList.SortedItems.Keys[0], dtoOrderedList[0].K); Assert.AreEqual(this.testList.SortedItems.Keys[1], dtoOrderedList[1].K); Assert.AreEqual(this.testList.SortedItems.Values[0].Iid, dtoOrderedList[0].V); Assert.AreEqual(this.testList.SortedItems.Values[1].Iid, dtoOrderedList[1].V); }
public void VerifyThatIndexOfReturnsTheExpectpedIndex() { this.testList = new OrderedItemList<Thing>(this.person, true); var email_0 = new EmailAddress(Guid.NewGuid(), null, null); var email_1 = new EmailAddress(Guid.NewGuid(), null, null); var email_2 = new EmailAddress(Guid.NewGuid(), null, null); var email_notcontained = new EmailAddress(Guid.NewGuid(), null, null); this.testList.Add(email_0); this.testList.Add(email_1); this.testList.Add(email_2); Assert.AreEqual(0, this.testList.IndexOf(email_0)); Assert.AreEqual(1, this.testList.IndexOf(email_1)); Assert.AreEqual(2, this.testList.IndexOf(email_2)); Assert.AreEqual(-1, this.testList.IndexOf(email_notcontained)); }
/// <summary> /// Clear and add to the <see cref="OrderedItemList{T}"/> from a <see cref="IEnumerable{OrderedItem}"/> /// </summary> /// <typeparam name="T">The generic type of the <see cref="OrderedItemList{T}"/>. This should be a primitive type that matches the value of the <see cref="DTO.Thing"/>'s <see cref="IEnumerable{OrderedItem}"/></typeparam> /// <param name="list">The <see cref="OrderedItemList{T}"/> to resolve</param> /// <param name="orderedItemList">The source <see cref="IEnumerable{OrderedItem}"/></param> internal static void ClearAndAddRange <T>(this OrderedItemList <T> list, IEnumerable <OrderedItem> orderedItemList) { list.Clear(); list.AddOrderedItems(orderedItemList); }
public void VerifyThatAddNullThrowsException() { this.testList = new OrderedItemList<Thing>(this.person, true); Assert.Throws<ArgumentNullException>(() => this.testList.Add(null)); }
public void Setup() { this.person = new Person(Guid.NewGuid(), null, null); this.testList = new OrderedItemList<Thing>(container: null); }
public void VerifyThatNullCannotBeInserted() { var list = new OrderedItemList<Thing>(this.person, false); Assert.Throws<ArgumentNullException>(() =>list.Insert(1, null)); }