public void AccountBalanceDecreased_WhenUserWithdraws() { int accountId = 30; options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "TestingDb") .Options; using (var context = new BankAppDataContext(options)) { accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context); context.Accounts.Add(new Account { AccountId = accountId, Balance = 2000 }); context.SaveChanges(); } using (var context = new BankAppDataContext(options)) { accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context); decimal balanceBefore = accountQueriesHandler.GetAccount(accountId).Balance; decimal withdrawalAmount = 1000; accountCommandHandler.Withdraw(accountId, withdrawalAmount); decimal balanceAfter = accountQueriesHandler.GetAccount(accountId).Balance; Assert.Less(balanceAfter, balanceBefore); } }
public AccountCommandHandlerTests() { _accountRepositoryMock = new Mock <IAccountRepository>(); _jwtAuthServiceMock = new Mock <IJwtAuthService>(); _handler = new AccountCommandHandler(_accountRepositoryMock.Object, _jwtAuthServiceMock.Object); _accountRepositoryMock .Setup(x => x.GetUserByEmailAndPassword("*****@*****.**", "123")) .Returns(Task.FromResult(new User("Nicolas", "*****@*****.**", "123", UserRole.Admin))); }
public void Setup() { options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "TestingDb") .Options; systemClock = Substitute.For <ISystemClock>(); context = new BankAppDataContext(options); accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context); customerCommandHandler = new CustomerCommandHandler(context); customerQueriesHandler = new CustomerQueriesHandler(context); dispositionQueriesHandler = new DispositionQueriesHandler(context); }
public AccountService() { IEventStoreConnection esConnection = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113"); var conn = new EventStoreConnectionWrapper(esConnection); esConnection.Connected += (_, __) => { }; //Console.WriteLine("Connected"); esConnection.ConnectAsync().Wait(); IStreamNameBuilder namer = new PrefixedCamelCaseStreamNameBuilder(); IEventSerializer ser = new JsonMessageSerializer(); _repo = new StreamStoreRepository(namer, conn, ser); _cmdHandler = new AccountCommandHandler(_repo); var listener = new StreamListener("AccountAggregate", conn, namer, ser); _readModel = new BalanceReadModel(() => listener); }
protected AccountTestsBase() { AccountId = Guid.NewGuid(); IEventStoreConnection esConnection = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113"); var conn = new EventStoreConnectionWrapper(esConnection); esConnection.Connected += (_, __) => { }; esConnection.ConnectAsync().Wait(); IStreamNameBuilder namer = new PrefixedCamelCaseStreamNameBuilder("Tests"); IEventSerializer ser = new JsonMessageSerializer(); Repo = new StreamStoreRepository(namer, conn, ser); CmdHandler = new AccountCommandHandler(Repo); var listener = new StreamListener("AccountAggregate", conn, namer, ser); ReadModel = new BalanceReadModel(() => listener); }
public void InterestIsCorrectlyApplied_WhenUserActivatesInterest() { int accountId = 78; options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "TestingDb") .Options; using (var context = new BankAppDataContext(options)) { accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context, systemClock); context.Accounts.Add(new Account { AccountId = accountId, Balance = 2000 }); context.SaveChanges(); } using (var context = new BankAppDataContext(options)) { var systemClock = Substitute.For <ISystemClock>(); systemClock.GetCurrentTime().Returns(new DateTime(2020, 4, 4, 14, 0, 0, DateTimeKind.Utc)); accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context, systemClock); decimal balanceBefore = accountQueriesHandler.GetAccount(accountId).Balance; double rate = 2; DateTime latestInterestDate = new DateTime(2018, 02, 02); var currentDate = new DateTime(2020, 4, 4, 14, 0, 0, DateTimeKind.Utc); accountCommandHandler.ApplyInterest(accountId, rate, latestInterestDate); decimal balanceAfter = accountQueriesHandler.GetAccount(accountId).Balance; double days = (currentDate - latestInterestDate).TotalDays; Assert.AreEqual(balanceAfter, Decimal.Round(balanceBefore + (decimal)((double)balanceBefore * rate / 100 / 365 * days), 2)); } }
public IActionResult DeleteAccount(int accountId) { if (accountId == null) { return(BadRequest()); } try { var command = new DeleteAccountCommand(accountId); var commandHandler = new AccountCommandHandler(_accountRepository); commandHandler.Handle(command); return(Ok()); } catch (CommandValidationException <eAccountError> ex) { return(BadRequest(ex.Error.ToString())); } }
public void TransactionIsCreated_WhenUserAppliesInterest() { int accountId = 77; options = new DbContextOptionsBuilder <BankAppDataContext>() .UseInMemoryDatabase(databaseName: "TestingDb") .Options; using (var context = new BankAppDataContext(options)) { accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context, systemClock); context.Accounts.Add(new Account { AccountId = accountId, Balance = 2000 }); context.SaveChanges(); } using (var context = new BankAppDataContext(options)) { var systemClock = Substitute.For <ISystemClock>(); systemClock.GetCurrentTime().Returns(new DateTime(2020, 4, 4, 14, 0, 0, DateTimeKind.Utc)); accountQueriesHandler = new AccountQueriesHandler(context); accountCommandHandler = new AccountCommandHandler(context, systemClock); int allTransactionsBefore = context.Transactions.CountAsync().Result; double rate = 0.02; DateTime latestInterestDate = new DateTime(2018, 02, 02); var currentDate = DateTime.Now; accountCommandHandler.ApplyInterest(accountId, rate, latestInterestDate); int allTransactionsAfter = context.Transactions.CountAsync().Result; Assert.AreEqual(allTransactionsAfter, allTransactionsBefore + 1); } }
public IActionResult PutAccount([FromBody] AccountPutRequest accountPutRequest, [FromRoute] int accountId) { if (accountPutRequest == null || accountId == null) { return(BadRequest()); } try { var command = accountPutRequest.MapToCommand(accountId); var commandHandler = new AccountCommandHandler(_accountRepository); var account = commandHandler.Handle(command); var response = account.MapToResponse(); return(Ok(response)); } catch (CommandValidationException <eAccountError> ex) { return(BadRequest(ex.Error.ToString())); } }
public AccountController() { accountHandler = new AccountCommandHandler(); }
public DispositionCommandHandler(BankAppDataContext context) { this.context = context; accountCommandHandler = new AccountCommandHandler(context); }