public int GetId(StockRegistrationInfo stockInfo)
        {
            var entity = this.dbContext.Stocks.First(f =>
                                                     f.Type == stockInfo.Type &&
                                                     f.Price == stockInfo.Price);

            return(entity.ID);
        }
Ejemplo n.º 2
0
        public string Post([FromBody] StockRegistrationInfo value)
        {
            StockEntity stock = new StockEntity()
            {
                Type  = value.Type,
                Price = value.Price,
            };

            stocksService.Add(stock);
            stocksService.SaveChanges();
            int id = stocksService.GetId(value);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(stocksService.Get(id)));
        }
Ejemplo n.º 3
0
        public int RegisterNewStock(StockRegistrationInfo args)
        {
            var entityToAdd = new StockEntity()
            {
                Type  = args.Type,
                Price = args.Price
            };

            if (this.stockTableRepository.Contains(entityToAdd))
            {
                throw new ArgumentException("This stock is already exists. Can't continue");
            }
            this.stockTableRepository.Add(entityToAdd);
            this.stockTableRepository.SaveChanges();
            return(entityToAdd.ID);
        }
Ejemplo n.º 4
0
        public void ShouldNotRegisterNewStockIfItExists()
        {
            //Arrange
            var stockTableRepository = Substitute.For<IStockTableRepository>();
            StocksService stockService = new StocksService(stockTableRepository);
            StockRegistrationInfo args = new StockRegistrationInfo();
            args.Type = "StockTypeA";
            args.Price = 10;

            //Act
            stockService.RegisterNewStock(args);

            stockTableRepository.Contains(Arg.Is<StockEntity>(w =>
            w.Type == args.Type
            && w.Price == args.Price)).Returns(true);
            stockService.RegisterNewStock(args);

        }
Ejemplo n.º 5
0
        public void ShouldRegisterNewStock()
        {
            //Arrange
            var stockTableRepository = Substitute.For<IStockTableRepository>();
            StocksService stockService = new StocksService(stockTableRepository);
            StockRegistrationInfo args = new StockRegistrationInfo();
            args.Type = "StockTypeA";
            args.Price = 10;

            //Act
            var stockId = stockService.RegisterNewStock(args);

            //Assert
            stockTableRepository.Received(1).Add(Arg.Is<StockEntity>(w =>
            w.Type == args.Type
            && w.Price == args.Price));
            stockTableRepository.Received(1).SaveChanges();
        }
Ejemplo n.º 6
0
        public int RegisterNewStock(StockRegistrationInfo args)
        {
            var entityToAdd = new StockEntity()
            {
                Name = args.Name,
                Type = args.Type,
                Cost = args.Cost
            };

            if (this.stockTableRepository.Contains(entityToAdd))
            {
                throw new ArgumentException("This client has been registered already. Can't continue");
            }

            this.stockTableRepository.Add(entityToAdd);

            this.stockTableRepository.SaveChanges();

            return(entityToAdd.ID);
        }