Ejemplo n.º 1
0
        public void TradeItems()
        {
            var trader1             = TestHelper.GetPlayer();
            var trader2             = TestHelper.GetPlayer();
            var tradeRequestAction  = new TradeRequestAction();
            var tradeResponseAction = new TradeAcceptAction();

            var item1 = this.GetItem();
            var item2 = this.GetItem();

            trader1.Inventory.AddItem(20, item1);
            trader1.Inventory.AddItem(21, item2);
            tradeRequestAction.RequestTrade(trader1, trader2);
            tradeResponseAction.HandleTradeAccept(trader2, true);
            var itemMoveAction = new MoveItemAction();

            itemMoveAction.MoveItem(trader1, 20, Storages.Inventory, 0, Storages.Trade);
            itemMoveAction.MoveItem(trader1, 21, Storages.Inventory, 2, Storages.Trade);
            Assert.That(trader1.TemporaryStorage.Items.First(), Is.SameAs(item1));

            var gameContext = new Mock <IGameContext>();

            gameContext.Setup(c => c.PersistenceContextProvider).Returns(new InMemoryPersistenceContextProvider());
            var tradeButtonHandler = new TradeButtonAction(gameContext.Object);

            tradeButtonHandler.TradeButtonChanged(trader1, TradeButtonState.Checked);
            tradeButtonHandler.TradeButtonChanged(trader2, TradeButtonState.Checked);
            Assert.That(trader1.Inventory.ItemStorage.Items, Is.Empty);
            Assert.That(trader2.Inventory.ItemStorage.Items.First(), Is.SameAs(item1));
        }
Ejemplo n.º 2
0
        public void TradeItems()
        {
            var trader1             = TestHelper.GetPlayer();
            var trader2             = TestHelper.GetPlayer();
            var tradeRequestAction  = new TradeRequestAction();
            var tradeResponseAction = new TradeAcceptAction();

            var item1 = this.GetItem();
            var item2 = this.GetItem();

            trader1.Inventory !.AddItem(20, item1);
            trader1.Inventory.AddItem(21, item2);
            tradeRequestAction.RequestTrade(trader1, trader2);
            tradeResponseAction.HandleTradeAccept(trader2, true);
            var itemMoveAction = new MoveItemAction();

            itemMoveAction.MoveItem(trader1, 20, Storages.Inventory, 0, Storages.Trade);
            itemMoveAction.MoveItem(trader1, 21, Storages.Inventory, 2, Storages.Trade);
            Assert.That(trader1.TemporaryStorage !.Items.First(), Is.SameAs(item1));

            var tradeButtonHandler = new TradeButtonAction();

            tradeButtonHandler.TradeButtonChanged(trader1, TradeButtonState.Checked);
            tradeButtonHandler.TradeButtonChanged(trader2, TradeButtonState.Checked);
            Assert.That(trader1.Inventory.ItemStorage.Items, Is.Empty);
            Assert.That(trader2.Inventory !.ItemStorage.Items.First(), Is.SameAs(item1));
        }
Ejemplo n.º 3
0
        public void TestTradeRequest()
        {
            var player       = this.CreateTrader(PlayerState.EnteredWorld); // The player which will send the trade request
            var tradePartner = this.CreateTrader(PlayerState.EnteredWorld); // The player which will receive the trade request

            var packetHandler = new TradeRequestAction();
            var success       = packetHandler.RequestTrade(player, tradePartner);

            Assert.AreEqual(true, success);
            Assert.AreSame(tradePartner, player.TradingPartner);
            Assert.AreSame(player, tradePartner.TradingPartner);
            Assert.AreEqual(PlayerState.TradeRequested, player.PlayerState.CurrentState);
            Assert.AreEqual(PlayerState.TradeRequested, tradePartner.PlayerState.CurrentState);
            Mock.Get(tradePartner.ViewPlugIns.GetPlugIn <IShowTradeRequestPlugIn>()).Verify(view => view !.ShowTradeRequest(player), Times.Once);
        }
Ejemplo n.º 4
0
        public void TestTradeRequest()
        {
            var player       = this.CreateTrader(PlayerState.EnteredWorld); // The player which will send the trade request
            var tradePartner = this.CreateTrader(PlayerState.EnteredWorld); // The player which will receive the trade request

            tradePartner.TradeView.Expect(view => view.ShowTradeRequest(player)).Repeat.Once();
            var packetHandler = new TradeRequestAction();
            var success       = packetHandler.RequestTrade(player, tradePartner);

            Assert.AreEqual(true, success);
            Assert.AreSame(tradePartner, player.TradingPartner);
            Assert.AreSame(player, tradePartner.TradingPartner);
            Assert.AreEqual(PlayerState.TradeRequested, player.PlayerState.CurrentState);
            Assert.AreEqual(PlayerState.TradeRequested, tradePartner.PlayerState.CurrentState);
            tradePartner.TradeView.VerifyAllExpectations();
        }