Esempio n. 1
0
        private void UserRegistrate(string name, string surname, string phoneNumber)
        {
            UserRegistrationInfo newUser = new UserRegistrationInfo()
            {
                Name        = name,
                Surname     = surname,
                PhoneNumber = phoneNumber,
            };

            try
            {
                usersService.RegisterNewUser(newUser);
                int         ID          = usersService.GetUserId(newUser);
                int         stockID     = r.Next(1, 10);
                int         stockAmount = r.Next(1, 5);
                BalanceInfo balance     = new BalanceInfo()
                {
                    UserID      = ID,
                    StockID     = stockID,
                    StockAmount = stockAmount,
                    Balance     = stocksService.GetStock(stockID).Price *stockAmount
                };
                balancesService.CreateBalance(balance);
                Logger.Log.Info($"User registration success. New user is {name} {surname} ID: {ID}");
                Console.WriteLine("Registration successful!");
            }
            catch (ArgumentException e)
            {
                Logger.Log.Error($"Registration failed. Message: {e.Message}");
            }
        }
Esempio n. 2
0
        public void DeleteEquityTest()
        {
            var service = new StocksService();
            var stock   = new Equity()
            {
                Price    = 50000,
                Quantity = 3
            };
            var newStockId = service.AddStock(stock);
            var newStock   = service.GetStock(newStockId);

            Assert.IsNotNull(newStock);
            service.DeleteStock(newStock.Id);
            newStock = service.GetStock(newStockId);
            Assert.IsNull(newStock);
        }
        public void ShouldGetExceptionIfStockNotRegistered()
        {
            //Arrange
            var stockTableRepository = Substitute.For<IStockTableRepository>();
            stockTableRepository.Contains(Arg.Is(11)).Returns(false);
            StocksService stockService = new StocksService(stockTableRepository);

            // Act
            var stock = stockService.GetStock(11);
        }
Esempio n. 4
0
        public void EquityNameIsGeneratedTest()
        {
            var service = new StocksService();
            var stock   = new Equity()
            {
                Price    = 50000,
                Quantity = 3
            };
            var newStockId = service.AddStock(stock);
            var newStock   = service.GetStock(newStockId);

            Assert.IsTrue(Regex.IsMatch(newStock.Name, @"Equity\d+"));
        }
        public void ShouldGetStockInfo()
        {
            //Arrange
            var stockTableRepository = Substitute.For<IStockTableRepository>();
            stockTableRepository.Contains(Arg.Is(11)).Returns(true);
            StocksService stockService = new StocksService(stockTableRepository);

            // Act
            var stock = stockService.GetStock(11);

            //Assert
            stockTableRepository.Received(1).Get(11);

        }
Esempio n. 6
0
        public void EquityNameIsInctementedTest()
        {
            var service = new StocksService();
            var stock   = new Equity()
            {
                Price    = 50000,
                Quantity = 3
            };
            var stock1 = new Equity()
            {
                Price    = 50000,
                Quantity = 3
            };

            var newStockId   = service.AddStock(stock);
            var newStock     = service.GetStock(newStockId);
            var newStock1Id  = service.AddStock(stock1);
            var newStock1    = service.GetStock(newStock1Id);
            var numericPart1 = Convert.ToInt32(Regex.Match(newStock.Name, @"\d+").Value);
            var numericPart2 = Convert.ToInt32(Regex.Match(newStock1.Name, @"\d+").Value);

            Assert.IsTrue(numericPart2 - numericPart1 == 1);
        }
Esempio n. 7
0
        public void AddEquityTest()
        {
            var service = new StocksService();
            var stock   = new Equity()
            {
                Price    = 50000,
                Quantity = 3
            };
            var newStockId = service.AddStock(stock);
            var newStock   = service.GetStock(newStockId);

            Assert.IsNotNull(newStock);
            Assert.AreEqual(stock.Price, newStock.Price);
            Assert.AreEqual(stock.Quantity, newStock.Quantity);
        }