예제 #1
0
        public async Task EditAsync_ShouldEditACard()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                var initCards = ACTION_RESULTS;
                await db.AddRangeAsync(initCards);

                await db.SaveChangesAsync();

                IRepository <UserActionResult> repository = new DBUserActionResultRepository(db);

                var expectedCards = await repository.GetAllAsync();

                var cardToEdit = expectedCards.First();
                expectedCards.Remove(cardToEdit);

                cardToEdit.WithdrawalAmount += 1.00M;
                expectedCards.Add(cardToEdit);

                // Act
                await repository.EditAsync(cardToEdit);

                var result = await repository.GetAllAsync();

                // Assert

                var actualCards = Assert.IsAssignableFrom <List <UserActionResult> >(result);
                Assert.Equal(
                    expectedCards.OrderBy(x => x.Id).Select(x => (id: x.Id, cid: x.CreditCardId, time: x.TimeStamp, operationCode: x.OperationCode, withdrawal: x.WithdrawalAmount)),
                    actualCards.OrderBy(x => x.Id).Select(x => (id: x.Id, cid: x.CreditCardId, time: x.TimeStamp, operationCode: x.OperationCode, withdrawal: x.WithdrawalAmount)));
            }
        }
예제 #2
0
        public async Task EditAsync_ShouldNotEdit()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                var cardToEdit = ACTION_NOT_IN_SEEDING_ACTIONS;
                var initCards  = ACTION_RESULTS;
                if (initCards.Exists(cc => cc.Id == cardToEdit.Id))
                {
                    throw new InvalidOperationException($"Seeding cards already contain the card that is not supposed to be there: {cardToEdit}");
                }
                await db.AddRangeAsync(initCards);

                await db.SaveChangesAsync();

                IRepository <UserActionResult> repository = new DBUserActionResultRepository(db);

                // Act
                Func <Task> action = async() => await repository.EditAsync(cardToEdit);

                // Assert
                await Assert.ThrowsAsync <ArgumentException>(action);
            }
        }