Esempio n. 1
0
 public SalesService(IOperationTableRepository operationTableRepository, IBalanceTableRepository balanceTableRepository, IBlockedMoneyTableRepository blockedMoneyTableRepository, ISharesNumberTableRepository sharesNumberTableRepository, IBlockedSharesNumberTableRepository blockedSharesNumberTableRepository)
 {
     this.operationTableRepository           = operationTableRepository;
     this.balanceTableRepository             = balanceTableRepository;
     this.blockedMoneyTableRepository        = blockedMoneyTableRepository;
     this.sharesNumberTableRepository        = sharesNumberTableRepository;
     this.blockedSharesNumberTableRepository = blockedSharesNumberTableRepository;
 }
Esempio n. 2
0
 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 void Initialize()
        {
            this.operationTableRepository = Substitute.For <IOperationTableRepository>();

            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();

            this.sharesNumberTableRepository = Substitute.For <ISharesNumberTableRepository>();

            this.blockedMoneyTableRepository = Substitute.For <IBlockedMoneyTableRepository>();

            this.blockedSharesNumberTableRepository = Substitute.For <IBlockedSharesNumberTableRepository>();
        }
        public void ShouldThrowExceptionIfCantFindBalance()
        {
            // Arrange
            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            int testId = 55;

            this.balanceTableRepository.ContainsById(Arg.Is(testId)).Returns(false); // Now Contains returns false (table don't contains share type with this Id)
            BalancesService balancesService = new BalancesService(this.balanceTableRepository);

            // Act
            balancesService.ContainsById(testId); // Try to get share type and get exception

            // Assert
        }
Esempio n. 5
0
        public void ShouldChangeBalanceOfTheSeller()
        {
            //Arrange

            historyTableRepository = Substitute.For <IHistoryTableRepository>();
            balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            stockTableRepository   = Substitute.For <IStockTableRepository>();
            TransactionService transactionService = new TransactionService(this.historyTableRepository, this.balanceTableRepository, this.stockTableRepository);
            var args = new TransactionInfo();

            args.SellerID        = 22;
            args.SellerBalanceID = "2201";
            args.BuyerID         = 7;
            args.BuyerBalanceID  = "701";
            args.StockAmount     = 2;
            args.StockID         = 5;
            args.dateTime        = DateTime.Now;

            var stock = new StockEntity();

            stock.ID    = 5;
            stock.Price = 200;
            stock.Type  = "StockTypeA";

            stockTableRepository.Get(5).Returns(stock);

            var sellerBalance = new BalanceEntity();

            sellerBalance.BalanceID   = "2201";
            sellerBalance.Balance     = 1000;
            sellerBalance.StockID     = 3;
            sellerBalance.StockAmount = 2;
            sellerBalance.UserID      = 22;
            sellerBalance.CreatedAt   = DateTime.Now;

            balanceTableRepository.Get("2201").Returns(sellerBalance);


            //Act
            transactionService.MakeSell(args, stock);
            //Assert
            balanceTableRepository.Received(1).Change(Arg.Is <BalanceEntity>(w =>
                                                                             w.Balance == sellerBalance.Balance &&
                                                                             w.BalanceID == sellerBalance.BalanceID &&
                                                                             w.CreatedAt == sellerBalance.CreatedAt &&
                                                                             w.StockID == sellerBalance.StockID &&
                                                                             w.StockAmount == sellerBalance.StockAmount &&
                                                                             w.UserID == sellerBalance.UserID));
            balanceTableRepository.Received(1).SaveChanges();
        }
        public void ShouldGetBalanceInfo()
        {
            // Arrange
            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            int testId = 55;

            this.balanceTableRepository.ContainsById(Arg.Is(testId)).Returns(true);
            BalancesService balancesService = new BalancesService(this.balanceTableRepository);

            // Act
            var balanceInfo = balancesService.GetBalance(testId);

            // Assert
            this.balanceTableRepository.Received(1).Get(testId);
        }
        public void ShouldChangeAmount()
        {
            // Arrange
            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            int testId = 55;

            this.balanceTableRepository.ContainsById(Arg.Is(testId)).Returns(true);
            BalancesService balancesService = new BalancesService(this.balanceTableRepository);
            decimal         newAmount       = 5000.00M;

            // Act
            balancesService.ChangeBalance(testId, newAmount);

            // Assert
            this.balanceTableRepository.Received(1).ChangeAmount(testId, newAmount);
            this.balanceTableRepository.Received(1).SaveChanges();
        }
