Example #1
0
        public void ShouldNotRegisterNewClientIfItExists()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            ClientsService         clientsService = new ClientsService(this.clientTableRepository);
            ClientRegistrationInfo args           = new ClientRegistrationInfo();

            args.LastName    = "Michael";
            args.FirstName   = "Lomonosov";
            args.PhoneNumber = "+79521234567";
            args.Status      = true;

            // Act
            clientsService.RegisterNewClient(args);

            this.clientTableRepository.Contains(Arg.Is <ClientEntity>(
                                                    c => c.LastName == args.LastName &&
                                                    c.FirstName == args.FirstName &&
                                                    c.PhoneNumber == args.PhoneNumber &&
                                                    c.Status == args.Status)).Returns(true);

            clientsService.RegisterNewClient(args);

            // Assert
        }
        public void ShouldUpdateClient()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            var clientId = 44;

            this.clientTableRepository.ContainsById(Arg.Is(clientId)).Returns(true);
            this.clientTableRepository.Get(Arg.Is(clientId)).Returns(new ClientEntity()
            {
                Id          = clientId,
                CreatedAt   = DateTime.Now,
                LastName    = "Misha",
                FirstName   = "Lomonosow",
                PhoneNumber = "+79211234567",
                Status      = true
            });
            ClientsService clientsService = new ClientsService(this.clientTableRepository);

            ClientRegistrationInfo args = new ClientRegistrationInfo();

            args.LastName    = "Michael";
            args.FirstName   = "Lomonosov";
            args.PhoneNumber = "+79521234567";

            // Act
            clientsService.UpdateClientData(clientId, args);

            // Assert
            this.clientTableRepository.Received(1).Update(Arg.Is <ClientEntity>(
                                                              c => c.LastName == args.LastName &&
                                                              c.FirstName == args.FirstName &&
                                                              c.PhoneNumber == args.PhoneNumber));
            this.clientTableRepository.Received(1).SaveChanges();
        }
 public ReportsService(IOperationTableRepository operationTableRepository, ISharesNumberTableRepository sharesNumberTableRepository, IBalanceTableRepository balanceTableRepository, IShareTableRepository shareTableRepository, IClientTableRepository clientTableRepository)
 {
     this.operationTableRepository    = operationTableRepository;
     this.sharesNumberTableRepository = sharesNumberTableRepository;
     this.balanceTableRepository      = balanceTableRepository;
     this.shareTableRepository        = shareTableRepository;
     this.clientTableRepository       = clientTableRepository;
 }
 public TradesEmulator(
     IClientTableRepository clientTableRepository,
     ISharesTableRepository sharesTableRepository,
     ITransactionService transactionService)
 {
     this.clientTableRepository = clientTableRepository;
     this.sharesTableRepository = sharesTableRepository;
     this.transactionService    = transactionService;
 }
 public TransactionService(
     IClientTableRepository clientTableRepository,
     IClientSharesTableRepository clientSharesTableRepository,
     ISharesTableRepository sharesTableRepository,
     ITransactionHistoryTableRepository transactionHistoryTableRepository
     )
 {
     this.clientTableRepository             = clientTableRepository;
     this.clientSharesTableRepository       = clientSharesTableRepository;
     this.sharesTableRepository             = sharesTableRepository;
     this.transactionHistoryTableRepository = transactionHistoryTableRepository;
 }
Example #6
0
        public void ShouldThrowExceptionIfCantFindClient()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            this.clientTableRepository.ContainsById(Arg.Is(55)).Returns(false);
            ClientsService clientsService = new ClientsService(this.clientTableRepository);

            // Act
            var clientInfo = clientsService.GetClient(55);

            // Assert
        }
 public TransactionServiceProxy(
     TransactionService transactionService,
     LoggerLog4Net logger,
     IClientTableRepository clientTableRepository,
     ISharesTableRepository sharesTableRepository)
 {
     this.transactionService    = transactionService;
     this.logger                = logger;
     this.clientTableRepository = clientTableRepository;
     this.sharesTableRepository = sharesTableRepository;
     logger.InitLogger();
 }
