Пример #1
0
        // With xUnit the constructor can be used for common setup.
        public ConstructorExample(Samurai samurai, Mock<IWeapon> weapon)
        {
            _samurai = samurai;

              // Arrange
              weapon.Setup (w => w.Name).Returns ("katana");
        }
Пример #2
0
        public void FightWithNukito(Samurai samurai, Mock<IWeapon> weapon)
        {
            // Arrange
              weapon.Setup (w => w.Name).Returns ("nunchaku");

              // Act
              string result = samurai.Fight();

              // Assert
              result.Should().Be ("Samurai fights with nunchaku");
              // Expectations for requested mocks are verified by default.
        }
Пример #3
0
        public void FightWithoutNukito()
        {
            // Arrange
              var weapon = new Mock<IWeapon>();
              var samurai = new Samurai (weapon.Object);
              weapon.Setup (w => w.Name).Returns ("katana");

              // Act
              string result = samurai.Fight();

              // Assert
              result.Should().Be ("Samurai fights with katana");
              weapon.VerifyAll(); // Verifies invocation of getter (IWeapon.Name)
        }