コード例 #1
0
        public void Add()
        {
            var col = Bag.Of <ViewModel>()
                      .WithConvertor((Dto x) => new ViewModel(x))
                      .WithId(x => x.Id)
                      .Build();
            var added = new Dto {
                Id = 2, Name = "two"
            };

            col.Change(new NotificationEventArgs(added, OperationType.Add));

            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(added, col.First().Dto);
        }
コード例 #2
0
        public void Delete()
        {
            var item1 = new ViewModel(new Dto {
                Id = 1, Name = "one"
            });
            var item2 = new ViewModel(new Dto {
                Id = 2, Name = "two"
            });
            var col = Bag.Of <ViewModel>()
                      .WithConvertor((Dto x) => new ViewModel(x))
                      .WithId(x => x.Id)
                      .Loads(() => new ViewModel[] { item1, item2 })
                      .Build();

            var deletedItem = new Dto {
                Id = 1, Name = "one"
            };

            col.Change(new NotificationEventArgs(deletedItem, OperationType.Delete));

            Assert.AreEqual(1, col.Count);
            Assert.AreEqual("two", col.First().Name);
        }
コード例 #3
0
        public void Edit()
        {
            var item1 = new ViewModel(new Dto {
                Id = 1, Name = "one"
            });
            var item2 = new ViewModel(new Dto {
                Id = 2, Name = "two"
            });
            var col = Bag.Of <ViewModel>()
                      .WithConvertor((Dto x) => new ViewModel(x))
                      .WithId(x => x.Id)
                      .Loads(() => new ViewModel[] { item1, item2 })
                      .Build();

            var item3 = new Dto {
                Id = 2, Name = "updated two"
            };

            col.Change(new NotificationEventArgs(item3, OperationType.Update));

            Assert.AreEqual(2, col.Count);
            Assert.AreEqual(2, col.Last().Id);
            Assert.AreEqual("updated two", col.Last().Name);
        }
コード例 #4
0
 public ViewModel(Dto dto)
 {
     Dto = dto;
 }