Example #8
0
 public TransactionService(IClientTableRepository clientTableRepository,
                           IStockTableRepository stockTableRepository,
                           IStockOfClientsTableRepository stockClientTableRepository,
                           ITransactionHistoryTableRepository transactionHistoryTableRepository,
                           EditCleintStockService editCleintStockService)
 {
     this.clientTableRepository             = clientTableRepository;
     this.stockTableRepository              = stockTableRepository;
     this.stockClientTableRepository        = stockClientTableRepository;
     this.transactionHistoryTableRepository = transactionHistoryTableRepository;
     this.editCleintStockService            = editCleintStockService;
 }
        public void Initialize()
        {
            this.clientTableRepository             = Substitute.For <IClientTableRepository>();
            this.stockTableRepository              = Substitute.For <IStockTableRepository>();
            this.stockOfClientsTableRepository     = Substitute.For <IStockOfClientsTableRepository>();
            this.transactionHistoryTableRepository = Substitute.For <ITransactionHistoryTableRepository>();
            this.editCleintStockService            = new EditCleintStockService(this.stockOfClientsTableRepository);

            this.clientTableRepository.Get(5).Returns(new ClientEntity()
            {
                ID             = 5,
                Name           = "Serj",
                Surname        = "Tankian",
                PhoneNumber    = "+7228133705",
                AccountBalance = 100,
            });
            this.clientTableRepository.Get(32).Returns(new ClientEntity()
            {
                ID             = 32,
                Name           = "Chester",
                Surname        = "Bennington",
                PhoneNumber    = "+7228133705",
                AccountBalance = 50
            });

            this.stockTableRepository.Get(1).Returns(new StockEntity()
            {
                ID   = 1,
                Name = "Yandex",
                Type = "P",
                Cost = 10
            });

            this.stockOfClientsTableRepository.Get(2).Returns(new StockOfClientsEntity()
            {
                ID       = 2,
                ClientID = 32,
                StockID  = 1,
                Amount   = 5
            });

            this.stockTableRepository.GetCost(Arg.Is <int>(1)).Returns(10);
            this.stockOfClientsTableRepository.GetAmount(
                Arg.Is <int>(5),
                Arg.Is <int>(1)).Returns(0);
            this.stockOfClientsTableRepository.GetAmount(
                Arg.Is <int>(32),
                Arg.Is <int>(1)).Returns(10);
            this.clientTableRepository.GetBalance(Arg.Is <int>(5)).Returns(100);
            this.clientTableRepository.GetBalance(Arg.Is <int>(32)).Returns(50);
            this.stockTableRepository.GetType(Arg.Is <int>(1)).Returns("P");
        }
Example #10
0
        public void ShouldGetClientInfo()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            this.clientTableRepository.ContainsById(Arg.Is(55)).Returns(true);
            ClientsService clientsService = new ClientsService(this.clientTableRepository);

            // Act
            var clientInfo = clientsService.GetClient(55);

            // Assert
            this.clientTableRepository.Received(1).Get(55);
        }
        public void ShouldRemoveClient()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            this.clientTableRepository.ContainsById(Arg.Is(55)).Returns(true);
            ClientsService clientsService = new ClientsService(this.clientTableRepository);

            // Act
            clientsService.RemoveClient(55);

            // Assert
            this.clientTableRepository.Received(1).Deactivate(55);
            this.clientTableRepository.Received(1).SaveChanges();
        }
