コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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
                        });
                    }
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public override Answer Execute(BankAppService service)
        {
            var tr = service.GetCancelTransaction(UserLogin);

            return(new CancelTransactionAnswer {
                CancelTransactions = tr
            });
        }
コード例 #11
0
        public override Answer Execute(BankAppService service)
        {
            var bal = service.GetBalance(AccountId);

            return(new BalanceAnswer {
                Balans = bal
            });
        }
コード例 #12
0
        public override Answer Execute(BankAppService service)
        {
            var acc = service.GetClientAccounts(UserLogin);

            return(new ClientAccountAnswer {
                Accounts = acc
            });
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: filmobile/BankSolution
        static void Main(string[] args)
        {
            var server  = new Server();
            var service = new BankAppService();

            new Thread(() => server.Start(service)).Start();

            Console.ReadLine();
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public void ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull()
        {
            //Arrange
            SICustomerRepository    customerRepository     = new SICustomerRepository();
            SIBankAccountRepository bankAcccountRepository = null;
            IBankTransferService    transferService        = new BankTransferService();

            //Act
            IBankAppService bankingService = new BankAppService(bankAcccountRepository, customerRepository, transferService);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
 public override Answer Execute(BankAppService service)
 {
     service.CreateTransaction(FromAccountId, ToAccountId, Sum);
     return(new OkAnswer());
 }