public void SetUp()
        {
            _mockStreamingManager = MockRepository.GenerateMock<IStreamingManager>();
            _mockPriceStreamFactory = MockRepository.GenerateMock<IPriceStreamFactory>();
            _mockNewsStreamFactory = MockRepository.GenerateMock<INewsStreamFactory>();
            _mockOrderStreamFactory = MockRepository.GenerateMock<IOrderStreamFactory>();

            _streams = new Streams(_mockStreamingManager, _mockPriceStreamFactory, _mockNewsStreamFactory, _mockOrderStreamFactory);

            _mockLsCityindexStreamingConnection = MockRepository.GenerateMock<ILsCityindexStreamingConnection>();
            _mockLStreamingClientAccountConnection = MockRepository.GenerateMock<ILsStreamingClientAccountConnection>();

            _mockApiConnection = MockRepository.GenerateMock<IApiConnection>();
            _mockLightStreamerConnectionManager = MockRepository.GenerateMock<LightStreamerConnectionManager>(_mockApiConnection);
        }
        public void ConnectToStreamingClientAccountAdapterConnectsWithTheCorrectParametersAndReturnsIt()
        {
            //Arrange
            Uri streamingClientAccountAdapterUsed = null;
            _mockLsStreamingClientAccountConnectionFactory.Expect(
                x => x.Create(Arg<Uri>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything))
                .Return(_mockLsStreamingClientAccountConnection)
                .WhenCalled(x => streamingClientAccountAdapterUsed = (Uri)x.Arguments[0]);

            _mockLsStreamingClientAccountConnection.Expect(x => x.Connect());

            // Act
            var lightStreamerConnectionManager = new LightStreamerConnectionManager(_mockApiConnection);
            lightStreamerConnectionManager.ConnectToStreamingClientAccountAdapter(STREAMING_URL, _mockLsStreamingClientAccountConnectionFactory);

            // Assert
            Assert.AreEqual(STREAMING_URL + "/" + STREAMINGCLIENTACCOUNT_ADAPTER, streamingClientAccountAdapterUsed.AbsoluteUri);
            Assert.AreEqual(_mockLsStreamingClientAccountConnection, lightStreamerConnectionManager.LsStreamingClientAccountConnection);
            Assert.IsTrue(lightStreamerConnectionManager.StreamingClientAccountAdapterIsConnected);
            _mockLsStreamingClientAccountConnectionFactory.VerifyAllExpectations();
            _mockLsStreamingClientAccountConnection.VerifyAllExpectations();
        }
        public void ThrowsInvalidOperationExceptionIfTryToConnectToCityindexStreamingAdapterTwice()
        {
            //Arrange
            _mockLsCityindexStreamingConnectionFactory.Expect(
                x => x.Create(Arg<Uri>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything))
                .Return(_mockLsCityindexStreamingConnection)
                .Repeat.Any();

            _mockLsCityindexStreamingConnection.Expect(x => x.Connect())
                .Repeat.Once();

            // Act
            var lightStreamerConnectionManager = new LightStreamerConnectionManager(_mockApiConnection);
            //first call
            lightStreamerConnectionManager.ConnectToCityindexStreamingAdapter(STREAMING_URL, _mockLsCityindexStreamingConnectionFactory);
            //second call
            lightStreamerConnectionManager.ConnectToCityindexStreamingAdapter(STREAMING_URL, _mockLsCityindexStreamingConnectionFactory);

            // Assert
            _mockLsCityindexStreamingConnectionFactory.VerifyAllExpectations();
            _mockLsCityindexStreamingConnection.VerifyAllExpectations();
        }
        public void LightStreamerConnectionManagerDisconnectCallsDisconnectOnTheConnectionsIfNotNull()
        {
            // Arrange
            // Create a valid lightstreamer connections
            _mockLsCityindexStreamingConnectionFactory.Expect(
                x => x.Create(Arg<Uri>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything))
                .Return(_mockLsCityindexStreamingConnection);

            _mockLsStreamingClientAccountConnectionFactory.Expect(
                x => x.Create(Arg<Uri>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything))
                .Return(_mockLsStreamingClientAccountConnection);

            _mockLsCityindexStreamingConnection.Expect(x => x.Disconnect()).Repeat.Once();
            _mockLsStreamingClientAccountConnection.Expect(x => x.Disconnect()).Repeat.Once();

            // Act
            var lightStreamerConnectionManager = new LightStreamerConnectionManager(_mockApiConnection);
            lightStreamerConnectionManager.ConnectToStreamingClientAccountAdapter(STREAMING_URL, _mockLsStreamingClientAccountConnectionFactory);
            lightStreamerConnectionManager.ConnectToCityindexStreamingAdapter(STREAMING_URL, _mockLsCityindexStreamingConnectionFactory);

            // Act - then disconnect
            lightStreamerConnectionManager.Disconnect();
            // this time we do not expect the lightstreamerClientConnection Disconnect to be called
            lightStreamerConnectionManager.Disconnect();

            // Assert
            Assert.IsFalse(lightStreamerConnectionManager.StreamingClientAccountAdapterIsConnected);
            Assert.IsFalse(lightStreamerConnectionManager.CityindexStreamingAdaterIsConnected);
            _mockLsCityindexStreamingConnectionFactory.VerifyAllExpectations();
            _mockLsStreamingClientAccountConnectionFactory.VerifyAllExpectations();
            _mockLsCityindexStreamingConnection.VerifyAllExpectations();
            _mockLsStreamingClientAccountConnection.VerifyAllExpectations();
        }
 public void SetUp()
 {
     _mockApiConnection = MockRepository.GenerateMock<IApiConnection>();
     _mockLightStreamerConnectionManager = MockRepository.GenerateMock<LightStreamerConnectionManager>(_mockApiConnection);
     _streamingManager = new StreamingManager(_mockLightStreamerConnectionManager);
 }