Esempio n. 1
0
        public async Task <List <Order> > AddOrders(List <Watcher> watchers)
        {
            // Start watch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Grab watchers willing to buy or sell
            watchers = watchers.Where(WatcherExpression.WatcherBuyingOrSelling().Compile()).ToList();

            // Build new orders
            var newOrders = OrderBuilder.BuildNewOrders(watchers);

            // Add
            _mainDbContext.Orders.AddRange(newOrders);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Stop watch
            stopwatch.Stop();

            // Log
            _logger.LogInformation("{@Event}, {@Count}, {@ExecutionTime}", "OrdersAdded", newOrders.Count, stopwatch.Elapsed.TotalSeconds);

            // Return
            return(newOrders);
        }
        public void Test_WatcherBuyingOrSelling()
        {
            // Arrange
            var watchersBuyingAndSelling = FakeWatcher.GetWatchersBuyingAndSelling();

            // Act
            var filter = watchersBuyingAndSelling.Where(WatcherExpression.WatcherBuyingOrSelling().Compile()).ToList();

            // Assert
            Assert.AreEqual(watchersBuyingAndSelling.Count, filter.Count);
        }