示例#1
0
        public async Task Handle_CreateAccountNonExistingAccountType_ShouldReturnBusinessException()
        {
            var handler = new AccountCreateHandler(Mapper, _mockRepo.Object);

            var request = new AccountCreateRequest {
                AccountTypeId = 1, CustomerId = 2
            };

            MockReturnNullAccount();

            _mockRepo
            .Setup(repo => repo.Customer.FindById(It.Is <int>(c => c == request.CustomerId), It.IsAny <List <string> >()))
            .Returns(new Customer {
                Id = request.CustomerId.Value
            })
            .Verifiable();

            _mockRepo
            .Setup(repo => repo.AccountType.FindById(It.Is <int>(at => at == request.AccountTypeId), It.IsAny <List <string> >()))
            .Returns(null as AccountType)
            .Verifiable();

            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(request, default));

            _mockRepo.Verify();
        }
示例#2
0
        public async Task Handle_CreateExistingAccount_ShouldReturnBusinessException()
        {
            var handler = new AccountCreateHandler(Mapper, _mockRepo.Object);

            var existingAccount = GetTestAccount();

            _mockRepo
            .Setup(repo => repo.Account.FindSingle(It.IsAny <Expression <Func <Account, bool> > >(), It.IsAny <List <string> >()))
            .Returns(existingAccount);

            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(new AccountCreateRequest {
                AccountTypeId = 1, CustomerId = 2
            }, default));
        }
示例#3
0
        public async Task Handle_CreateNewAccount_ShouldReturnNewAccount()
        {
            var handler = new AccountCreateHandler(Mapper, _mockRepo.Object);

            var request = new AccountCreateRequest {
                AccountTypeId = 1, CustomerId = 2
            };

            MockReturnNullAccount();

            _mockRepo
            .Setup(repo => repo.Customer.FindById(It.Is <int>(c => c == request.CustomerId), It.IsAny <List <string> >()))
            .Returns(new Customer {
                Id = request.CustomerId.Value
            })
            .Verifiable();

            _mockRepo
            .Setup(repo => repo.AccountType.FindById(It.Is <int>(at => at == request.AccountTypeId), It.IsAny <List <string> >()))
            .Returns(new AccountType {
                Id = 1
            })
            .Verifiable();

            _mockRepo
            .Setup(repo => repo.Account.Create(It.Is <Account>(a => a.AccountTypeId == request.AccountTypeId && request.CustomerId == a.CustomerId)))
            .Callback <Account>(a => a.Id = 4)
            .Verifiable();

            var result = await handler.Handle(request, default);

            _mockRepo.Verify();

            Assert.IsType <AccountModel>(result);
            Assert.Equal(4, result.Id);
        }