Esempio n. 1
0
        public async Task Seed()
        {
            var coinReferentials = SwissFrancCoinReferential.GetAll();

            await this._context.Coins.AddRangeAsync(coinReferentials);

            await this._context.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task <List <Coin> > GetAll()
        {
            var coinsReferential = await Task.Run(() => SwissFrancCoinReferential.GetAll());

            var coins = new List <Coin>();

            coinsReferential.ForEach(c => coins.Add(new Coin(c.Id, c.Label, c.Value, 10)));

            return(coins);
        }
        [TestCase(9, 22)]      // total 2 : 4 coins (5.-), 1 coin (2.-)
        public async Task WhenCallingGetChangeWithEnoughCoinsThenReturnsOptimizedListOfCoins(int index, decimal remaningAmount)
        {
            IList <CoinBo> coinReferential = SwissFrancCoinReferential.GetAll().Select(c => new CoinBo(c.Id, c.Label, c.Value, c.Quantity)).ToList();

            this._coinBoxService.Setup(m => m.GetCoins()).Returns(Task.Run(() => coinReferential));

            var result = await this._getChangeService.GetChange(remaningAmount);

            switch (index)
            {
            case 0:
                // 1
                Assert.That(result.Count, Is.EqualTo(1));
                CheckCoinTypeExistance(
                    result,
                    Is.False,
                    Is.False,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False);
                break;

            case 1:
                // 0
                Assert.That(result, Is.Empty);
                break;

            case 2:
                // 1.45
                Assert.That(result.Count, Is.EqualTo(3));
                CheckCoinTypeExistance(
                    result,
                    Is.False,
                    Is.False,
                    Is.True,
                    Is.False,
                    Is.True,
                    Is.False,
                    Is.True);
                Assert.That(result.Find(c => c.Id == SwissFrancCoinReferential.OneFranc.Id).Quantity, Is.EqualTo(1));
                Assert.That(result.Find(c => c.Id == SwissFrancCoinReferential.TwentyCents.Id).Quantity, Is.EqualTo(2));
                Assert.That(result.Find(c => c.Id == SwissFrancCoinReferential.FiveCents.Id).Quantity, Is.EqualTo(1));
                break;

            case 3:
                // 0.05
                Assert.That(result.Count, Is.EqualTo(1));
                CheckCoinTypeExistance(
                    result,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.True);
                Assert.That(result.Find(c => c.Id == SwissFrancCoinReferential.FiveCents.Id).Quantity, Is.EqualTo(1));
                break;

            case 4:
                // 1.85
                Assert.That(result.Count, Is.EqualTo(5));
                CheckCoinTypeExistance(
                    result,
                    Is.False,
                    Is.False,
                    Is.True,
                    Is.True,
                    Is.True,
                    Is.True,
                    Is.True);
                break;

            case 5:
                // 2.40
                Assert.That(result.Count, Is.EqualTo(2));
                CheckCoinTypeExistance(
                    result,
                    Is.False,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.True,
                    Is.False,
                    Is.False);
                break;

            case 6:
                // 5
                Assert.That(result.Count, Is.EqualTo(1));
                CheckCoinTypeExistance(
                    result,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False);
                break;

            case 7:
                // 7
                Assert.That(result.Count, Is.EqualTo(2));
                CheckCoinTypeExistance(
                    result,
                    Is.True,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False);
                break;

            case 8:
                // 15.50
                Assert.That(result.Count, Is.EqualTo(2));
                CheckCoinTypeExistance(
                    result,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.False);
                break;

            case 9:
                // 22
                Assert.That(result.Count, Is.EqualTo(2));
                CheckCoinTypeExistance(
                    result,
                    Is.True,
                    Is.True,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False,
                    Is.False);
                break;

            default:
                Assert.Fail("Index not specified for Unit test");
                break;
            }
        }