Exemple #1
0
        public async void Transfer_Balance_To_Other_User_And_Check_both_balances()
        {
            //arrange
            var sourceUserId    = 1;
            var targetUserId    = 2;
            var UserName        = "******";
            var accountId       = 1;
            var targetAccountId = 2;
            //act
            var userService = new UserService(_fixture.GetDbContext(), null);
            var accountTransactionService = new AccountTransactionService(_fixture.GetDbContext(), userService);

            await accountTransactionService.ModifyBalanceAsync(new ModifyBalanceDto
                                                               { AccountId = accountId, Amount = 100, Description = "Movimiento 1", UserId = sourceUserId });

            await accountTransactionService.BalanceTransferToUserAsync(new BalanceTransferDto
                                                                       { AccountId = targetAccountId, Amount = 10, AccountIdTarget = targetAccountId, UserTarget = UserName });

            var sourceUser = await userService.GetByIdAsync(sourceUserId);

            var targetUsert = await userService.GetByIdAsync(targetUserId);

            var sourceTotalBalance = AccountServiceMock.Instance().GetTotalBalanceByAccountId(_fixture, accountId);
            var targetTotalBalance = AccountServiceMock.Instance().GetTotalBalanceByAccountId(_fixture, targetAccountId);

            //Assert
            Assert.True(sourceUser.TotalBalance.Equals(sourceTotalBalance));
            Assert.True(targetUsert.TotalBalance.Equals(targetTotalBalance));
        }
Exemple #2
0
        public async Task AccountController_ChangePassword_Success()
        {
            var email          = "*****@*****.**";
            var password       = "******";
            var accountId      = 42;
            var accountService = new AccountServiceMock()
            {
                CheckAccountPasswordResult = true,
                GetAccountByEmailAccount   = new Account {
                    Id = accountId, EmailAddress = email
                }
            };

            var authenticatorProvider = new AuthenticatorProviderMock()
            {
                Email = email
            };
            var sut = new AccountController(accountService, authenticatorProvider);

            var result = await sut.ChangePassword("oldPassword", password);

            Assert.IsTrue(result, "result");
            Assert.AreEqual(accountId, accountService.ChangedAccountId, "accountService.ChangedAccountId");
            Assert.AreEqual(password, accountService.ChangedPassword, "accountService.ChangedPassword");
        }
Exemple #3
0
        public async Task AccountController_Register_CreatesAccount()
        {
            var email    = "*****@*****.**";
            var password = "******";

            var accountService = new AccountServiceMock();
            var sut            = new AccountController(accountService, new AuthenticatorProviderMock());

            await sut.Register(email, password);

            Assert.AreEqual(email, accountService.CreatedAccountEmail, "Unexpected Email.");
            Assert.AreEqual(password, accountService.CreatedAccountPassword, "Unexpected Password");
        }
Exemple #4
0
        public async Task AccountController_Login_Fail()
        {
            var email          = "*****@*****.**";
            var accountService = new AccountServiceMock()
            {
                CheckAccountPasswordResult = false
            };
            var authenticatorProvider = new AuthenticatorProviderMock();
            var sut = new AccountController(accountService, authenticatorProvider);

            var result = await sut.Login(email, "testpassword");

            Assert.IsFalse(result, "result");
            Assert.IsFalse(authenticatorProvider.IsAuthenticated, "IsAuthenticated");
            Assert.IsNull(authenticatorProvider.Email, "Email");
        }
Exemple #5
0
        public async Task AccountController_ChangePassword_Fail_WrongPassword()
        {
            var email          = "*****@*****.**";
            var password       = "******";
            var accountService = new AccountServiceMock()
            {
                CheckAccountPasswordResult = false
            };
            var authenticatorProvider = new AuthenticatorProviderMock()
            {
                Email = email
            };
            var sut = new AccountController(accountService, authenticatorProvider);

            var result = await sut.ChangePassword("oldPassword", password);

            Assert.IsFalse(result, "result");
            Assert.IsNull(accountService.ChangedAccountId, "accountService.ChangedEmail");
            Assert.IsNull(accountService.ChangedPassword, "accountService.ChangedPassword");
        }
Exemple #6
0
        public async void Add_Balance_And_Check_balance()
        {
            //arrange
            var userId      = 3;
            var userService = new UserService(_fixture.GetDbContext(), null);
            var accountTransactionService = new AccountTransactionService(_fixture.GetDbContext(), userService);
            //act
            await accountTransactionService.ModifyBalanceAsync(new ModifyBalanceDto
                                                               { AccountId = 3, Amount = 100, Description = "Movimiento 1", UserId = userId });

            await accountTransactionService.ModifyBalanceAsync(new ModifyBalanceDto
                                                               { AccountId = 3, Amount = -5, Description = "Movimiento 2", UserId = userId });

            var user = await userService.GetByIdAsync(userId);

            var targetTotalBalance = AccountServiceMock.Instance().GetTotalBalanceByAccountId(_fixture, 3);

            //Assert
            Assert.True(user.TotalBalance.Equals(targetTotalBalance));
        }
Exemple #7
0
 public AccountServiceTest(DatabaseFixture fixture)
 {
     _fixture = fixture;
     AccountServiceMock.Instance().AddUserWithAccount(_fixture);
 }