public void FindBankAccountsReturnAllItems() { var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetAll = () => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"), }; bankAccount.SetCustomerOwnerOfThisBankAccount(customer); bankAccount.GenerateNewIdentity(); var accounts = new List <BankAccount>() { bankAccount }; return(accounts); }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccounts(); Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void LockBankAccountReturnFalseIfBankAccountNotExist() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => null); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.False(result); }
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 Start(BankAppService service) { var list = new TcpListener(IPAddress.Parse(Settings.Default.ListenIp), Settings.Default.ListenPort); list.Start(); while (true) { using (var tcp = list.AcceptTcpClient()) { var cmd = (Command) new BinaryFormatter().Deserialize(tcp.GetStream()); try { var answer = cmd.Execute(service); new BinaryFormatter().Serialize(tcp.GetStream(), answer); service.Dispose(); } catch (Exception ex) { new BinaryFormatter().Serialize(tcp.GetStream(), new ErrorAnswer() { Message = ex.Message }); } } } }
public void LockBankAccountReturnFalseIfIdentifierIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = guid => { if (guid == Guid.Empty) { return(null); } else { return(new BankAccount { }); } }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.LockBankAccount(Guid.Empty); //Assert Assert.IsFalse(result); }
public void LockBankAccountReturnFalseIfBankAccountNotExist() { //Arrange SICustomerRepository customerRepository = new SICustomerRepository(); IBankTransferService transferService = new BankTransferService(); SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository(); bankAccountRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return(uow); }; bankAccountRepository.GetGuid = (guid) => { return(null); }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.IsFalse(result); }
public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => guid == Guid.Empty ? null : new BankAccount { }); 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); //Act var result = bankingService.FindBankAccountActivities(Guid.Empty); //Assert Assert.Null(result); }
public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = guid => { if (guid == Guid.Empty) { return(null); } else { return(new BankAccount { }); } }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccountActivities(Guid.Empty); //Assert Assert.IsNull(result); }
public void LockBankAccountReturnFalseIfIdentifierIsEmpty() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => guid == Guid.Empty ? null : new BankAccount { }); 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); //Act var result = bankingService.LockBankAccount(Guid.Empty); //Assert Assert.False(result); }
public override Answer Execute(BankAppService service) { var tr = service.GetCancelTransaction(UserLogin); return(new CancelTransactionAnswer { CancelTransactions = tr }); }
public override Answer Execute(BankAppService service) { var bal = service.GetBalance(AccountId); return(new BalanceAnswer { Balans = bal }); }
public override Answer Execute(BankAppService service) { var acc = service.GetClientAccounts(UserLogin); return(new ClientAccountAnswer { Accounts = acc }); }
static void Main(string[] args) { var server = new Server(); var service = new BankAppService(); new Thread(() => server.Start(service)).Start(); Console.ReadLine(); }
protected override void OnStart(string[] args) { // Debugger.Launch(); var server = new Server(); var service = new BankAppService(); new Thread(() => server.Start(service)).Start(); Thread.Sleep(100); }
public void ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull() { //Arrange SICustomerRepository customerRepository = new SICustomerRepository(); SIBankAccountRepository bankAcccountRepository = null; IBankTransferService transferService = new BankTransferService(); //Act IBankAppService bankingService = new BankAppService(bankAcccountRepository, customerRepository, transferService); }
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 ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull() { //Arrange Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); Exception ex = Assert.Throws <ArgumentNullException>(() => { //Act IBankAppService bankingService = new BankAppService(null, customerRepository.Object, transferService, _mockLogger.Object); } ); Assert.IsType(typeof(ArgumentNullException), ex); }
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 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 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 FindBankAccountActivitiesReturnAllItems() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = (guid) => { var bActivity1 = new BankAccountActivity() { Date = DateTime.Now, Amount = 1000 }; bActivity1.GenerateNewIdentity(); var bActivity2 = new BankAccountActivity() { Date = DateTime.Now, Amount = 1000 }; bActivity2.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountActivity = new HashSet <BankAccountActivity>() { bActivity1, bActivity2 } }; bankAccount.GenerateNewIdentity(); return(bankAccount); }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccountActivities(Guid.NewGuid()); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); }
public void FindBankAccountActivitiesReturnNullWhenBankAccountNotExists() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = (guid) => { return(null); }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccountActivities(Guid.NewGuid()); //Assert Assert.IsNull(result); }
public void FindBankAccountActivitiesReturnAllItems() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => { var bActivity1 = new BankAccountActivity() { Date = DateTime.Now, Amount = 1000 }; bActivity1.GenerateNewIdentity(); var bActivity2 = new BankAccountActivity() { Date = DateTime.Now, Amount = 1000 }; bActivity2.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountActivity = new HashSet <BankAccountActivity>() { bActivity1, bActivity2 } }; bankAccount.GenerateNewIdentity(); return(bankAccount); }); 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); //Act var result = bankingService.FindBankAccountActivities(Guid.NewGuid()); //Assert Assert.NotNull(result); Assert.True(result.Count == 2); }
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 LockBankAccountReturnTrueIfBankAccountIsLocked() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); var bankAccountRepository = new Mock <IBankAccountRepository>(); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); bankAccountRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount(); bankAccount.GenerateNewIdentity(); bankAccount.SetCustomerOwnerOfThisBankAccount(customer); return(bankAccount); }); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.True(result); }
public void LockBankAccountReturnTrueIfBankAccountIsLocked() { //Arrange var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); uow.Commit = () => { }; return(uow); }; bankAccountRepository.GetGuid = (guid) => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount(); bankAccount.GenerateNewIdentity(); bankAccount.SetCustomerOwnerOfThisBankAccount(customer); return(bankAccount); }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.IsTrue(result); }
public void FindBankAccountsReturnAllItems() { var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository.Setup(x => x.GetAll()).Returns(() => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"), }; bankAccount.SetCustomerOwnerOfThisBankAccount(customer); bankAccount.GenerateNewIdentity(); var accounts = new List <BankAccount>() { bankAccount }; return(accounts); } ); 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); //Act var result = bankingService.FindBankAccounts(); Assert.NotNull(result); Assert.True(result.Count == 1); }
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); }
public override Answer Execute(BankAppService service) { service.CreateTransaction(FromAccountId, ToAccountId, Sum); return(new OkAnswer()); }