예제 #1
0
        public void _商品を購入する()
        {
            var racks = TestHelper.InitInfinityItems(ItemRackState.CanNotPurchase);

            var pool   = TestHelper.InitInfinityReservedChange();
            var credit = new CashDeal();

            var coinMeckRole = new CoinMeckRole();
            var itemRackRole = new  ItemRackRole();

            coinMeckRole.Receive(credit, Money.Coin100);
            coinMeckRole.Receive(credit, Money.Coin10);
            coinMeckRole.Receive(credit, Money.Coin10);

            var rack = itemRackRole.FindRackAt(racks, 0);

            itemRackRole.UpdateItemSelectionState(rack, credit, pool);

            var svCount = rack.Count;

            Assert.That(itemRackRole.CanItemPurchase(rack), Is.True);

            coinMeckRole.Purchase(credit, rack.Item.Price);
            var item = itemRackRole.Purchase(rack);

            Assert.That(item, Is.Not.Null);
            Assert.That(item.Name, Is.EqualTo("Item0"));

            Assert.That(credit.UsedAmount, Is.EqualTo(120));
            Assert.That(credit.ChangedAount, Is.EqualTo(0));

            Assert.That(rack.Count, Is.EqualTo(svCount - 1));
        }
예제 #2
0
        public void _お金を入れず購入()
        {
            var role     = new CoinMeckRole();
            var received = new CashDeal();

            Assert.False(role.Purchase(received, 100));

            Assert.That(received.UsedAmount, Is.EqualTo(0));
        }
예제 #3
0
        public void _商品購入後お金を排出する(
            [ValueSource(typeof(_商品購入後お金を排出するParams), "Source")]
            _商品購入後お金を排出するParams.Parameter inParameter)
        {
            var role     = new CoinMeckRole();
            var received = new CashDeal();
            var pool     = TestHelper.InitInfinityReservedChange();

            foreach (var m in inParameter.ReceivedMoney)
            {
                for (var i = 0; i < m.Item2; ++i)
                {
                    role.Receive(received, m.Item1);
                }
            }

            Assert.True(role.Purchase(received, 100));

            var changed = role.Eject(received, pool)
                          .GroupBy(m => m)
                          .ToDictionary(g => g.Key, g => g)
            ;

            var lookup = inParameter.ChangedMoney.ToDictionary(m => m.Item1, m => m.Item2);

            Assert.That(received.RecevedMoney.Count, Is.EqualTo(0));

            Assert.That(received.UsedAmount, Is.EqualTo(100));

            Assert.That(changed.Count, Is.EqualTo(lookup.Count), "count money type (id = {0})", inParameter.Id);

            foreach (var pair in changed)
            {
                Assert.True(lookup.ContainsKey(pair.Key), "money ({0}) should be contained (id = {1})", pair.Key, inParameter.Id);
                Assert.That(pair.Value.Count(), Is.EqualTo(lookup[pair.Key]), "money ({0}) count should be equaled (id = {1})", pair.Key, inParameter.Id);
            }
        }