Esempio n. 1
0
        public void ConstructionTest(MaterialType[] request, MaterialType[] offer)
        {
            var player = new Mock<IPlayer>();
            player.Setup(p => p.HasResources(offer)).Returns(true);

            var trade = new Trade(offer, request, player.Object);

            Assert.Equal(request, trade.Request);
            Assert.Equal(offer, trade.Offer);
            Assert.Equal(player.Object, trade.Owner);
            Assert.Equal(TradeState.Open, trade.State);
        }
Esempio n. 2
0
        public void CantAcceptIfNoOfferMaterials()
        {
            var offer = new MaterialType[] {  };
            var request = new MaterialType[] { MaterialType.Wool, MaterialType.Grain };
            var player1 = new Mock<IPlayer>();
            var player2 = new Mock<IPlayer>();
            player1.Setup(p => p.HasResources(offer)).Returns(true);
            player2.Setup(p => p.HasResources(request)).Returns(true);

            var trade = new Trade(offer, request, player1.Object);
            //canged to false after trade created
            player1.Setup(p => p.HasResources(offer)).Returns(false);

            Assert.Throws<InvalidOperationException>(() => trade.Accept(player2.Object));
        }
Esempio n. 3
0
        public void AcceptTest()
        {
            var offer = new MaterialType[] { MaterialType.Brick, MaterialType.Brick };
            var request = new MaterialType[] { MaterialType.Wool, MaterialType.Grain };
            var offeredMaterials = offer.Select(m => new RawMaterial(m)).ToArray();
            var requestedMaterrials = request.Select(m => new RawMaterial(m)).ToArray();

            var player1 = new Mock<IPlayer>();
            player1.Setup(p => p.HasResources(offer)).Returns(true);
            player1.Setup(p => p.TakeResources(offer)).Returns(offeredMaterials);

            var player2 = new Mock<IPlayer>();
            player2.Setup(p => p.HasResources(request)).Returns(true);
            player2.Setup(p => p.TakeResources(request)).Returns(requestedMaterrials);

            var trade = new Trade(offer, request, player1.Object);
            trade.Accept(player2.Object);

            player1.Verify(p => p.TakeResources(offer), Times.Once);
            player2.Verify(p => p.TakeResources(request), Times.Once);
            player1.Verify(p => p.AddResources(requestedMaterrials), Times.Once);
            player2.Verify(p => p.AddResources(offeredMaterials), Times.Once);

            Assert.Equal(TradeState.Processed, trade.State);
        }
Esempio n. 4
0
 public OpenTradeCommand NewOpenTrade(IPlayer player, MaterialType[] offer, MaterialType[] request)
 {
     var trade = new Trade(offer, request, player);
     var market = scope.Resolve<IMarket>();
     return new OpenTradeCommand(player, market, trade);
 }