public void CreaturesFactory_WhenInValidNameIsPassed_ShouldThrowArgumentException() { // Arrange var factory = new ExtendedCreatureFactory(); // Act & Assert Assert.Throws <ArgumentException>(() => factory.CreateCreature("Gosho")); }
public void CreaturesFactory_WhenValidNameIsPassed_ShouldReturnExpectedType(string name, Type expectedCreature) { //Arrange var factory = new ExtendedCreatureFactory(); //Act var creature = factory.CreateCreature(name); //Assert Assert.IsInstanceOf(expectedCreature.GetType(), creature.GetType()); }
public void CreaturesFactory_WhenInValidNameIsPassed_ShouldThrowArgumentExceptionWithExpectedMessage() { // Arrange var factory = new ExtendedCreatureFactory(); // Act & Assert (method 1) //try //{ // factory.CreateCreature("Gosho"); //} //catch (ArgumentException ex) //{ // Assert.AreEqual($"Invalid creature type \"Gosho\"!", ex.Message); //} // Act & Assert (method 2) Assert.That(() => factory.CreateCreature("Gosho"), Throws.ArgumentException.With.Message.Contains($"Invalid creature type \"Gosho\"!")); }