Esempio n. 8
0
        public void ShouldLogInHistoryTable()
        {
            //Arrange

            historyTableRepository = Substitute.For <IHistoryTableRepository>();
            balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            stockTableRepository   = Substitute.For <IStockTableRepository>();
            TransactionService transactionService = new TransactionService
                                                    (
                this.historyTableRepository,
                this.balanceTableRepository,
                this.stockTableRepository
                                                    );
            var args = new TransactionInfo();

            args.SellerID        = 22;
            args.SellerBalanceID = "2201";
            args.BuyerID         = 7;
            args.BuyerBalanceID  = "701";
            args.StockAmount     = 2;
            args.StockID         = 5;
            args.dateTime        = DateTime.Now;

            var stock = new StockEntity();

            stock.ID    = 5;
            stock.Price = 200;
            stock.Type  = "StockTypeA";

            //Act
            transactionService.TransactionHistoryLogger(args, stock);

            //Assert
            historyTableRepository.Received(1).Add(Arg.Is <TransactionHistoryEntity>(w =>
                                                                                     w.SellerBalanceID == args.SellerBalanceID &&
                                                                                     w.BuyerBalanceID == args.BuyerBalanceID &&
                                                                                     w.StockName == stock.Type &&
                                                                                     w.StockAmount == args.StockAmount &&
                                                                                     w.TransactionQuantity == args.StockAmount * stock.Price &&
                                                                                     w.TimeOfTransaction == args.dateTime));
            historyTableRepository.Received(1).SaveChanges();
        }
        public void ShouldNotRegisterNewBalanceIfItExists()
        {
            // Arrange
            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            BalancesService         balancesService = new BalancesService(this.balanceTableRepository);
            BalanceRegistrationInfo args            = new BalanceRegistrationInfo();

            args.Client = this.newClient;
            args.Amount = 5000.00M;
            args.Status = true;

            // Act
            balancesService.RegisterNewBalance(args);

            this.balanceTableRepository.Contains(Arg.Is <BalanceEntity>( // Now Contains returns true (table contains this balance of client)
                                                     b => b.Client == args.Client)).Returns(true);

            balancesService.RegisterNewBalance(args); // Try to reg. same twice and get exception

            // Assert
        }
        public void ShouldRegisterNewBalance()
        {
            // Arrange
            this.balanceTableRepository = Substitute.For <IBalanceTableRepository>();
            BalancesService         balancesService = new BalancesService(this.balanceTableRepository);
            BalanceRegistrationInfo args            = new BalanceRegistrationInfo();

            args.Client = this.newClient;
            args.Amount = 5000.00M;
            args.Status = true;

            // Act
            var shareId = balancesService.RegisterNewBalance(args);

            // Assert
            this.balanceTableRepository.Received(1).Add(Arg.Is <BalanceEntity>(
                                                            b => b.Client == args.Client &&
                                                            b.Amount == args.Amount &&
                                                            b.Status == args.Status));
            this.balanceTableRepository.Received(1).SaveChanges();
        }
 public TransactionService(IHistoryTableRepository historyTableRepository, IBalanceTableRepository balanceTableRepository, IStockTableRepository stockTableRepository)
 {
     this.historyTableRepository = historyTableRepository;
     this.balanceTableRepository = balanceTableRepository;
     this.stockTableRepository   = stockTableRepository;
 }
Esempio n. 12
0
 public BalancesService(IBalanceTableRepository balanceTableRepository)
 {
     this.balanceTableRepository = balanceTableRepository;
 }
        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]
            });
        }
Esempio n. 14
0
 public StocksController(IStockTableRepository stocksService, IBalanceTableRepository balancesService)
 {
     this.stocksService   = stocksService;
     this.balancesService = balancesService;
 }
Esempio n. 15
0
 public ValidationOfTransactionService(IBalanceTableRepository balanceTableRepository)
 {
     this.balanceTableRepository = balanceTableRepository;
 }