コード例 #1
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;
 }
コード例 #2
0
        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");
        }
コード例 #3
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();
        }
コード例 #4
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();
        }
コード例 #5
0
 public StockService(IStockTableRepository stockTableRepository)
 {
     this.stockTableRepository = stockTableRepository;
 }
コード例 #6
0
 public TransactionService(IHistoryTableRepository historyTableRepository, IBalanceTableRepository balanceTableRepository, IStockTableRepository stockTableRepository)
 {
     this.historyTableRepository = historyTableRepository;
     this.balanceTableRepository = balanceTableRepository;
     this.stockTableRepository   = stockTableRepository;
 }
コード例 #7
0
        public void Initialize()
        {
            historyTableRepository     = Substitute.For <IHistoryTableRepository>();
            traderStockTableRepository = Substitute.For <ITraderStockTableRepository>();
            traderTableRepository      = Substitute.For <ITraderTableRepository>();

            traderTableRepository.GetById(5).Returns(new TraderEntityDB()
            {
                Id      = 5,
                Name    = "Muhamed",
                Surname = "Ali",
                Balance = 123123.0M
            });
            traderTableRepository.GetById(40).Returns(new TraderEntityDB()
            {
                Id      = 40,
                Name    = "Brad",
                Surname = "Pitt",
                Balance = 1243123.0M
            });

            stockTableRepository = Substitute.For <IStockTableRepository>();
            stockTableRepository.GetById(7).Returns(new StockEntityDB()
            {
                Id           = 7,
                Name         = "Pepsi",
                PricePerItem = 123.0M
            });
            stockTableRepository.GetById(20).Returns(new StockEntityDB()
            {
                Id           = 20,
                Name         = "Shmepsi",
                PricePerItem = 33.0M
            });

            this.traderStocksTable = new List <StockToTraderEntityDB>()
            {
                new StockToTraderEntityDB()
                {
                    Id           = 1,
                    TraderId     = 5,
                    StockId      = 7,
                    StockCount   = 4,
                    PricePerItem = 123.0M
                },
                new StockToTraderEntityDB()
                {
                    Id           = 2,
                    TraderId     = 5,
                    StockId      = 20,
                    StockCount   = 2,
                    PricePerItem = 33.0M
                },
                new StockToTraderEntityDB()
                {
                    Id           = 3,
                    TraderId     = 40,
                    StockId      = 7,
                    StockCount   = 2,
                    PricePerItem = 33.0M
                }
            };

            traderStockTableRepository.GetStocksFromSeller(Arg.Any <BuyArguments>())
            .Returns((callInfo) =>
            {
                var buyArguments = callInfo.Arg <BuyArguments>();

                var retVal = this.traderStocksTable.First(w => w.TraderId == buyArguments.SellerID &&
                                                          w.StockId == buyArguments.StockID);
                return(retVal);
            });

            traderStockTableRepository.ContainsSeller(Arg.Any <BuyArguments>())
            .Returns((callInfo) =>
            {
                var buyArguments = callInfo.Arg <BuyArguments>();
                try
                {
                    var retVal = this.traderStocksTable.First(w => w.TraderId == buyArguments.SellerID &&
                                                              w.StockId == buyArguments.StockID);
                }
                catch (Exception)
                {
                    return(false);
                }
                return(true);
            });

            traderStockTableRepository.ContainsCustomer(Arg.Any <BuyArguments>())
            .Returns((callInfo) =>
            {
                var buyArguments = callInfo.Arg <BuyArguments>();
                try
                {
                    var retVal = this.traderStocksTable.First(w => w.TraderId == buyArguments.CustomerID &&
                                                              w.StockId == buyArguments.StockID);
                }
                catch (Exception)
                {
                    return(false);
                }
                return(true);
            });

            traderStockTableRepository.Contains(Arg.Any <StockToTraderEntityDB>())
            .Returns((callInfo) =>
            {
                var stockToTrader = callInfo.Arg <StockToTraderEntityDB>();
                try
                {
                    var retVal = this.traderStocksTable.First(w => w.TraderId == stockToTrader.TraderId &&
                                                              w.StockId == stockToTrader.StockId);
                }
                catch (Exception)
                {
                    return(false);
                }
                return(true);
            });

            traderTableRepository.ContainsById(5).Returns(true);
            traderTableRepository.ContainsById(40).Returns(true);


            saleHandler = new SaleService(this.traderStockTableRepository, this.traderTableRepository, this.historyTableRepository);
        }
コード例 #8
0
 public void Initialize()
 {
     stockTableRepository = Substitute.For <IStockTableRepository>();
     stockService         = new StockService(this.stockTableRepository);
 }
コード例 #9
0
 public DealController(IHistoryTableRepository transactionsService, IStockTableRepository stockService)
 {
     this.transactionsService = transactionsService;
     this.stockService        = stockService;
 }
コード例 #10
0
 public StocksController(IStockTableRepository stocksService, IBalanceTableRepository balancesService)
 {
     this.stocksService   = stocksService;
     this.balancesService = balancesService;
 }