public void AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); var customerRepository = new Mock <ICustomerRepository>(); customerRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => null); IBankTransferService transferService = new BankTransferService(); var dto = new BankAccountDTO() { CustomerId = Guid.NewGuid() }; Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); Exception ex = Assert.Throws <InvalidOperationException>(() => { //Act bankingService.AddBankAccount(dto); } ); Assert.IsType(typeof(InvalidOperationException), ex); }
public void AddBankAccountReturnDTOWhenSaveSucceed() { //Arrange IBankTransferService transferService = new BankTransferService(); var customerRepository = new Mock <ICustomerRepository>(); customerRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => { var customer = new Customer() { FirstName = "Jhon", LastName = "El rojo" }; customer.ChangeCurrentIdentity(guid); return(customer); } ); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository.Setup(x => x.Add(It.IsAny <BankAccount>())); bankAccountRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); var dto = new BankAccountDTO() { CustomerId = Guid.NewGuid(), BankAccountNumber = "BA" }; Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.AddBankAccount(dto); //Assert Assert.NotNull(result); }
public void AddBankAccountThrowArgumentNullExceptionWhenBankAccountDtoIsNull() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.AddBankAccount(null); //Assert Assert.IsNull(result); }
public void AddBankAccountReturnNullWhenCustomerIdIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); var dto = new BankAccountDto() { CustomerId = Guid.Empty }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.AddBankAccount(dto); }
public void AddBankAccountReturnDTOWhenSaveSucceed() { //Arrange IBankTransferService transferService = new BankTransferService(); SICustomerRepository customerRepository = new SICustomerRepository(); customerRepository.GetGuid = (guid) => { var customer = new Customer() { FirstName = "Jhon", LastName = "El rojo" }; customer.ChangeCurrentIdentity(guid); return(customer); }; SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository(); bankAccountRepository.AddBankAccount = (ba) => { }; bankAccountRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return(uow); }; var dto = new BankAccountDTO() { CustomerId = Guid.NewGuid(), BankAccountNumber = "BA" }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.AddBankAccount(dto); //Assert Assert.IsNotNull(result); }
public void AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); var customerRepository = new StubICustomerRepository(); customerRepository.GetGuid = (guid) => { return(null); }; IBankTransferService transferService = new BankTransferService(); var dto = new BankAccountDto() { CustomerId = Guid.NewGuid() }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act bankingService.AddBankAccount(dto); }
public void AddBankAccountThrowArgumentNullExceptionWhenBankAccountDTOIsNull() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); Exception ex = Assert.Throws <ArgumentException>(() => { //Act var result = bankingService.AddBankAccount(null); //Assert Assert.Null(result); } ); Assert.IsType(typeof(ArgumentException), ex); }
public void AddBankAccountReturnNullWhenCustomerIdIsEmpty() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); var dto = new BankAccountDTO() { CustomerId = Guid.Empty }; Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); Exception ex = Assert.Throws <ArgumentException>(() => { //Act var result = bankingService.AddBankAccount(dto); } ); Assert.IsType(typeof(ArgumentException), ex); }