Ejemplo n.º 1
0
        public virtual ApiLogOnResponseDTO Login(string username, string password, string tradingUrl)
        {
            try
            {
                if (_loggedIn)
                {
                    Log.Info("Tried to log in twice, must log off before logging in again.");
                    return _apiLogOnResponseDTO;
                }

                Log.Debug("logging in with username " + username + ".");
                if (_coreConnection == null)
                    _coreConnection = new Connection(username, password, tradingUrl);
                
                _apiLogOnResponseDTO = _coreConnection.Authenticate(username, password);

                _userName = username;
                _session = _apiLogOnResponseDTO.Session;
                _loggedIn = true;
                return _apiLogOnResponseDTO;
            }
            catch (Exception ex)
            {
                Log.Error("Error trying to log in: " + ex);
                throw;
            }
        }
Ejemplo n.º 2
0
        public virtual ApiLogOnResponseDTO Login(string username, string password, string tradingUrl)
        {
            try
            {
                if (_loggedIn)
                {
                    Log.Info("Tried to log in twice, must log off before logging in again.");
                    return(_apiLogOnResponseDTO);
                }

                Log.Debug("logging in with username " + username + ".");
                if (_coreConnection == null)
                {
                    _coreConnection = new Connection(username, password, tradingUrl);
                }

                _apiLogOnResponseDTO = _coreConnection.Authenticate(username, password);

                _userName = username;
                _session  = _apiLogOnResponseDTO.Session;
                _loggedIn = true;
                return(_apiLogOnResponseDTO);
            }
            catch (Exception ex)
            {
                Log.Error("Error trying to log in: " + ex);
                throw;
            }
        }
Ejemplo n.º 3
0
        public void CanLogin()
        {
            var server = new TestServer(true);

            server.Start();



            server.ProcessRequest += (s, e) =>
            {
                var dto = new ApiLogOnResponseDTO
                {
                    AllowedAccountOperator = true,
                    PasswordChangeRequired = false,
                    Session =
                        "86c6b0df-24d4-4b3f-b699-688626817599"
                };
                string json = JsonConvert.SerializeObject(dto);
                e.Response = TestServer.CreateRpcResponse(json);
            };
            try
            {
                var ctx = new Client(new Uri("http://localhost.:" + server.Port), new Uri("http://localhost.:" + server.Port), "foo");

                ctx.LogIn(Settings.RpcUserName, Settings.RpcPassword);

                Assert.IsNotNullOrEmpty(ctx.Session);
                ctx.Dispose();
            }
            finally
            {
                server.Stop();
            }
        }
Ejemplo n.º 4
0
 protected void Application_Start(object sender, EventArgs e)
 {
     // set up a capturing logger so that we can output snapshots of activity upon page render
     LogManager.CreateInnerLogger =
         (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) =>
     {
         return(new CapturingAppender(logName, logLevel, showLevel, showDateTime, showLogName,
                                      dateTimeFormat));
     };
     try
     {
         GlobalRpcClient = new Client(new Uri("https://ciapipreprod.cityindextest9.co.uk/TradingApi"), AppKey);
         ApiLogOnResponseDTO response = GlobalRpcClient.LogIn("XX070608", "password");
         if (response.PasswordChangeRequired)
         {
             _rpcStatus = "admin must change password for global account";
         }
         else
         {
             _rpcStatus = "OK";
         }
     }
     catch (ApiException ex)
     {
         _rpcStatus = ex.ToString();
     }
     catch (Exception ex)
     {
         _rpcStatus = ex.ToString();
     }
 }
 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);
 }
Ejemplo n.º 6
0
 private void SetUpApiInstanceToBeLoggedOut()
 {
     if (!CiApi.Instance.LoggedIn)
     {
         var response = new ApiLogOnResponseDTO();
         _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response).Repeat.Once();
         CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
     }
     CiApi.Instance.Logout();
 }
