Пример #1
0
            public void ReturnsTheNewIndex()
            {
                List <MockItem> list = new List <MockItem>
                {
                    new MockItem {
                        Id = 0, Description = "A"
                    },
                    new MockItem {
                        Id = 1, Description = "B"
                    },
                    new MockItem {
                        Id = 2, Description = "C"
                    },
                    new MockItem {
                        Id = 3, Description = "D"
                    }
                };
                var collection = new ObservableGroupedOrderedCollection <MockItem>(i => i.Id, i => i.Description, i => i.Description.Length);

                collection.ReplaceWith(list);

                var scheduler = new TestScheduler();
                var observer  = scheduler.CreateObserver <ICollectionChange>();

                collection.CollectionChange.Subscribe(observer);

                var updated = new MockItem {
                    Id = 4, Description = "B2"
                };
                var index = collection.UpdateItem(1, updated);

                index.HasValue.Should().BeTrue();
                index.Value.Section.Should().Be(1);
                index.Value.Row.Should().Be(0);
            }
Пример #2
0
            public void SendsEventWhenUpdated()
            {
                List <MockItem> list = new List <MockItem>
                {
                    new MockItem {
                        Id = 0, Description = "A"
                    },
                    new MockItem {
                        Id = 1, Description = "B"
                    },
                    new MockItem {
                        Id = 3, Description = "D"
                    }
                };
                var collection = new ObservableGroupedOrderedCollection <MockItem>(i => i.Id, i => i.Description, i => i.Description.Length);

                collection.ReplaceWith(list);

                var scheduler = new TestScheduler();
                var observer  = scheduler.CreateObserver <ICollectionChange>();

                collection.CollectionChange.Subscribe(observer);

                var updated = new MockItem {
                    Id = 1, Description = "C"
                };

                collection.UpdateItem(updated.Id, updated);

                ICollectionChange change = new UpdateRowCollectionChange <MockItem>(new SectionedIndex(0, 1), updated);

                observer.Messages.AssertEqual(
                    OnNext(0, change)
                    );
            }
Пример #3
0
            public void CanCreateNewSectionWhenMovingItem()
            {
                List <MockItem> list = new List <MockItem>
                {
                    new MockItem {
                        Id = 0, Description = "A"
                    },
                    new MockItem {
                        Id = 1, Description = "B"
                    },
                    new MockItem {
                        Id = 3, Description = "D"
                    },
                    new MockItem {
                        Id = 8, Description = "DFE"
                    }
                };
                var collection = new ObservableGroupedOrderedCollection <MockItem>(i => i.Id, i => i.Description, i => i.Description.Length);

                collection.ReplaceWith(list);

                var scheduler = new TestScheduler();
                var observer  = scheduler.CreateObserver <ICollectionChange>();

                collection.CollectionChange.Subscribe(observer);

                var updated = new MockItem {
                    Id = 1, Description = "ED"
                };

                collection.UpdateItem(updated.Id, updated);

                List <List <MockItem> > expected = new List <List <MockItem> >
                {
                    new List <MockItem>
                    {
                        new MockItem {
                            Id = 0, Description = "A"
                        },
                        new MockItem {
                            Id = 3, Description = "D"
                        },
                    },
                    new List <MockItem>
                    {
                        new MockItem {
                            Id = 1, Description = "ED"
                        }
                    },
                    new List <MockItem>
                    {
                        new MockItem {
                            Id = 8, Description = "DFE"
                        }
                    }
                };

                CollectionAssert.AreEqual(collection, expected);
            }