Esempio n. 1
0
        public void SynchronizesData()
        {
            var start = DateTime.UtcNow;
            var end   = start.AddSeconds(15);

            var time    = start;
            var stream1 = Enumerable.Range(0, 10).Select(x => new Tick {
                Time = time.AddSeconds(x * 1)
            }).GetEnumerator();
            var stream2 = Enumerable.Range(0, 5).Select(x => new Tick {
                Time = time.AddSeconds(x * 2)
            }).GetEnumerator();

            var previous     = DateTime.MinValue;
            var synchronizer = new LiveEquityDataSynchronizingEnumerator(new RealTimeProvider(), DateTimeZone.Utc, stream1, stream2);

            while (synchronizer.MoveNext() && DateTime.UtcNow < end)
            {
                if (synchronizer.Current != null)
                {
                    Assert.That(synchronizer.Current.EndTime, Is.GreaterThanOrEqualTo(previous));
                    previous = synchronizer.Current.EndTime;
                }
            }
        }
        public void SynchronizesData(int timeOffsetSeconds, int testTimeSeconds)
        {
            var start = DateTime.UtcNow;
            var end   = start.AddSeconds(testTimeSeconds);

            var time      = start;
            var tickList1 = Enumerable.Range(0, 10).Select(x => new Tick {
                Time = time.AddSeconds(x * 1 + timeOffsetSeconds), Value = x
            }).ToList();
            var tickList2 = Enumerable.Range(0, 5).Select(x => new Tick {
                Time = time.AddSeconds(x * 2 + timeOffsetSeconds), Value = x + 100
            }).ToList();
            var stream1 = tickList1.GetEnumerator();
            var stream2 = tickList2.GetEnumerator();

            var count1       = 0;
            var count2       = 0;
            var previous     = DateTime.MinValue;
            var synchronizer = new LiveEquityDataSynchronizingEnumerator(new RealTimeProvider(), DateTimeZone.Utc, stream1, stream2);

            while (synchronizer.MoveNext() && DateTime.UtcNow < end)
            {
                if (synchronizer.Current != null)
                {
                    if (synchronizer.Current.Value < 100)
                    {
                        Assert.AreEqual(count1, synchronizer.Current.Value);
                        count1++;
                    }
                    else
                    {
                        Assert.AreEqual(count2 + 100, synchronizer.Current.Value);
                        count2++;
                    }

                    Assert.That(synchronizer.Current.EndTime, Is.GreaterThanOrEqualTo(previous));
                    previous = synchronizer.Current.EndTime;

                    Log.Trace($"Data point emitted: {synchronizer.Current.EndTime:O} - {synchronizer.Current}");
                }
            }

            Log.Trace($"Total point count: {count1 + count2}");

            Assert.AreEqual(tickList1.Count, count1);
            Assert.AreEqual(tickList2.Count, count2);
            synchronizer.Dispose();
        }