Ejemplo n.º 7
0
        public void InvalidOperationExceptionThrownIfTryToLogInWhenAlreadyLoggedIn()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            var response = new ApiLogOnResponseDTO(){Session = "newSession"};
            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response);

            // Act
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            // log in again
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            _mockApiConnection.VerifyAllExpectations();
        }
        public void LoginCreatesATradingConnectionAndReturnsASessionAndSetsLoggedInToTrue()
        {
            // Arrange
            var logOnResponseDTO = new ApiLogOnResponseDTO {Session = SESSION_ID};

            _mockConnection.Expect(x => x.Authenticate(USERNAME, PASSWORD))
                .Return(logOnResponseDTO);

            // Act
            var apiLogOnResponseDTO = _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);

            // Assert
            Assert.AreEqual(SESSION_ID, apiLogOnResponseDTO.Session);
            Assert.IsTrue(_apiConnection.LoggedIn);
            _mockConnection.VerifyAllExpectations();
        }
        public void IfLoginIsCalledTwiceOnlyOneConnectionIsCreated()
        {
            // Arrange
            var logOnResponseDTO = new ApiLogOnResponseDTO { Session = SESSION_ID };

            _mockConnection.Expect(x => x.Authenticate(USERNAME, PASSWORD))
                .Return(logOnResponseDTO)
                .Repeat.Once();

            // Act
            var apiLogOnResponseDTO = _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);
            var apiLogOnResponseDTOSecondCall = _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);

            // Assert
            Assert.AreEqual(apiLogOnResponseDTO, apiLogOnResponseDTOSecondCall);
            _mockConnection.VerifyAllExpectations();
        }
Ejemplo n.º 10
0
        public void LoginCallsApiConnectionLoginMethodAndIfItsSessionIsNotNullLoggedInIsSetToTrue()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            var response = new ApiLogOnResponseDTO(){Session = "validSession"};
            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response);
            
            // Act
            var result = CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);

            // Assert
            Assert.IsTrue(CiApi.Instance.LoggedIn);
            Assert.AreEqual(response, result);
            _mockApiConnection.VerifyAllExpectations();
        }
Ejemplo n.º 11
0
        public void LoginCreatesATradingConnectionAndReturnsASessionAndSetsLoggedInToTrue()
        {
            // Arrange
            var logOnResponseDTO = new ApiLogOnResponseDTO {
                Session = SESSION_ID
            };

            _mockConnection.Expect(x => x.Authenticate(USERNAME, PASSWORD))
            .Return(logOnResponseDTO);

            // Act
            var apiLogOnResponseDTO = _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);

            // Assert
            Assert.AreEqual(SESSION_ID, apiLogOnResponseDTO.Session);
            Assert.IsTrue(_apiConnection.LoggedIn);
            _mockConnection.VerifyAllExpectations();
        }
Ejemplo n.º 12
0
        public void InvalidOperationExceptionThrownIfTryToLogInWhenAlreadyLoggedIn()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            var response = new ApiLogOnResponseDTO()
            {
                Session = "newSession"
            };

            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response);

            // Act
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            // log in again
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            _mockApiConnection.VerifyAllExpectations();
        }
Ejemplo n.º 13
0
        public void IfLoginIsCalledTwiceOnlyOneConnectionIsCreated()
        {
            // Arrange
            var logOnResponseDTO = new ApiLogOnResponseDTO {
                Session = SESSION_ID
            };

            _mockConnection.Expect(x => x.Authenticate(USERNAME, PASSWORD))
            .Return(logOnResponseDTO)
            .Repeat.Once();

            // Act
            var apiLogOnResponseDTO           = _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);
            var apiLogOnResponseDTOSecondCall = _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);

            // Assert
            Assert.AreEqual(apiLogOnResponseDTO, apiLogOnResponseDTOSecondCall);
            _mockConnection.VerifyAllExpectations();
        }
Ejemplo n.º 14
0
        public void LogoutCallsTheApiConnectionLogoutMethod()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            var apiLogOnResponseDTO = new ApiLogOnResponseDTO()
            {
                Session = "session"
            };

            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(apiLogOnResponseDTO);
            _mockApiConnection.Expect(x => x.Logout());

            // Act
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            CiApi.Instance.Logout();

            // Assert
            _mockApiConnection.VerifyAllExpectations();
        }
Ejemplo n.º 15
0
        public void LoginCallsApiConnectionLoginMethodAndIfItsSessionIsNotNullLoggedInIsSetToTrue()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            var response = new ApiLogOnResponseDTO()
            {
                Session = "validSession"
            };

            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response);

            // Act
            var result = CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);

            // Assert
            Assert.IsTrue(CiApi.Instance.LoggedIn);
            Assert.AreEqual(response, result);
            _mockApiConnection.VerifyAllExpectations();
        }