Example #12
0
 public void Initialize()
 {
     clientTableRepository = Substitute.For <IClientTableRepository>();
     clientTableRepository.GetById(1).Returns(new ClientEntity()
     {
         Id      = 1,
         Balance = 0M,
         Name    = "Vlad Blood"
     });
     clientTableRepository.GetClientsInOrangeZone()
     .Returns(new List <ClientEntity>());
     clientTableRepository.GetClientsInBlackZone()
     .Returns(new List <ClientEntity>());
     clientsService = new ClientsService(clientTableRepository);
 }
        public void ShouldThrowExceptionIfValidationRegDataFailed()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            ClientsService         clientsService = new ClientsService(this.clientTableRepository);
            ClientRegistrationInfo args           = new ClientRegistrationInfo();

            args.LastName    = "M";
            args.FirstName   = "LomonosovLomonosovLom";
            args.PhoneNumber = "0";

            // Act
            clientsService.Validation(args);

            // Assert
        }
        public void Initialize()
        {
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            IEnumerable <ClientEntity> clients = new List <ClientEntity>()
            {
                new ClientEntity
                {
                    Name           = "Vasiliy",
                    Surname        = "Pupkin",
                    PhoneNumber    = "+7123",
                    AccountBalance = 356
                },
                new ClientEntity
                {
                    Name           = "Oleg",
                    Surname        = "Larchik",
                    PhoneNumber    = "+8954",
                    AccountBalance = 1
                },
                new ClientEntity
                {
                    Name           = "Larisa",
                    Surname        = "Vitchuck",
                    PhoneNumber    = "+6414",
                    AccountBalance = 0
                },
                new ClientEntity
                {
                    Name           = "Luis",
                    Surname        = "Vatson",
                    PhoneNumber    = "+36584",
                    AccountBalance = -1
                },
                new ClientEntity
                {
                    Name           = "Medik",
                    Surname        = "Tompon",
                    PhoneNumber    = "+6519",
                    AccountBalance = -6412
                },
            };

            this.clientTableRepository.GetClients().Returns(clients);
        }
Example #15
0
        public void ShouldRegisterNewClient()
        {
            // Arrange
            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            ClientsService         clientsService = new ClientsService(this.clientTableRepository);
            ClientRegistrationInfo args           = new ClientRegistrationInfo();

            args.LastName    = "Michael";
            args.FirstName   = "Lomonosov";
            args.PhoneNumber = "+79521234567";
            args.Status      = true;

            // Act
            var clientId = clientsService.RegisterNewClient(args);

            // Assert
            this.clientTableRepository.Received(1).Add(Arg.Is <ClientEntity>(
                                                           c => c.LastName == args.LastName &&
                                                           c.FirstName == args.FirstName &&
                                                           c.PhoneNumber == args.PhoneNumber &&
                                                           c.Status == args.Status));
            this.clientTableRepository.Received(1).SaveChanges();
        }
