Exemple #1
0
        public void UpdateChangingTest()
        {
            var books      = BookGenerator.GenerateBooks(19, 100);
            var aggregator = PrepareAggregator(books);

            var bestAsk = books.BestAsk();
            var bestBid = books.BestBid();

            mockedDataWriter
            .Setup(d => d.Write(It.IsAny <ResultData>()))
            .Callback((ResultData data) =>
            {
                Assert.Equal(data.InstrumentName, InstrumentName);
                Assert.Equal(data.BestAsk, bestAsk);
                Assert.Equal(data.BestBid, bestBid);
            });

            var newBidBook = new Book {
                Amount = 1, Count = 1, Price = bestBid + 1
            };

            bestBid = newBidBook.Price;

            aggregator.GetBook(newBidBook);

            var newAskBook = new Book {
                Amount = -1, Count = 1, Price = bestAsk - 1
            };

            bestAsk = newAskBook.Price;

            aggregator.GetBook(newAskBook);

            mockedDataWriter.Verify(d => d.Write(It.IsAny <ResultData>()), Times.Exactly(2));
        }
Exemple #2
0
        public void DeleteChangingTest()
        {
            var books      = BookGenerator.GenerateBooks(23, 100);
            var aggregator = PrepareAggregator(books);

            var bestAsk = books.BestAsk();
            var bestBid = books.BestBid();

            mockedDataWriter
            .Setup(d => d.Write(It.IsAny <ResultData>()))
            .Callback((ResultData data) =>
            {
                Assert.Equal(data.InstrumentName, InstrumentName);
                Assert.Equal(data.BestAsk, bestAsk);
                Assert.Equal(data.BestBid, bestBid);
            });

            var deleteBook = new Book {
                Count = 0, Amount = 1, Price = bestBid
            };

            bestBid = books.Where(b => b.Count > 0 && b.Amount > 0).OrderByDescending(b => b.Price).Skip(1).First().Price;

            aggregator.GetBook(deleteBook);

            mockedDataWriter.Verify(d => d.Write(It.IsAny <ResultData>()), Times.Once);
        }
Exemple #3
0
        public void SnapshotTest()
        {
            var books = BookGenerator.GenerateBooks(13, 100);

            var bestBid = books.BestBid();
            var bestAsk = books.BestAsk();

            var aggregator = new BookAggregator(mockedDataWriter.Object, ChannelId, InstrumentName);

            mockedDataWriter
            .Setup(d => d.Write(It.IsAny <ResultData>()))
            .Callback((ResultData data) =>
            {
                Assert.Equal(data.InstrumentName, InstrumentName);
                Assert.Equal(data.BestAsk, bestAsk);
                Assert.Equal(data.BestBid, bestBid);
            });

            aggregator.GetSnapshot(books);

            mockedDataWriter.Verify(d => d.Write(It.IsAny <ResultData>()), Times.Once);
            mockedDataWriter.ResetCalls();
        }
        public static Book[] GenerateBooks(int seed, int count)
        {
            var random = new Random(seed);

            return(Enumerable.Range(1, count).Select(r => BookGenerator.GenerateBook(random.Next())).ToArray());
        }