示例#1
0
        public async Task DeleteAsync_ShouldDeleteAAction()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                var initActions = ACTION_RESULTS;
                await db.AddRangeAsync(initActions);

                await db.SaveChangesAsync();

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

                var expectedActions = await repository.GetAllAsync();

                var actionToDelete = expectedActions.First();
                expectedActions.Remove(actionToDelete);

                // Act
                await repository.DeleteAsync(actionToDelete);

                var result = await repository.GetAllAsync();

                // Assert

                var actualActions = Assert.IsAssignableFrom <List <UserActionResult> >(result);
                Assert.Equal(
                    expectedActions.OrderBy(x => x.Id).Select(x => (id: x.Id, cid: x.CreditCardId, time: x.TimeStamp, operationCode: x.OperationCode, withdrawal: x.WithdrawalAmount)),
                    actualActions.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 DeleteAsync_ShouldNotDelete()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                var actionToDelete = ACTION_NOT_IN_SEEDING_ACTIONS;
                var initActions    = ACTION_RESULTS;
                if (initActions.Exists(a => a.Id == actionToDelete.Id))
                {
                    throw new InvalidOperationException($"Seeding cards already contain the card that is not supposed to be there: {actionToDelete}");
                }
                await db.AddRangeAsync(initActions);

                await db.SaveChangesAsync();

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

                // Act
                Func <Task> action = async() => await repository.DeleteAsync(actionToDelete);

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