public void BeforeEach() { _objectUnderTest = new TestViewModelBase(); _changedProperties = new List <string>(); _objectUnderTest.PropertyChanged += (sender, args) => _changedProperties.Add(args.PropertyName); }
public static void Constructor_ExpectedValues() { // Call var viewModel = new TestViewModelBase(); // Assert Assert.That(viewModel, Is.InstanceOf <INotifyPropertyChanged>()); }
public void WhenVmIsInitializedPropertyIsInitializedShouldChanged() { var testViewModel = new TestViewModelBase(); testViewModel.IsInitialized.ShouldBeFalse(); ViewModelProvider.InitializeViewModel(testViewModel, null); testViewModel.IsInitialized.ShouldBeTrue(); }
public void GetActualServiceTest2() { UserControl root = new UserControl(); var service = CreateMessageService(); Interaction.GetBehaviors(root).Add(service); var viewModel = new TestViewModelBase(); root.DataContext = viewModel; Button button = new Button(); var b = new ConfirmationBehavior(); Interaction.GetBehaviors(button).Add(b); root.Content = button; Assert.AreEqual(service, viewModel.MessageBoxService); Assert.AreEqual(service, b.GetActualService()); }
public void InitializedEventShouldBeInvokedAfterViewModelWasInitialized() { var testViewModel = new TestViewModelBase(); testViewModel.IsInitialized.ShouldBeFalse(); bool isInvoked = false; Action invokeAction = () => isInvoked = true; testViewModel.Initialized += (sender, args) => invokeAction(); isInvoked.ShouldBeFalse(); ViewModelProvider.InitializeViewModel(testViewModel, null); testViewModel.IsInitialized.ShouldBeTrue(); isInvoked.ShouldBeTrue(); }
public void OnPropertyChanged_WithValidArguments_RaisesPropertyChangedEvent(string propertyName) { // Setup var viewModel = new TestViewModelBase(); PropertyChangedEventArgs eventArgs = null; bool propertyChangedTriggered = false; viewModel.PropertyChanged += (o, e) => { eventArgs = e; propertyChangedTriggered = true; }; // Call viewModel.PublicOnPropertyChanged(propertyName); // Assert Assert.That(propertyChangedTriggered, Is.True); Assert.That(eventArgs, Is.Not.Null); Assert.That(eventArgs.PropertyName, Is.EqualTo(propertyName)); }
public void GetActualServiceTest4() { UserControl root = new UserControl(); var service = CreateMessageService(); Interaction.GetBehaviors(root).Add(service); Button button = new Button(); var b = new ConfirmationBehavior(); Interaction.GetBehaviors(button).Add(b); root.DataContext = new object(); root.Content = button; var viewModel = new TestViewModelBase(); button.DataContext = viewModel; var service2 = b.GetActualService(); var service3 = b.GetActualService(); Assert.IsNotNull(viewModel.MessageBoxService); Assert.AreNotEqual(service, service2); Assert.AreEqual(service2, service3); b.MessageBoxService = service; Assert.AreEqual(service, b.GetActualService()); }
public void GetActualServiceTest3() { UserControl root = new UserControl(); var viewModel = new TestViewModelBase(); root.DataContext = viewModel; Button button = new Button(); var b = new ConfirmationBehavior(); Interaction.GetBehaviors(button).Add(b); root.Content = button; var service = b.GetActualService(); var service2 = b.GetActualService(); var service3 = Interaction.GetBehaviors(button).First(x => x is IMessageBoxService); Assert.AreEqual(service, service2); Assert.AreEqual(service, service3); }