コード例 #1
0
 public SaleService(
     ITraderStockTableRepository traderStockTableRepository,
     ITraderTableRepository traderTableRepository,
     IHistoryTableRepository historyTableRepository)
 {
     this.traderTableRepository      = traderTableRepository;
     this.traderStockTableRepository = traderStockTableRepository;
     this.historyTableRepository     = historyTableRepository;
 }
コード例 #2
0
 public TradingService(
     IAccountTableRepository accountTableRepository,
     IStockPriceTableRepository stockPriceTableRepository,
     IHistoryTableRepository historyTableRepository,
     IStockOfClientTableRepository stockOfClientTableRepository,
     ILogger logger)
 {
     this.accountTableRepository       = accountTableRepository;
     this.stockPriceTableRepository    = stockPriceTableRepository;
     this.historyTableRepository       = historyTableRepository;
     this.stockOfClientTableRepository = stockOfClientTableRepository;
     this.logger = logger;
 }
コード例 #3
0
 public ShowDbInfoService(
     IClientsTableRepository clientsTableRepository,
     IAccountTableRepository accountTableRepository,
     IStockPriceTableRepository stockPriceTableRepository,
     IHistoryTableRepository historyTableRepository,
     IStockOfClientTableRepository stockOfClientTableRepository)
 {
     this.clientsTableRepository       = clientsTableRepository;
     this.accountTableRepository       = accountTableRepository;
     this.stockPriceTableRepository    = stockPriceTableRepository;
     this.historyTableRepository       = historyTableRepository;
     this.stockOfClientTableRepository = stockOfClientTableRepository;
 }
コード例 #4
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();
        }
コード例 #5
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();
        }
コード例 #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 HistoryService(IHistoryTableRepository historyTableRepository)
 {
     this.historyTableRepository = historyTableRepository;
 }
コード例 #9
0
 public DealController(IHistoryTableRepository transactionsService, IStockTableRepository stockService)
 {
     this.transactionsService = transactionsService;
     this.stockService        = stockService;
 }
コード例 #10
0
 public TransactionsController(IHistoryTableRepository transactionsService)
 {
     this.transactionsService = transactionsService;
 }