Example #16
0
        public void Initialize()
        {
            clientTableRepository             = Substitute.For <IClientTableRepository>();
            sharesTableRepository             = Substitute.For <ISharesTableRepository>();
            clientSharesTableRepository       = Substitute.For <IClientSharesTableRepository>();
            transactionHistoryTableRepository = Substitute.For <ITransactionHistoryTableRepository>();
            clientTableRepository.ContainsById(1).Returns(true);
            clientTableRepository.ContainsById(2).Returns(true);
            clientTableRepository.ContainsById(3).Returns(false);
            sharesTableRepository.ContainsById(1).Returns(true);
            sharesTableRepository.ContainsById(2).Returns(true);
            sharesTableRepository.ContainsById(3).Returns(true);
            sharesTableRepository.ContainsById(4).Returns(false);
            clientTableRepository.GetById(1).Returns(new ClientEntity()
            {
                Id        = 1,
                Balance   = 0M,
                Name      = "Seller",
                Portfolio = new List <ClientSharesEntity>()
                {
                    new ClientSharesEntity()
                    {
                        Id       = 1,
                        Quantity = 50,
                        Shares   = new SharesEntity
                        {
                            Id         = 1,
                            Price      = 10M,
                            SharesType = "TypeA"
                        }
                    },

                    new ClientSharesEntity()
                    {
                        Id       = 2,
                        Quantity = 10,
                        Shares   = new SharesEntity
                        {
                            Id         = 3,
                            Price      = 15M,
                            SharesType = "TypeC"
                        }
                    }
                }
            });
            clientTableRepository.GetById(2).Returns(new ClientEntity()
            {
                Id        = 2,
                Balance   = 100M,
                Name      = "Buyer",
                Portfolio = new List <ClientSharesEntity>()
                {
                    new ClientSharesEntity()
                    {
                        Id       = 2,
                        Quantity = 0,
                        Shares   = new SharesEntity
                        {
                            Id         = 2,
                            Price      = 5M,
                            SharesType = "TypeB"
                        }
                    },

                    new ClientSharesEntity()
                    {
                        Id       = 3,
                        Quantity = 15,
                        Shares   = new SharesEntity
                        {
                            Id         = 1,
                            Price      = 10M,
                            SharesType = "TypeA"
                        }
                    }
                }
            });
            sharesTableRepository.GetById(1).Returns(new SharesEntity()
            {
                Id         = 1,
                Price      = 10M,
                SharesType = "TypeA"
            });
            sharesTableRepository.GetById(2).Returns(new SharesEntity()
            {
                Id         = 2,
                Price      = 5M,
                SharesType = "TypeB"
            });
            sharesTableRepository.GetById(3).Returns(new SharesEntity()
            {
                Id         = 3,
                Price      = 15M,
                SharesType = "TypeC"
            });

            transactionService = new TransactionService(
                clientTableRepository,
                clientSharesTableRepository,
                sharesTableRepository,
                transactionHistoryTableRepository);
        }
