public void Reset_NewViewModel_CollectionReplaced() { // Arrange Utils.PlayerDummy m = new Utils.PlayerDummy(); Utils.PlayerDummy modelNotified = null; CollectionViewModel <Utils.PlayerDummy, DummyPlayerVM> collection = new CollectionViewModel <Utils.PlayerDummy, DummyPlayerVM> (); collection.ViewModels.Add(new DummyPlayerVM { Model = m }); Utils.PlayerDummy mToUpdate = new Utils.PlayerDummy(); var vmToUpdate = new DummyPlayerVM { Model = mToUpdate }; // Act collection.ViewModels.Reset(new List <DummyPlayerVM> { vmToUpdate }); // Assert Assert.AreEqual(1, collection.ViewModels.Count()); }
public void Add_OneElement_SendAddNotification() { // Arrange var limitation = new CountLimitationVM { Model = new CountLicenseLimitation { Enabled = false, Maximum = 1 } }; col.Limitation = limitation; col.Model.AddRange(players); col.ViewModels.CollectionChanged += HandleCollectionChanged; var vmToAdd = new DummyPlayerVM { Model = new Utils.PlayerDummy() }; // Act col.ViewModels.Add(vmToAdd); col.ViewModels.CollectionChanged -= HandleCollectionChanged; // Assert Assert.AreEqual(1, actionsNotified.Count()); Assert.AreEqual(NotifyCollectionChangedAction.Add, actionsNotified [0]); }
public void StaticViewModel_AddViewModels_MantainsVisibility() { DummyLimitedCollectionVM collection = new DummyLimitedCollectionVM(); collection.Limitation = new CountLimitationVM { Model = new CountLicenseLimitation { Maximum = 2, Enabled = true } }; var staticVM = new DummyPlayerVM { Model = new Utils.PlayerDummy { CreationDate = DateTime.Now, Name = "P4" } }; collection.StaticViewModels.Add(staticVM); collection.ViewModels.Add(staticVM); collection.Model.AddRange(players); Assert.AreEqual(3, collection.ViewModels.Count()); Assert.AreEqual(staticVM, collection.ViewModels.Last()); }
public void ViewModelsCollectionChange_Replace_UpdateModelsAndLimitationOk() { // Arrange LimitedCollectionViewModel <Utils.PlayerDummy, DummyPlayerVM> collection = new LimitedCollectionViewModel <Utils.PlayerDummy, DummyPlayerVM> (); collection.Limitation = new CountLimitationVM { Model = new CountLicenseLimitation { Maximum = 1, Enabled = true } }; collection.ViewModels.Add(new DummyPlayerVM { Model = new Utils.PlayerDummy() }); collection.ViewModels.Add(new DummyPlayerVM { Model = new Utils.PlayerDummy() }); // Act var vmToReplace = new DummyPlayerVM { Model = new Utils.PlayerDummy() }; collection.ViewModels.Reset(new List <DummyPlayerVM> { vmToReplace }); // Assert Assert.AreEqual(1, collection.Model.Count); Assert.AreEqual(1, collection.ViewModels.Count); Assert.AreEqual(1, ((CollectionViewModel <Utils.PlayerDummy, DummyPlayerVM>)collection).ViewModels.Count); Assert.AreEqual(1, collection.LimitedViewModels.Count); Assert.IsTrue(collection.ViewModels.Contains(vmToReplace)); }