Пример #1
0
        public async void AddTransactionAsync()
        {
            // arrange
            var serviceProvider = ServiceCreator.CreateServiceCollection();
            var transactionRepo = serviceProvider.GetService <ITransactionRepository>();
            var securityRepo    = serviceProvider.GetService <ISecurityRepository>();
            var portfolioRepo   = serviceProvider.GetService <IPortfolioRepository>();

            TransactionService transactionService = new TransactionService(transactionRepo, securityRepo, portfolioRepo);

            var sqlExecutor = new SqlExecutor();

            var portfolio = new Portfolio()
            {
                PortfolioName = Guid.NewGuid().ToString().Substring(1, 6)
            };

            // insert portfolio
            string sql = $"INSERT INTO Portfolio (PortfolioName) VALUES ({portfolio.PortfolioName})";

            portfolio.Id = (int)sqlExecutor.ExecuteScalar(sql);

            var transaction = new Transaction()
            {
                Action      = "Buy",
                Amount      = 200,
                Date        = DateTime.UtcNow,
                Description = "test",
                Fees        = 0,
                PortfolioId = portfolio.Id,
                Price       = 20,
                Quantity    = 10,
                Symbol      = "HD"
            };

            // act
            var result = await transactionService.AddTransactionAsync(transaction, portfolio.Id);

            // assert
            Assert.True(result);
        }