public void Factory_CreateNewHero_ShouldThrowArgumentExceptionForInvalidInput() { //Arrange IHeroFactory factory = CreateFactoryInstance(); //Act Assert.That(() => factory.CreateNewHero("", 50, 0.5f), Throws.InstanceOf <ArgumentException>(), "An empty name should not be allowed"); Assert.That(() => factory.CreateNewHero(null, 50, 0.5f), Throws.InstanceOf <ArgumentException>(), "An empty name should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 0, 0.5f), Throws.InstanceOf <ArgumentException>(), "Strength of zero or less should not be allowed"); Assert.That(() => factory.CreateNewHero("John", -10, 0.5f), Throws.InstanceOf <ArgumentException>(), "Strength of zero or less should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 101, 0.5f), Throws.InstanceOf <ArgumentException>(), "Strength bigger than 100 should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 120, 0.5f), Throws.InstanceOf <ArgumentException>(), "Strength bigger than 100 should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 50, -1.0f), Throws.InstanceOf <ArgumentException>(), "A negative supermode likeliness should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 50, -10.0f), Throws.InstanceOf <ArgumentException>(), "A negative supermode likeliness should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 50, 1.1f), Throws.InstanceOf <ArgumentException>(), "A supermode likeliness bigger than 1.0f should not be allowed"); Assert.That(() => factory.CreateNewHero("John", 50, 10.0f), Throws.InstanceOf <ArgumentException>(), "A supermode likeliness bigger than 1.0f should not be allowed"); }
private static void AssertCreateValidHero(IHeroFactory factory, string name, int strength, float superModeLikeliness) { IHero hero = factory.CreateNewHero(name, strength, superModeLikeliness); string call = $@"CreateNewHero(""{name}"", {strength}, {superModeLikeliness})"; Assert.That(hero, Is.Not.Null, $"{call} should not return null."); Assert.That(hero.Name, Is.EqualTo(name), $"{call} does not set name correctly."); Assert.That(hero.Strength, Is.EqualTo(strength), $"{call} does not set strength correctly."); Assert.That(hero.SuperModeLikeliness, Is.EqualTo(superModeLikeliness), $"{call} does not set supermode likeliness correctly."); Assert.That(hero.Health, Is.EqualTo(100), "Health should be 100."); }