public void CantAddUnsourcedOrSea(MaterialType type) { var material = new Mock<IRawMaterial>(); material.Setup(m => m.Type).Returns(type); var player = new Player("Henk"); Assert.Throws<ArgumentException>(() => player.AddResources(material.Object)); }
public void AddResourceTest(MaterialType type) { var material = new Mock<IRawMaterial>(); material.Setup(m => m.Type).Returns(type); var player = new Player("Henk"); player.AddResources(material.Object); Assert.Contains(material.Object, player.Inventory); }
public void AddMultipleResourcesTest(IEnumerable<MaterialType> types) { IRawMaterial[] materails = types.Select(t => new RawMaterial(t)).ToArray(); var player = new Player("jkljkl"); player.AddResources(materails); foreach (var material in materails) { Assert.Contains(material, player.Inventory); } }
public void ExecuteTest() { var player = new Player("Bob"); player.AddResources(new RawMaterial(MaterialType.Brick)); var victim1 = CreatePlayer(MaterialType.Brick, MaterialType.Grain, MaterialType.Ore); var victim2 = CreatePlayer(MaterialType.Grain, MaterialType.Grain, MaterialType.Brick, MaterialType.Grain); var victims = new IPlayer[] { victim1, victim2 }; var command = new MonopolyCommand(player, victims, MaterialType.Grain); command.Execute(); Assert.Equal(4, player.Inventory.Count(r => r.Type == MaterialType.Grain)); Assert.Equal(5, player.Inventory.Count()); Assert.Equal(0, victim1.Inventory.Count(r => r.Type == MaterialType.Grain)); Assert.Equal(2, victim1.Inventory.Count()); Assert.Equal(0, victim2.Inventory.Count(r => r.Type == MaterialType.Grain)); Assert.Equal(1, victim2.Inventory.Count()); }
private static IPlayer CreatePlayer(params MaterialType[] materials) { var player = new Player("Test"); player.AddResources(materials.Select(m => new RawMaterial(m)).ToArray()); return player; }
public void CanAddNullResource() { var player = new Player("Abd"); var materials = new IRawMaterial[] { null }; Assert.Throws<ArgumentNullException>(() => player.AddResources(materials)); }
public void CantAddNullResources() { var player = new Player("ABC"); Assert.Throws<ArgumentNullException>(() => player.AddResources(null)); }
public void RemoveResourcesTest(MaterialType[] playerResources, MaterialType[] removeResources, MaterialType[] expected) { var player = new Player("Henk"); foreach (var resource in playerResources) { var mock = new Mock<IRawMaterial>(); mock.Setup(m => m.Type).Returns(resource); player.AddResources(mock.Object); } IEnumerable<IRawMaterial> materials = player.TakeResources(removeResources); Assert.Equal(expected, player.Inventory.Select(i => i.Type)); Assert.Equal(removeResources, materials.Select(m => m.Type)); Assert.Equal(removeResources.Length, materials.Count()); }
public void RemoveResourcesNotInInventoryException(MaterialType[] playerResources, MaterialType[] removeResources) { var player = new Player("Henk"); foreach (var resource in playerResources) { var mock = new Mock<IRawMaterial>(); mock.Setup(m => m.Type).Returns(resource); player.AddResources(mock.Object); } Assert.Throws<InvalidOperationException>(() => player.TakeResources(removeResources)); Assert.True(player.HasResources(playerResources)); //assert nothing gets removed when failing }
public void HasResourcesTest(MaterialType[] current, MaterialType[] requested, bool expected) { var player = new Player("Bob"); foreach (var material in current) { var mock = new Mock<IRawMaterial>(); mock.Setup(m => m.Type).Returns(material); player.AddResources(mock.Object); } bool result = player.HasResources(requested); Assert.True(expected == result, $"Expected: {expected} != result {result}.\nCurrent:{string.Join(", ", current)}\nRequested:{string.Join(", ", requested)}"); }