예제 #1
0
        public void CloseAccountCommand_Execute_Should_Call_Writer_With_Correct_Output()
        {
            // Arrange
            var writer         = new Mock <IWriter>();
            var userRepo       = new Mock <IUserRepository>();
            var accountingRepo = new Mock <IAccountingRepository>();
            var user           = new Mock <IUser>();

            user.Setup(x => x.PhoneNumber).Returns("123456");
            user.Setup(x => x.Bill).Returns(10m);
            user.Setup(x => x.FirstName).Returns("firstName");
            user.Setup(x => x.LastName).Returns("lastName");
            userRepo.SetupGet(x => x.Users).Returns(new List <IUser>()
            {
                user.Object
            });
            var command = new CloseAccountCommand(userRepo.Object, accountingRepo.Object, writer.Object);

            command.Parameters = new List <string>()
            {
                "closeaccount", "123456"
            };

            // Act
            command.Execute();

            // Assert
            writer.Verify(x => x.WriteLine("firstName lastName's account was closed"));
        }
예제 #2
0
        public void CloseAccountCommand_Execute_Should_Call_UserBill_Twice()
        {
            // Arrange
            var writer         = new Mock <IWriter>();
            var userRepo       = new Mock <IUserRepository>();
            var accountingRepo = new Mock <IAccountingRepository>();
            var user           = new Mock <IUser>();

            user.Setup(x => x.PhoneNumber).Returns("123456");
            user.Setup(x => x.Bill).Returns(10m);
            userRepo.SetupGet(x => x.Users).Returns(new List <IUser>()
            {
                user.Object
            });
            var command = new CloseAccountCommand(userRepo.Object, accountingRepo.Object, writer.Object);

            command.Parameters = new List <string>()
            {
                "closeaccount", "123456"
            };

            // Act
            command.Execute();

            // Assert
            user.Verify(x => x.Bill, Times.AtLeastOnce);
        }
        public async Task CloseAccountAsync(CloseAccountCommand command)
        {
            var account = BuildAccountFromDomainEvents(command.AccountNumber);
            var events  = account.CloseAccount(command);

            await this.EventStore.AddEventsAsync(events);
        }
        public async Task <BaseResponse> Delete(string id)
        {
            var closeAccountCommand = new CloseAccountCommand()
            {
                Id = id
            };

            return(await _mediator.Send(closeAccountCommand));
        }
예제 #5
0
        public async Task <IActionResult> Close(CloseAccountCommand command)
        {
            Guid closeResult = await _closeAccountCommandHandler.Execute(command);

            if (closeResult == Guid.Empty)
            {
                return(new NoContentResult());
            }
            return(Ok());
        }
        public void CloseAccount()
        {
            AccountDto accountDto;
            int        originalVersion;

            if (this.AccountDictionary.TryGetValue(this.AccountID, out accountDto))
            {
                originalVersion = accountDto.Version;
            }
            else
            {
                originalVersion = -1;
            }
            var closeCommand = new CloseAccountCommand(this.AccountID, originalVersion);

            this.bus.Send(closeCommand);
        }
예제 #7
0
        public async Task <IActionResult> Close(Guid accountId)
        {
            var command = new CloseAccountCommand
            {
                UserId    = CurrentUserId,
                AccountId = accountId
            };

            var account = await _mediator.Send(command);

            await _mediator.Send(new LogActionCommand
            {
                AccountId  = account.Id,
                ActionType = ActionType.Close
            });

            return(Ok(account));
        }
예제 #8
0
        public IEnumerable <AggregateEvent> CloseAccount(CloseAccountCommand command)
        {
            if (this.AccountState == AccountState.Closed)
            {
                throw new InvalidOperationException($"Account {AccountNumber} is already closed.");
            }

            if (this.CurrentBalance > 0)
            {
                throw new InvalidOperationException($"Account {AccountNumber} still has money on it. Please withdraw before closing.");
            }

            var aggregateEvent = new AccountClosed(command.AccountNumber, ++SequenceNumber);

            Handle(aggregateEvent);

            return(new AggregateEvent[]
            {
                aggregateEvent
            });
        }
예제 #9
0
        public void CloseAccountCommand_Execute_Should_Throw_ArgumentNullException_When_User_Not_Found()
        {
            // Arrange
            var writer         = new Mock <IWriter>();
            var userRepo       = new Mock <IUserRepository>();
            var accountingRepo = new Mock <IAccountingRepository>();
            var user           = new Mock <IUser>();

            user.Setup(x => x.PhoneNumber).Returns("123456");
            userRepo.SetupGet(x => x.Users).Returns(new List <IUser>()
            {
                user.Object
            });
            var command = new CloseAccountCommand(userRepo.Object, accountingRepo.Object, writer.Object);

            command.Parameters = new List <string>()
            {
                "closeaccount", "111111"
            };

            // Act  & Assert
            Assert.ThrowsException <ArgumentNullException>(() => command.Execute());
        }
예제 #10
0
        string BuildClose(long accountId, long customerId)
        {
            var command = new CloseAccountCommand(accountId, customerId);

            return(JsonConvert.SerializeObject(command));
        }
예제 #11
0
        public async Task <ActionResult> CloseAccount([FromBody] CloseAccountCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(result));
        }
예제 #12
0
        public void CloseAccount(Guid accountId)
        {
            var closeCommand = new CloseAccountCommand(accountId);

            bus.Publish(closeCommand);
        }