public void ShouldEditClientStockAmount()
        {
            // Arrange

            ClientStockService clientStockService = new ClientStockService(clientStockTableRepository);

            clientStockTableRepository.ContainsByPK(1, 1).Returns(true);
            int clientId = 1;
            int stockId  = 1;

            int         amount      = 5;
            ClientStock clientStock = new ClientStock()
            {
                ClientID = 1,
                StockID  = 1,
                Quantity = 1000,
            };

            // Act
            clientStockService.EditClientStocksAmount(clientId, stockId, amount);

            // Assert
            clientStockTableRepository.Received(1).FindByPK(clientId, stockId);
            clientStock.Quantity += amount;
            clientStockTableRepository.Received(1).SaveChanges();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            var logger = new Logger(log4net.LogManager.GetLogger("Logger"));

            var optionsBuilder = new DbContextOptionsBuilder <ExchangeContext>();

            optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=StockExchangeW;Trusted_Connection=True;");
            IUnitOfWork unitOfWork = new UnitOfWork(new ExchangeContext(optionsBuilder.Options));

            IClientService             clientService             = new ClientService(unitOfWork);
            IClientStockService        clientStockService        = new ClientStockService(unitOfWork);
            IOrderService              orderService              = new OrderService(unitOfWork);
            IStockService              stockService              = new StockService(unitOfWork);
            ITransactionHistoryService transactionHistoryService = new TransactionHistoryService(unitOfWork);



            StockExchange stockExchange = new StockExchange(
                unitOfWork,
                clientService,
                clientStockService,
                orderService,
                stockService,
                transactionHistoryService,
                logger);



            logger.Info("Trading is started");
            stockExchange.RunTraiding();
            logger.Info("Trading is finished");
        }
Exemple #3
0
 public StockExchange(ExchangeContext db,
                      ITableRepository <Client> clientTableRepository,
                      ITableRepository <ClientStock> clientStockTableRepository,
                      ITableRepository <Issuer> issuerTableRepository,
                      ITableRepository <Order> orderTableRepository,
                      ITableRepository <PriceHistory> priceHistoryTableRepository,
                      ITableRepository <Stock> stockTableRepository,
                      ITableRepository <TransactionHistory> transactionHistoryTableRepository,
                      ClientService clientService,
                      ClientStockService clientStockService,
                      OrderService orderService,
                      PriceHistoryService priceHistoryService,
                      TransactionHistoryService transactionHistoryService,
                      ILogger logger
                      )
 {
     this.db = db;
     this.clientTableRepository             = clientTableRepository;
     this.clientStockTableRepository        = clientStockTableRepository;
     this.issuerTableRepository             = issuerTableRepository;
     this.orderTableRepository              = orderTableRepository;
     this.priceHistoryTableRepository       = priceHistoryTableRepository;
     this.stockTableRepository              = stockTableRepository;
     this.transactionHistoryTableRepository = transactionHistoryTableRepository;
     this.clientService             = clientService;
     this.clientStockService        = clientStockService;
     this.orderService              = orderService;
     this.priceHistoryService       = priceHistoryService;
     this.transactionHistoryService = transactionHistoryService;
     this.logger = logger;
 }
        public void ShouldThrowExceptionIfCantFindClientStock()
        {
            // Arrange

            ClientStockService clientStockService = new ClientStockService(clientStockTableRepository);

            clientStockTableRepository.ContainsByPK(1, 1).Returns(false);

            // Act
            var clientStock = clientStockService.GetEntityByCompositeID(1, 1);
        }
        public void ShouldGetClientStockInfo()
        {
            // Arrange

            ClientStockService clientStockService = new ClientStockService(clientStockTableRepository);

            clientStockTableRepository.ContainsByPK(1, 1).Returns(true);


            // Act
            var clientStock = clientStockService.GetEntityByCompositeID(1, 1);

            // Assert
            clientStockTableRepository.Received(1).FindByPK(1, 1);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            var             logger = new Logger(log4net.LogManager.GetLogger("Logger"));
            ExchangeContext db     = new ExchangeContext();

            IDTOMethodsforPriceHistory dTOMethodsforPriceHistory = new DTOMethodsforPriceHistory(db);

            ITableRepository <Client>             clientTableRepository             = new ClientTableRepository <Client>(db);
            ITableRepository <ClientStock>        clientStockTableRepository        = new ClientStockTableRepository <ClientStock>(db);
            ITableRepository <Issuer>             issuerTableRepository             = new IssuerTableRepository <Issuer>(db);
            ITableRepository <Order>              orderTableRepository              = new OrderTableRepository <Order>(db);
            ITableRepository <PriceHistory>       priceHistoryTableRepository       = new PriceHistoryTableRepository <PriceHistory>(db);
            ITableRepository <Stock>              stockTableRepository              = new StockTableRepository <Stock>(db);
            ITableRepository <TransactionHistory> transactionHistoryTableRepository = new TransactionHistoryTableRepository <TransactionHistory>(db);

            ClientService             clientService             = new ClientService(clientTableRepository);
            ClientStockService        clientStockService        = new ClientStockService(clientStockTableRepository);
            OrderService              orderService              = new OrderService(orderTableRepository);
            PriceHistoryService       priceHistoryService       = new PriceHistoryService(priceHistoryTableRepository, dTOMethodsforPriceHistory);
            TransactionHistoryService transactionHistoryService = new TransactionHistoryService(transactionHistoryTableRepository);



            StockExchange stockExchange = new StockExchange(
                db,
                clientTableRepository,
                clientStockTableRepository,
                issuerTableRepository,
                orderTableRepository,
                priceHistoryTableRepository,
                stockTableRepository,
                transactionHistoryTableRepository,
                clientService,
                clientStockService,
                orderService,
                priceHistoryService,
                transactionHistoryService,
                logger);


            using (db)
            {
                logger.Info("Trading is started");
                stockExchange.RunTraiding();
                logger.Info("Trading is finished");
            };
        }
        public void ShouldAddNewClientStock()
        {
            //Arrange
            ClientStockService clientStockService = new ClientStockService(clientStockTableRepository);
            ClientStockInfo    clientStockInfo    = new ClientStockInfo
            {
                ClientId = 1,
                StockId  = 1,
                Amount   = 10
            };

            //Act
            clientStockService.AddClientStock(clientStockInfo);
            //Assert
            clientStockTableRepository.Received(1).Add(Arg.Is <ClientStock>(
                                                           w => w.ClientID == 1 &&
                                                           w.StockID == 1 &&
                                                           w.Quantity == 10
                                                           ));
        }
        public void ShouldNotAddNewClientStockIfItExists()
        {
            // Arrange

            ClientStockService clientStockService = new ClientStockService(clientStockTableRepository);
            ClientStockInfo    clientStockInfo    = new ClientStockInfo
            {
                ClientId = 1,
                StockId  = 1,
                Amount   = 10
            };

            // Act
            clientStockService.AddClientStock(clientStockInfo);

            clientStockTableRepository.ContainsDTO(Arg.Is <ClientStock>(
                                                       w => w.ClientID == 1 &&
                                                       w.StockID == 1 &&
                                                       w.Quantity == 10)).Returns(true);

            clientStockService.AddClientStock(clientStockInfo);
        }