コード例 #1
0
        public void Start_SourceReaderThrowException_OnError()
        {
            //Arrange
            var sourceReaderMock = new Mock<ISourceReader<StockQuote>>();
            sourceReaderMock.Setup(x => x.Read(It.IsAny<SourceDescriptor>())).Throws(new Exception());

            var observerMock = new Mock<IObserver<StockQuote>>();
            var stockQuotesStream = new StockQuotesStream(sourceReaderMock.Object);

            //Act
            stockQuotesStream.Inputs.Subscribe(observerMock.Object);
            stockQuotesStream.Start(new SourceDescriptor("test_test.csv"));

            //Assert
            observerMock.Verify(x => x.OnError(It.IsAny<Exception>()));
        }
コード例 #2
0
        public void Start_SourceReaderReadNElements_NOnNextAndCompleted()
        {
            //Arrange
            var sourceReaderMock = new Mock<ISourceReader<StockQuote>>();
            var stockQuotes = new[] { new StockQuote(), new StockQuote() };
            sourceReaderMock.Setup(x => x.Read(It.IsAny<SourceDescriptor>())).Returns(stockQuotes);

            var observerMock = new Mock<IObserver<StockQuote>>();
            var stockQuotesStream = new StockQuotesStream(sourceReaderMock.Object);

            //Act
            stockQuotesStream.Inputs.Subscribe(observerMock.Object);
            stockQuotesStream.Start(new SourceDescriptor("test_test.csv"));

            //Assert
            observerMock.Verify(x => x.OnNext(It.IsAny<StockQuote>()), Times.Exactly(stockQuotes.Count()));
            observerMock.Verify(x => x.OnCompleted());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: mberent/ATStreaming
        static void Main(string[] args)
        {
            BasicConfigurator.Configure();

            var directory = "Files";

            foreach (var filePath in Directory.EnumerateFiles(directory))
            {
                var descriptor = new SourceDescriptor(filePath);
                var reader = new SourceReader();
                var delay = 10;
                var inputSource = new StockQuotesStream(reader);
                var rocIndex = new RocIndex(delay);

                inputSource.Inputs.Subscribe(rocIndex);
                var pocket = new Pocket(inputSource.Inputs.Skip(delay), rocIndex.Values.Select(x => x > 0 ? true : false), 1000);

                decimal finalValue = 0;
                pocket.Money.Subscribe(Console.WriteLine);

                inputSource.Start(descriptor);
                Console.WriteLine(String.Format("{0}: {1}", Path.GetFileName(filePath), finalValue));
            }
        }