Example #17
0
 public ClientsService(IClientTableRepository clientTableRepository, ISharesTableRepository sharesTableRepository)
 {
     this.clientTableRepository = clientTableRepository;
     this.sharesTableRepository = sharesTableRepository;
 }
        public void Initialize()
        {
            var clients = new List <ClientEntity>()
            {
                new ClientEntity()
                {
                    Id = 1, CreatedAt = DateTime.Now, LastName = "Pavlov", FirstName = "Ivan", PhoneNumber = "+7(812)5551243", Status = true
                },
                new ClientEntity()
                {
                    Id = 2, CreatedAt = DateTime.Now, LastName = "Mechnikov", FirstName = "Ilya", PhoneNumber = "+33(0)140205317", Status = true
                },
                new ClientEntity()
                {
                    Id = 3, CreatedAt = DateTime.Now, LastName = "Bunin", FirstName = "Ivan", PhoneNumber = "+33(0)420205320", Status = true
                },
                new ClientEntity()
                {
                    Id = 4, CreatedAt = DateTime.Now, LastName = "Semyonov", FirstName = "Nikolay", PhoneNumber = "+7(495)4652317", Status = true
                },
                new ClientEntity()
                {
                    Id = 5, CreatedAt = DateTime.Now, LastName = "Pasternak", FirstName = "Boris", PhoneNumber = "+7(495)4368173", Status = true
                },
                new ClientEntity()
                {
                    Id = 6, CreatedAt = DateTime.Now, LastName = "Cherenkov", FirstName = "Pavel", PhoneNumber = "+7(495)3246421", Status = true
                },
                new ClientEntity()
                {
                    Id = 7, CreatedAt = DateTime.Now, LastName = "Tamm", FirstName = "Igor", PhoneNumber = "+7(495)7523146", Status = true
                },
                new ClientEntity()
                {
                    Id = 8, CreatedAt = DateTime.Now, LastName = "Frank", FirstName = "Ilya", PhoneNumber = "+7(495)7924194", Status = true
                },
                new ClientEntity()
                {
                    Id = 9, CreatedAt = DateTime.Now, LastName = "Landau", FirstName = "Lev", PhoneNumber = "+7(495)7924194", Status = true
                }
            };
            var balances = new List <BalanceEntity>()
            {
                new BalanceEntity()
                {
                    Id = 1, Client = clients[0], Amount = 138000, Status = true
                },
                new BalanceEntity()
                {
                    Id = 2, Client = clients[1], Amount = 142000, Status = true
                },
                new BalanceEntity()
                {
                    Id = 3, Client = clients[2], Amount = 130000, Status = true
                },
                new BalanceEntity()
                {
                    Id = 4, Client = clients[3], Amount = 0, Status = true
                },
                new BalanceEntity()
                {
                    Id = 5, Client = clients[4], Amount = 0, Status = true
                },
                new BalanceEntity()
                {
                    Id = 6, Client = clients[5], Amount = -139700, Status = true
                },
                new BalanceEntity()
                {
                    Id = 7, Client = clients[6], Amount = 139700, Status = true
                },
                new BalanceEntity()
                {
                    Id = 8, Client = clients[7], Amount = -131000, Status = true
                },
                new BalanceEntity()
                {
                    Id = 9, Client = clients[8], Amount = 0, Status = true
                },
            };
            var shareTypesList = new List <ShareTypeEntity>()
            {
                new ShareTypeEntity()
                {
                    Id = 1, Name = "Cheap", Cost = 1000, Status = true
                },
                new ShareTypeEntity()
                {
                    Id = 2, Name = "Middle", Cost = 4000, Status = true
                },
                new ShareTypeEntity()
                {
                    Id = 3, Name = "Expensive", Cost = 10000, Status = true
                }
            };
            var sharesList = new List <ShareEntity>()
            {
                new ShareEntity()
                {
                    Id = 1, CreatedAt = DateTime.Now, CompanyName = "Microsoft", Type = shareTypesList[2] /*Expensive*/, Status = true
                },
                new ShareEntity()
                {
                    Id = 2, CreatedAt = DateTime.Now, CompanyName = "Apple", Type = shareTypesList[1] /*Middle*/, Status = true
                },
                new ShareEntity()
                {
                    Id = 3, CreatedAt = DateTime.Now, CompanyName = "Yandex", Type = shareTypesList[1] /*Middle*/, Status = true
                }
            };
            var sharesNumbers = new List <SharesNumberEntity>()
            {
                new SharesNumberEntity()
                {
                    Id     = 1,
                    Client = clients[0],    // Id = 1
                    Share  = sharesList[0], // Microsoft
                    Number = 50
                },
                new SharesNumberEntity()
                {
                    Id     = 2,
                    Client = clients[1],    // Id = 2
                    Share  = sharesList[0], // Microsoft
                    Number = 30
                },
                new SharesNumberEntity()
                {
                    Id     = 3,
                    Client = clients[1],    // Id = 2
                    Share  = sharesList[1], // Apple
                    Number = 40
                },
                new SharesNumberEntity()
                {
                    Id     = 4,
                    Client = clients[1],    // Id = 2
                    Share  = sharesList[2], // Yandex
                    Number = 30
                },
                new SharesNumberEntity()
                {
                    Id     = 5,
                    Client = clients[0],    // Id = 1
                    Share  = sharesList[1], // Apple
                    Number = 20
                },
                new SharesNumberEntity()
                {
                    Id     = 6,
                    Client = clients[5],    // Id = 6
                    Share  = sharesList[2], // Yandex
                    Number = 30
                },
                new SharesNumberEntity()
                {
                    Id     = 7,
                    Client = clients[4],    // Id = 5
                    Share  = sharesList[0], // Microsoft
                    Number = 40
                },
                new SharesNumberEntity()
                {
                    Id     = 8,
                    Client = clients[3],    // Id = 4
                    Share  = sharesList[0], // Microsoft
                    Number = 25
                }
            };
            var operations = new List <OperationEntity>()
            {
                new OperationEntity()
                {
                    Id            = 1,
                    DebitDate     = DateTime.Now,
                    Customer      = clients[1],
                    ChargeDate    = DateTime.Now,
                    Seller        = clients[0],
                    Share         = sharesList[0],           // 'Service' share
                    ShareTypeName = sharesList[0].Type.Name, // 'Middle'
                    Cost          = sharesList[0].Type.Cost, // 'Middle' cost
                    Number        = 12,
                    Total         = 12 * sharesList[0].Type.Cost
                },
                new OperationEntity()
                {
                    Id            = 2,
                    DebitDate     = DateTime.Now,
                    Customer      = clients[5],
                    ChargeDate    = DateTime.Now,
                    Seller        = clients[2],
                    Share         = sharesList[0],           // 'Service' share
                    ShareTypeName = sharesList[0].Type.Name, // 'Middle'
                    Cost          = sharesList[0].Type.Cost, // 'Middle' cost
                    Number        = 12,
                    Total         = 12 * sharesList[0].Type.Cost
                },
                new OperationEntity()
                {
                    Id            = 3,
                    DebitDate     = DateTime.Now,
                    Customer      = clients[1],
                    ChargeDate    = DateTime.Now,
                    Seller        = clients[0],
                    Share         = sharesList[1],           // 'Service' share
                    ShareTypeName = sharesList[0].Type.Name, // 'Middle'
                    Cost          = sharesList[1].Type.Cost, // 'Middle' cost
                    Number        = 12,
                    Total         = 12 * sharesList[0].Type.Cost
                },
                new OperationEntity()
                {
                    Id            = 4,
                    DebitDate     = DateTime.Now,
                    Customer      = clients[1],
                    ChargeDate    = DateTime.Now,
                    Seller        = clients[0],
                    Share         = sharesList[0],           // 'Service' share
                    ShareTypeName = sharesList[0].Type.Name, // 'Middle'
                    Cost          = sharesList[0].Type.Cost, // 'Middle' cost
                    Number        = 12,
                    Total         = 12 * sharesList[0].Type.Cost
                },
                new OperationEntity()
                {
                    Id            = 5,
                    DebitDate     = DateTime.Now,
                    Customer      = clients[1],
                    ChargeDate    = DateTime.Now,
                    Seller        = clients[0],
                    Share         = sharesList[0],           // 'Service' share
                    ShareTypeName = sharesList[0].Type.Name, // 'Middle'
                    Cost          = sharesList[0].Type.Cost, // 'Middle' cost
                    Number        = 12,
                    Total         = 12 * sharesList[0].Type.Cost
                }
            };

            this.operationTableRepository = Substitute.For <IOperationTableRepository>();
            this.operationTableRepository.GetByClient(Arg.Is(2), Arg.Is(4)).Returns(new List <OperationEntity>()
            {
                operations[0], operations[2], operations[3], operations[4]
            });


            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            this.balanceTableRepository.GetNegativeBalances().Returns(new List <BalanceEntity>()
            {
                balances[5], balances[7]
            });
            this.balanceTableRepository.GetZeroBalances().Returns(new List <BalanceEntity>()
            {
                balances[3], balances[4], balances[8]
            });


            this.sharesNumberTableRepository = Substitute.For <ISharesNumberTableRepository>();
            this.sharesNumberTableRepository.GetByClient(Arg.Is(4)).Returns(new List <SharesNumberEntity>()
            {
                sharesNumbers[7]
            });
            this.sharesNumberTableRepository.GetByShare(Arg.Is(4)).Returns(new List <SharesNumberEntity>()
            {
                sharesNumbers[3], sharesNumbers[5]
            });

            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            this.shareTableRepository.GetSharesCount().Returns(sharesList.Count);

            this.clientTableRepository = Substitute.For <IClientTableRepository>();
            this.clientTableRepository.GetClientsCount().Returns(clients.Count);
            this.clientTableRepository.Take(Arg.Is(5), Arg.Is(1)).Returns(new List <ClientEntity>()
            {
                clients[0], clients[1], clients[2], clients[3], clients[4]
            });
        }
Example #19
0
 public ClientService(IClientTableRepository clientTableRepository)
 {
     this.clientTableRepository = clientTableRepository;
 }