private static void SubscribeToPricesWithCustomFactory(string username, string lightstreamerUrl, ApiLogOnResponseDTO logonResponse, int validMarketId)
 {
     var cityindexStreamingConnection = new DefaultCityindexStreamingConnectionFactory().Create(new Uri(lightstreamerUrl + "/CITYINDEXSTREAMING"), username, logonResponse.Session);
     cityindexStreamingConnection.Connect();
     PriceStream priceStream = new PriceStream(cityindexStreamingConnection);
     priceStream.SubscribeToMarketPrice(validMarketId);
     priceStream.PriceChanged += new PriceChangedEventHandler(CustomPriceStream_PriceChanged);
 }
        public void ValidSubscribtionsAreAddedToAToNewsStreamListenerList()
        {
            // Arrange
            var mockPriceListener = MockRepository.GenerateMock<IStreamingListener<PriceDTO>>();

            _mockLsCityindexStreamingConnection.Expect(x => x.BuildPriceListener(Arg<string>.Is.Anything))
                .Return(mockPriceListener)
                .Repeat.Twice();

            // Act
            var priceStream = new PriceStream(_mockLsCityindexStreamingConnection);
            priceStream.SubscribeToMarketPrice(1);
            priceStream.SubscribeToMarketPrice(2);

            // Assert
            Assert.AreEqual(2, priceStream.Listeners.Count);
            _mockLsCityindexStreamingConnection.VerifyAllExpectations();
            mockPriceListener.VerifyAllExpectations();
        }
        public void UnsubscribeStopsEachThePriceListener()
        {
            // Arrange
            var mockPriceListener = MockRepository.GenerateMock<IStreamingListener<PriceDTO>>();
            var mockPriceListener2 = MockRepository.GenerateMock<IStreamingListener<PriceDTO>>();
            
            _mockLsCityindexStreamingConnection.Expect(x => x.BuildPriceListener(Arg<string>.Is.Anything))
                .Return(mockPriceListener)
                .Repeat.Once();

            _mockLsCityindexStreamingConnection.Expect(x => x.BuildPriceListener(Arg<List<string>>.Is.Anything))
               .Return(mockPriceListener2)
               .Repeat.Once();

            mockPriceListener.Expect(x => x.Stop());
            mockPriceListener2.Expect(x => x.Stop());

            // Act
            var priceStream = new PriceStream(_mockLsCityindexStreamingConnection);
            priceStream.SubscribeToMarketPrice(new int());
            priceStream.SubscribeToMarketPriceList(new List<int>());
            priceStream.Unsubscribe();

            // Assert
            _mockLsCityindexStreamingConnection.VerifyAllExpectations();
            mockPriceListener.VerifyAllExpectations();
            mockPriceListener2.VerifyAllExpectations();
        }