public void TransferCreatesDestinationIfInexistent() { //Arrange string idOrigin = "10"; string idDestination = "11"; var repo = new AccountRepository(); var service = new AccountService(repo); var eventModel = new ProcessEventModel.Request { Type = ProcessEventModel.EventType.Transfer, Origin = idOrigin, Destination = idDestination, Amount = 10 }; repo.Add(new Account.Domain.Models.Account(idOrigin)); //Act service.ProcessEvent(eventModel); //Assert var account = repo.Get(idDestination); Assert.IsNotNull(account); }
public Result <ProcessEventModel.Response> ProcessEvent(ProcessEventModel.Request eventModel) { return(eventModel.Type switch { ProcessEventModel.EventType.Deposit => ProcessDepositEvent(eventModel), ProcessEventModel.EventType.Withdraw => ProcessWithdrawEvent(eventModel), ProcessEventModel.EventType.Transfer => ProcessTransferEvent(eventModel), _ => throw new NotImplementedException() });
public IActionResult ProcessEvent([FromBody] ProcessEventModel.Request request) { var result = _accountService.ProcessEvent(request); if (result.Errors.OfType <AccountNotFoundError>().Any()) { return(NotFound(0)); } return(Created(string.Empty, result.Data)); }
public void WithdrawErrorsIfOriginNotFound() { //Arrange var repo = new AccountRepository(); var service = new AccountService(repo); var eventModel = new ProcessEventModel.Request { Type = ProcessEventModel.EventType.Withdraw, Origin = "400", Amount = 10 }; //Act var result = service.ProcessEvent(eventModel); //Assert Assert.IsFalse(result.IsOK); Assert.IsTrue(result.Errors.OfType <AccountNotFoundError>().Any()); }
public void DepositCreatesDestinationIfInexistent() { //Arrange string id = "10"; var repo = new AccountRepository(); var service = new AccountService(repo); var eventModel = new ProcessEventModel.Request { Type = ProcessEventModel.EventType.Deposit, Destination = id, Amount = 10 }; //Act service.ProcessEvent(eventModel); //Assert var account = repo.Get(id); Assert.IsNotNull(account); }
public void TransferErrorsIfOriginNotFound() { //Arrange string idDestination = "10"; var repo = new AccountRepository(); var service = new AccountService(repo); var eventModel = new ProcessEventModel.Request { Type = ProcessEventModel.EventType.Transfer, Origin = "500", Destination = idDestination, Amount = 10 }; repo.Add(new Account.Domain.Models.Account(idDestination)); //Act var result = service.ProcessEvent(eventModel); //Assert Assert.IsFalse(result.IsOK); Assert.IsTrue(result.Errors.OfType <AccountNotFoundError>().Any()); }