public void Test_sorting_items_inserted_in_sorted_order()
        {
            var item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 1, Status = WorkItemStatusEnum.Canceled
            });
            var item2 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 2, Status = WorkItemStatusEnum.Complete
            });
            var item3 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 3, Status = WorkItemStatusEnum.Failed
            });
            var item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 4, Status = WorkItemStatusEnum.Idle
            });
            var item5 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 5, Status = WorkItemStatusEnum.Pending
            });

            var items   = new ItemCollection <ActivityMonitorComponent.WorkItem>();
            var manager = new ActivityMonitorComponent.WorkItemUpdateManager(items, NoFilter, () => { });

            // insert items in sorted order, and verify that this order is preserved
            manager.Update(new [] { item1, item2, item3, item4, item5 }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

            // insert items in reverse order, and verify that they still end up in sorted order
            items.Clear();
            manager.Update(new[] { item5, item4, item3, item2, item1 }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

            // insert items out of sorted order, and verify that they still end up in sorted order
            items.Clear();
            manager.Update(new[] { item3, item5, item4, item1, item2 }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));
        }
        public void Test_sorting_update_nonsort_property_retains_order()
        {
            var item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 1, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal
            });
            var item2 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 2, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal
            });
            var item3 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 3, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal
            });
            var item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 4, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal
            });
            var item5 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 5, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal
            });

            var items = new ItemCollection <ActivityMonitorComponent.WorkItem>();

            items.AddRange(new[] { item1, item2, item3, item4, item5 });

            // the idea here is that if an item is updated, but the sorty property (Status) has not changed,
            // then the item does not move around in the list, but is updated in place
            var manager = new ActivityMonitorComponent.WorkItemUpdateManager(items, NoFilter, () => { });

            // item 1 Priority changes - should not cause a change in list order
            var x = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 1, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Stat
            });

            manager.Update(new[] { x }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

            // item 4 Priority changes - should not cause a change in list order
            var y = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 4, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.High
            });

            manager.Update(new[] { y }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));
        }
        public void Test_sorting_update_item_changes_order()
        {
            var item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 1, Status = WorkItemStatusEnum.Canceled
            });
            var item2 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 2, Status = WorkItemStatusEnum.Complete
            });
            var item3 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 3, Status = WorkItemStatusEnum.Failed
            });
            var item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 4, Status = WorkItemStatusEnum.Idle
            });
            var item5 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 5, Status = WorkItemStatusEnum.Pending
            });

            var items   = new ItemCollection <ActivityMonitorComponent.WorkItem>();
            var manager = new ActivityMonitorComponent.WorkItemUpdateManager(items, NoFilter, () => { });

            // insert items in sorted order, and verify that this order is preserved
            manager.Update(new[] { item1, item2, item3, item4, item5 }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

            // item 1 changes to Complete - should not cause a change in list order
            item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 1, Status = WorkItemStatusEnum.Canceling
            });
            manager.Update(new[] { item1 }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

            // item 4 changes to Complete, causing it to be repositioned in the list
            item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData {
                Identifier = 4, Status = WorkItemStatusEnum.Complete
            });
            manager.Update(new[] { item4 }, StatusComparison);
            Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item4, item3, item5 }) || items.SequenceEqual(new[] { item1, item4, item2, item3, item5 }));
        }
		public void Test_sorting_update_nonsort_property_retains_order()
		{
			var item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 1, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal });
			var item2 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 2, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal });
			var item3 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 3, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal });
			var item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 4, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal });
			var item5 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 5, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Normal });

			var items = new ItemCollection<ActivityMonitorComponent.WorkItem>();
			items.AddRange(new[] { item1, item2, item3, item4, item5 });

			// the idea here is that if an item is updated, but the sorty property (Status) has not changed,
			// then the item does not move around in the list, but is updated in place
			var manager = new ActivityMonitorComponent.WorkItemUpdateManager(items, NoFilter, () => { });

			// item 1 Priority changes - should not cause a change in list order
			var x = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 1, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.Stat});
			manager.Update(new[] { x }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

			// item 4 Priority changes - should not cause a change in list order
			var y = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 4, Status = WorkItemStatusEnum.Pending, Priority = WorkItemPriorityEnum.High});
			manager.Update(new[] { y }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));
		}
		public void Test_sorting_update_item_changes_order()
		{
			var item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 1, Status = WorkItemStatusEnum.Canceled });
			var item2 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 2, Status = WorkItemStatusEnum.Complete });
			var item3 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 3, Status = WorkItemStatusEnum.Failed });
			var item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 4, Status = WorkItemStatusEnum.Idle });
			var item5 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 5, Status = WorkItemStatusEnum.Pending });

			var items = new ItemCollection<ActivityMonitorComponent.WorkItem>();
			var manager = new ActivityMonitorComponent.WorkItemUpdateManager(items, NoFilter, () => { });

			// insert items in sorted order, and verify that this order is preserved
			manager.Update(new[] { item1, item2, item3, item4, item5 }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

			// item 1 changes to Complete - should not cause a change in list order
			item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 1, Status = WorkItemStatusEnum.Canceling });
			manager.Update(new[] { item1 }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

			// item 4 changes to Complete, causing it to be repositioned in the list
			item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 4, Status = WorkItemStatusEnum.Complete });
			manager.Update(new[] { item4 }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item4, item3, item5 }) || items.SequenceEqual(new[] { item1, item4, item2, item3, item5 }));
		}
		public void Test_sorting_items_inserted_in_sorted_order()
		{
			var item1 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 1, Status = WorkItemStatusEnum.Canceled });
			var item2 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 2, Status = WorkItemStatusEnum.Complete });
			var item3 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 3, Status = WorkItemStatusEnum.Failed });
			var item4 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 4, Status = WorkItemStatusEnum.Idle });
			var item5 = new ActivityMonitorComponent.WorkItem(new WorkItemData { Identifier = 5, Status = WorkItemStatusEnum.Pending });

			var items = new ItemCollection<ActivityMonitorComponent.WorkItem>();
			var manager = new ActivityMonitorComponent.WorkItemUpdateManager(items, NoFilter, () => { });

			// insert items in sorted order, and verify that this order is preserved
			manager.Update(new [] { item1, item2, item3, item4, item5 }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

			// insert items in reverse order, and verify that they still end up in sorted order
			items.Clear();
			manager.Update(new[] { item5, item4, item3, item2, item1 }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));

			// insert items out of sorted order, and verify that they still end up in sorted order
			items.Clear();
			manager.Update(new[] { item3, item5, item4, item1, item2 }, StatusComparison);
			Assert.IsTrue(items.SequenceEqual(new[] { item1, item2, item3, item4, item5 }));
		}