Ejemplo n.º 16
0
        protected void LoginButtonClick(object sender, EventArgs e)
        {
            ApiLogOnResponseDTO response = null;

            try
            {
                response = SessionClient.LogIn(UserNameTextBox.Text, PasswordTextBox.Text);
                if (response.PasswordChangeRequired)
                {
                    DisplayError("You must change your password.");
                    LoggedInPanel.Visible       = false;
                    ChangePasswordPanel.Visible = true;
                }
            }
            catch (Exception ex)
            {
                DisplayError(ex.Message);
            }

            ManagePanels();
        }
        public void LogoutSetsCoreConnectionToNullAndLoggedInStatusToFalse()
        {
            // Arrange
            var logOnResponseDTO = new ApiLogOnResponseDTO { Session = SESSION_ID };

            _mockConnection.Expect(x => x.Authenticate(USERNAME, PASSWORD))
                .Return(logOnResponseDTO)
                .Repeat.Once();

            // Assert before logout
            _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);
            Assert.IsNotNull(_apiConnection.CoreConnection);
            Assert.IsTrue(_apiConnection.LoggedIn);

            // Act
            _apiConnection.Logout();
            
            // Assert
            Assert.IsNull(_apiConnection.CoreConnection);
            Assert.IsFalse(_apiConnection.LoggedIn);
            _mockConnection.VerifyAllExpectations();
        }
Ejemplo n.º 18
0
        public void LogoutSetsCoreConnectionToNullAndLoggedInStatusToFalse()
        {
            // Arrange
            var logOnResponseDTO = new ApiLogOnResponseDTO {
                Session = SESSION_ID
            };

            _mockConnection.Expect(x => x.Authenticate(USERNAME, PASSWORD))
            .Return(logOnResponseDTO)
            .Repeat.Once();

            // Assert before logout
            _apiConnection.Login(USERNAME, PASSWORD, TRADING_URL);
            Assert.IsNotNull(_apiConnection.CoreConnection);
            Assert.IsTrue(_apiConnection.LoggedIn);

            // Act
            _apiConnection.Logout();

            // Assert
            Assert.IsNull(_apiConnection.CoreConnection);
            Assert.IsFalse(_apiConnection.LoggedIn);
            _mockConnection.VerifyAllExpectations();
        }
Ejemplo n.º 19
0
        public void ServiceManagerPropertyLoadsTheFirstTimeItsCalled()
        {
            //Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            // Log in
            var apiLogOnResponseDTO = new ApiLogOnResponseDTO()
            {
                Session = "session"
            };

            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(apiLogOnResponseDTO);

            // Act
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            var serviceManager           = CiApi.Instance.ServiceManager;
            var serviceManagerSecondCall = CiApi.Instance.ServiceManager;

            // Assert
            Assert.IsNotNull(serviceManager);
            Assert.AreEqual(serviceManager, serviceManagerSecondCall);
            _mockApiConnection.VerifyAllExpectations();
        }
Ejemplo n.º 20
0
        public void IfLoggedInThenLogoutCallsDisconnectsTheStreamingManager()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            // Login
            var apiLogOnResponseDTO = new ApiLogOnResponseDTO() { Session = "session" };
            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(apiLogOnResponseDTO);

            _mockStreamingManager.Expect(x => x.Disconnect());

            // Act
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            CiApi.Instance.Logout();

            // Assert
            _mockStreamingManager.VerifyAllExpectations();
        }
        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);
        }
Ejemplo n.º 22
0
 private void SetUpApiInstanceToBeLoggedOut()
 {
     if(!CiApi.Instance.LoggedIn)
     {
         var response = new ApiLogOnResponseDTO();
         _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response).Repeat.Once();
         CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
     }
     CiApi.Instance.Logout();
 }
Ejemplo n.º 23
0
        public void ServiceManagerPropertyLoadsTheFirstTimeItsCalled()
        {
            //Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            // Log in
            var apiLogOnResponseDTO = new ApiLogOnResponseDTO() { Session = "session" };
            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(apiLogOnResponseDTO);

            // Act
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);
            var serviceManager = CiApi.Instance.ServiceManager;
            var serviceManagerSecondCall = CiApi.Instance.ServiceManager;

            // Assert
            Assert.IsNotNull(serviceManager);
            Assert.AreEqual(serviceManager, serviceManagerSecondCall);
            _mockApiConnection.VerifyAllExpectations();
        }
Ejemplo n.º 24
0
        public void IfNotLoggedInLogoutDoesNotCallTheApiConnectionLogoutMethod()
        {
            // Arrange
            CiApi.Instance.SetUpApiForMocking(_mockApiConnection, _mockStreamingManager);
            SetUpApiInstanceToBeLoggedOut();

            // Login
            var response = new ApiLogOnResponseDTO(){Session = "session"};
            _mockApiConnection.Expect(x => x.Login(USERNAME, PASSWORD, TRADING_URL)).Return(response).Repeat.Once();
            CiApi.Instance.Login(USERNAME, PASSWORD, TRADING_URL);

            _mockApiConnection.Expect(x => x.Logout());
            
            // Act
            CiApi.Instance.Logout();

            // Assert
            _mockApiConnection.VerifyAllExpectations();
        }