Exemplo n.º 1
0
        public async Task AddAsync_ShouldAddANewAction()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                var expectedDbAction = ACTION_NOT_IN_SEEDING_ACTIONS;
                var initActions      = ACTION_RESULTS;
                if (initActions.Exists(a => a.Id == expectedDbAction.Id))
                {
                    throw new InvalidOperationException($"Seeding actions already contain the action that is not supposed to be there: {expectedDbAction}");
                }
                await db.AddRangeAsync(initActions);

                await db.SaveChangesAsync();

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

                var expectedActions = await repository.GetAllAsync();

                expectedActions.Add(expectedDbAction);

                // Act
                await repository.AddAsync(expectedDbAction);

                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)));
            }
        }
Exemplo n.º 2
0
        public async Task AddAsync_ShouldNotAddAAction()
        {
            using (var db = new ATMContext(TestOptions.TestDbContextOptions <ATMContext>()))
            {
                // Arrange
                var expectedAction = ACTION_RESULTS.First();
                await db.AddRangeAsync(ACTION_RESULTS);

                await db.SaveChangesAsync();

                IRepository <UserActionResult> repository = new DBUserActionResultRepository(db);
                var expectedActions = await repository.GetAllAsync();

                // Act
                Func <Task> action = async() => await repository.AddAsync(expectedAction);

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