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");
        }
Beispiel #2
0
        public void ContextualCommandsCollection_HasCommands()
        {
            // Arrange
            var testSubject = new ContextualCommandsCollection();

            // Case 1: no commands
            // Act + Assert
            testSubject.HasCommands.Should().BeFalse();

            // Case 2: has commands
            testSubject.Add(new ContextualCommandViewModel(this, new RelayCommand(() => { })));
            // Act + Assert
            testSubject.HasCommands.Should().BeTrue();
        }
        public void ContextualCommandsCollection_HasCommands()
        {
            // Setup
            var testSubject = new ContextualCommandsCollection();

            // Case 1: no commands
            // Act + Verify
            Assert.IsFalse(testSubject.HasCommands);

            // Case 2: has commands
            testSubject.Add(new ContextualCommandViewModel(this, new RelayCommand(()=> { })));
            // Act + Verify
            Assert.IsTrue(testSubject.HasCommands);
        }
        public void ContextualCommandsCollection_HasCommands()
        {
            // Setup
            var testSubject = new ContextualCommandsCollection();

            // Case 1: no commands
            // Act + Verify
            Assert.IsFalse(testSubject.HasCommands);

            // Case 2: has commands
            testSubject.Add(new ContextualCommandViewModel(this, new RelayCommand(() => { })));
            // Act + Verify
            Assert.IsTrue(testSubject.HasCommands);
        }
Beispiel #5
0
        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");
        }