コード例 #1
0
        public void TestBatchableViewModel_ChangeModelProperty_AllPropertyChangedFired()
        {
            var listOfPropertyNames = new List <string>();
            var vm = new TestBatchableViewModel();

            vm.PropertyChanged += (sender, args) => { listOfPropertyNames.Add(args?.PropertyName); };

            vm.SetBackingModel(new TestModel(name: "Test", id: 1));

            var expectedListOfNames = new List <string>()
            {
                "Model", nameof(vm.Name), nameof(vm.ID)
            };

            Assert.IsTrue(expectedListOfNames.Except(listOfPropertyNames).Count() == 0, $"All property names expected are NOT in the fired list: expected:[{HelperMethods.GetStringFromCollection(expectedListOfNames)}], fired:[{HelperMethods.GetStringFromCollection(listOfPropertyNames)}].");
            Assert.IsTrue(listOfPropertyNames.Except(expectedListOfNames).Count() == 0, $"All property names fired are NOT in the expected list: expected:[{HelperMethods.GetStringFromCollection(expectedListOfNames)}], fired:[{HelperMethods.GetStringFromCollection(listOfPropertyNames)}].");

            CollectionAssert.AreEqual(expectedListOfNames, listOfPropertyNames, $"The expected properties of the TestViewModel: expected:[{HelperMethods.GetStringFromCollection(expectedListOfNames)}], fired:[{HelperMethods.GetStringFromCollection(listOfPropertyNames)}]. They fired in an incorrect order...");
        }
コード例 #2
0
        public void TestBatchableViewModel_InBatchMode_ChangeModelProperty_NoPropertyChangedFired()
        {
            var listOfPropertyNames = new List <string>();
            var vm = new TestBatchableViewModel();

            vm.PropertyChanged += (sender, args) => { listOfPropertyNames.Add(args?.PropertyName); };

            vm.Begin_ViewModelUpdates();
            vm.SetBackingModel(new TestModel(name: "Test", id: 1));
            vm.End_ViewModelUpdates();

            var expectedListOfNames = new List <string>()
            {
                "Model", nameof(vm.Name), nameof(vm.ID)
            };

            Assert.IsFalse(expectedListOfNames.Except(listOfPropertyNames).Count() == 0, $"Nothing should have fired...uh oh...: expected:[{HelperMethods.GetStringFromCollection(expectedListOfNames)}], fired:[{HelperMethods.GetStringFromCollection(listOfPropertyNames)}].");
            Assert.IsTrue(listOfPropertyNames.Except(expectedListOfNames).Count() == 0, $"Nothing should have fired...uh oh...: expected:[{HelperMethods.GetStringFromCollection(expectedListOfNames)}], fired:[{HelperMethods.GetStringFromCollection(listOfPropertyNames)}].");

            Assert.AreEqual(0, listOfPropertyNames.Count, "No names should have fired...uh oh...");

            CollectionAssert.AreNotEqual(expectedListOfNames, listOfPropertyNames, $"The expected properties of the TestViewModel: expected:[{HelperMethods.GetStringFromCollection(expectedListOfNames)}], fired:[{HelperMethods.GetStringFromCollection(listOfPropertyNames)}]. They fired in an incorrect order...");
        }