// 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"); }
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. }
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) }