public static void RunVerificationTest <M, T>(M vm, string propertyName, T value1, T value2)
            where M : System.ComponentModel.INotifyPropertyChanged, new()
        {
            value2.Should().NotBe(value1, "Test error: cannot run test with two equal values");

            // Arrange
            PropertyInfo property = typeof(M).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty);

            property.Should().NotBeNull("Test error: Cannot find public property (get and set ) {0}", propertyName);
            Action <T> setProperty = (v) => property.SetValue(vm, v);
            Func <T>   getProperty = () => (T)property.GetValue(vm);

            setProperty(value1);
            getProperty().Should().Be(value1, "Test error: getProperty and setProperty are not working as expected");
            ViewModelVerifier verifier = new ViewModelVerifier(vm);

            // Change
            setProperty(value2);
            verifier.propertyChanges.Should().ContainSingle(propertyName);
            verifier.Reset();

            // No change
            setProperty(value2);
            verifier.propertyChanges.Should().BeEmpty();

            // Change again
            setProperty(value1);
            verifier.propertyChanges.Should().ContainSingle(propertyName);
        }
        public void ProgressViewModel_AllPublicPropertiesNotifyChanges()
        {
            ProgressViewModel testSubject = new ProgressViewModel();

            ViewModelVerifier.RunVerificationTest(testSubject, "Value", double.NaN, 1.0);
            ViewModelVerifier.RunVerificationTest(testSubject, "IsIndeterminate", true, false);
        }
Пример #3
0
        public static void RunVerificationTest <M, T>(M vm, string propertyName, T value1, T value2)
            where M : System.ComponentModel.INotifyPropertyChanged, new()
        {
            Assert.AreNotEqual(value1, value2, "Test error: cannot run test with two equal values");

            // Setup
            PropertyInfo property = typeof(M).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty);

            Assert.IsNotNull(property, "Test error: Cannot find public property (get and set ) {0}", propertyName);
            Action <T> setProperty = (v) => property.SetValue(vm, v);
            Func <T>   getProperty = () => (T)property.GetValue(vm);

            setProperty(value1);
            Assert.AreEqual(value1, getProperty(), "Test error: getProperty and setProperty are not working as expected");
            ViewModelVerifier verifier = new ViewModelVerifier(vm);

            // Change
            setProperty(value2);
            verifier.AssertSinglePropertyChange(propertyName);
            verifier.Reset();

            // No change
            setProperty(value2);
            verifier.AssertNoPropertChanges();

            // Change again
            setProperty(value1);
            verifier.AssertSinglePropertyChange(propertyName);
        }
        public void ProgressStepViewModel_AllPublicPropertiesNotifyChanges()
        {
            ProgressStepViewModel model = new ProgressStepViewModel();

            ViewModelVerifier.RunVerificationTest <ProgressStepViewModel, string>(model, "DisplayText", "value1", "value2");
            ViewModelVerifier.RunVerificationTest <ProgressStepViewModel, StepExecutionState>(model, "ExecutionState", StepExecutionState.Cancelled, StepExecutionState.Failed);
            ViewModelVerifier.RunVerificationTest <ProgressStepViewModel, string>(model, "ProgressDetailText", null, string.Empty);
        }
Пример #5
0
        public void ProgressControllerViewModel_AllPublicPropertiesNotifyChanges()
        {
            ProgressControllerViewModel model = new ProgressControllerViewModel();
            ProgressStepViewModel       step  = new ProgressStepViewModel();

            model.Steps.Add(step);

            ViewModelVerifier.RunVerificationTest <ProgressControllerViewModel, string>(model, "Title", "value1", "value2");
            ViewModelVerifier.RunVerificationTest <ProgressControllerViewModel, ProgressStepViewModel>(model, "Current", null, step);
            ViewModelVerifier.RunVerificationTest <ProgressControllerViewModel, bool>(model, "Cancellable", true, false);
            ViewModelVerifier.RunVerificationTest <ProgressControllerViewModel, ICommand>(model, "CancelCommand", null, new RelayCommand((s) => { }));
        }