public void InvalidDateIsIgnored()
        {
            var logger     = new LoggerStub();
            var repo       = new CandleHistoryRepositoryStub();
            var controller = new CandleGenerationController(repo, logger, "test component", env);

            DateTime unspecified = new DateTime(2017, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
            DateTime local       = new DateTime(2017, 1, 1, 0, 0, 0, DateTimeKind.Local);

            controller.HandleQuote(new Quote()
            {
                AssetPair = "btcrub", IsBuy = true, Price = 1, Timestamp = unspecified
            }).Wait();
            controller.HandleQuote(new Quote()
            {
                AssetPair = "btcrub", IsBuy = true, Price = 1, Timestamp = local
            }).Wait();
            controller.HandleQuote(new Quote()
            {
                AssetPair = "btcrub", IsBuy = true, Price = 1, Timestamp = DateTime.MinValue
            }).Wait();
            controller.HandleQuote(new Quote()
            {
                AssetPair = "btcrub", IsBuy = true, Price = 1, Timestamp = DateTime.MaxValue
            }).Wait();
            Assert.Equal(0, repo.Stored.Count);
        }
        public void NullIsIgnored()
        {
            var logger     = new LoggerStub();
            var repo       = new CandleHistoryRepositoryStub();
            var controller = new CandleGenerationController(repo, logger, "test component", env);

            controller.HandleQuote(null).Wait();
            Assert.Equal(0, repo.Stored.Count);
        }
예제 #3
0
        public void NoExceptionExpectedOnMultithread()
        {
            var logger      = new LoggerStub();
            var candlesRepo = new CandleHistoryRepositoryStub();
            var env         = new EnvironmentStub(new List <AssetPair>()
            {
                new AssetPair()
                {
                    Id = "btcusd", Accuracy = 5
                }
            });
            var controller = new CandleGenerationController(candlesRepo, logger, "test component", env);

            // Cancel after 1 sec
            CancellationTokenSource tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(2));
            CancellationToken       token       = tokenSource.Token;

            int consumeCalledTimes = 0;
            int tickCalledTimes    = 0;

            // Call Consume and Tick methods at the same time repeatedly and check that there was no exception.
            Task producing = Task.Run(async() =>
            {
                while (!token.IsCancellationRequested)
                {
                    await controller.HandleQuote(new Quote()
                    {
                        AssetPair = "btcusd",
                        IsBuy     = true,
                        Price     = 100,
                        Timestamp = DateTime.UtcNow
                    });
                    await Task.Delay(50);
                    Interlocked.Increment(ref consumeCalledTimes);
                }
            }, token);

            Task timer = Task.Run(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    controller.Tick();
                    Interlocked.Increment(ref tickCalledTimes);
                }
            }, token);

            Task.WaitAll(producing, timer);

            Assert.True(consumeCalledTimes > 0);
            Assert.True(tickCalledTimes > 0);
            Assert.True(candlesRepo.Stored.Count > 0);
        }
        public void EmptyAssetIsIgnored()
        {
            var logger     = new LoggerStub();
            var repo       = new CandleHistoryRepositoryStub();
            var controller = new CandleGenerationController(repo, logger, "test component", env);

            controller.HandleQuote(new Quote()
            {
                AssetPair = null, IsBuy = true, Price = 1, Timestamp = Utils.ParseUtc("2017-01-01 10:10:10Z")
            }).Wait();
            controller.HandleQuote(new Quote()
            {
                AssetPair = "", IsBuy = true, Price = 1, Timestamp = Utils.ParseUtc("2017-01-01 10:10:10Z")
            }).Wait();

            Assert.Equal(0, repo.Stored.Count);
        }