Esempio n. 1
0
        public void CantBuyFromBankWithoutPlayer()
        {
            var board = new Mock<IBoard>();
            var achievements = new IAchievement[0];
            var bank = new Bank(board.Object, achievements);

            Assert.Throws<ArgumentNullException>(() => bank.BuyResource(MaterialType.Brick, MaterialType.Grain, null));
        }
Esempio n. 2
0
        public void CantOfferInvalidResource(MaterialType material)
        {
            var board = new Mock<IBoard>();
            var player = new Mock<IPlayer>();

            var achievements = new IAchievement[0];
            var bank = new Bank(board.Object, achievements);
            Assert.Throws<ArgumentException>(() => bank.BuyResource(MaterialType.Grain, material, player.Object));
        }
Esempio n. 3
0
        public void BuyFailsIfPlayerHasNotTheOfferedResources()
        {
            var board = new Mock<IBoard>();
            board.Setup(b => b.GetHarbors(It.IsAny<IPlayer>())).Returns(new IHarbor[] { });

            var player = new Mock<IPlayer>();
            player.Setup(p => p.HasResources(It.IsAny<MaterialType[]>())).Returns(false);

            var achievements = new IAchievement[0];
            var bank = new Bank(board.Object, achievements);
            Assert.Throws<InvalidOperationException>(() => bank.BuyResource(MaterialType.Grain, MaterialType.Lumber, player.Object));
        }
Esempio n. 4
0
        public void BuyResourceUsesCheapestHarbor()
        {
            var board = new Mock<IBoard>();
            var resourceHarbor = new Mock<IHarbor>();
            resourceHarbor.Setup(h => h.Discount).Returns(MaterialType.Wool);
            var unsourcedHarbor = new Mock<IHarbor>();
            unsourcedHarbor.Setup(h => h.Discount).Returns(MaterialType.Unsourced);
            board.Setup(b => b.GetHarbors(It.IsAny<IPlayer>())).Returns(new IHarbor[] { unsourcedHarbor.Object, resourceHarbor.Object });

            var player = new Mock<IPlayer>();
            var offer = new MaterialType[] { MaterialType.Wool, MaterialType.Wool };
            player.Setup(p => p.HasResources(offer)).Returns(true);

            var achievements = new IAchievement[0];
            var bank = new Bank(board.Object, achievements);
            bank.BuyResource(MaterialType.Ore, MaterialType.Wool, player.Object);

            player.Verify(p => p.TakeResources(offer), Times.Once);
            player.Verify(p => p.AddResources(It.Is<IRawMaterial>(r => r.Type == MaterialType.Ore)));
        }
Esempio n. 5
0
        public void BuyResourceWithoutHarborTest()
        {
            var board = new Mock<IBoard>();
            board.Setup(b => b.GetHarbors(It.IsAny<IPlayer>())).Returns(new IHarbor[] { });

            var player = new Mock<IPlayer>();
            var offer = new MaterialType[] { MaterialType.Lumber, MaterialType.Lumber, MaterialType.Lumber, MaterialType.Lumber };
            player.Setup(p => p.HasResources(offer)).Returns(true);

            var achievements = new IAchievement[0];
            var bank = new Bank(board.Object, achievements);
            bank.BuyResource(MaterialType.Grain, MaterialType.Lumber, player.Object);

            player.Verify(p => p.TakeResources(offer), Times.Once);
            player.Verify(p => p.AddResources(It.Is<IRawMaterial>(r => r.Type == MaterialType.Grain)));
        }