public void ContextualCommandsCollection_HasCommands_ChangedOnCollectionChange() { // Setup var testSubject = new ContextualCommandsCollection(); int hasCommandsChangedCounter = 0; ((INotifyPropertyChanged)testSubject).PropertyChanged += (o, e) => { if (e.PropertyName == "HasCommands") { hasCommandsChangedCounter++; } }; // Case 1: Add command var cmd1 = new ContextualCommandViewModel(this, new RelayCommand(() => { })); var cmd2 = new ContextualCommandViewModel(this, new RelayCommand(() => { })); // Act testSubject.Add(cmd1); testSubject.Add(cmd2); // Verify Assert.AreEqual(2, hasCommandsChangedCounter, "Adding a command should update HasCommands"); // Case 2: Remove command // Act testSubject.Remove(cmd1); // Verify Assert.AreEqual(3, hasCommandsChangedCounter, "Adding a command should update HasCommands"); // Case 3: Update command // Act testSubject[0] = cmd1; // Verify Assert.AreEqual(4, hasCommandsChangedCounter, "Adding a command should update HasCommands"); }
public void ContextualCommandsCollection_HasCommands_ChangedOnCollectionChange() { // Arrange var testSubject = new ContextualCommandsCollection(); int hasCommandsChangedCounter = 0; ((INotifyPropertyChanged)testSubject).PropertyChanged += (o, e) => { if (e.PropertyName == "HasCommands") { hasCommandsChangedCounter++; } }; // Case 1: Add command var cmd1 = new ContextualCommandViewModel(this, new RelayCommand(() => { })); var cmd2 = new ContextualCommandViewModel(this, new RelayCommand(() => { })); // Act testSubject.Add(cmd1); testSubject.Add(cmd2); // Assert hasCommandsChangedCounter.Should().Be(2, "Adding a command should update HasCommands"); // Case 2: Remove command // Act testSubject.Remove(cmd1); // Assert hasCommandsChangedCounter.Should().Be(3, "Adding a command should update HasCommands"); // Case 3: Update command // Act testSubject[0] = cmd1; // Assert hasCommandsChangedCounter.Should().Be(4, "Adding a command should update HasCommands"); }