Exemple #1
0
        public void ChangePassword_Success(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            // 1. initializing the session
            InitSession initReq = new InitSession()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                RequestID    = "D3770630-9532-457D-8EBB-DBF99F6A23D3",
                SessionToken = null
            };

            InitSessionResponse initResp = Post <InitSession, InitSessionResponse>("InitSession", initReq);

            string sessionToken = initResp.SessionToken;

            // 2. changing password
            ChangePassword updateReq = base.PrepareRequest <ChangePassword>(name);

            updateReq.SessionToken = sessionToken;

            ChangePasswordResponse updateRes = Post <ChangePassword, ChangePasswordResponse>("ChangePassword", updateReq);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.True(updateRes.Success, "Password was not updated - success = false");
            Assert.IsEmpty(updateRes.Errors, "Unexpected errors returned");
        }
Exemple #2
0
        public object Any(InitSession request)
        {
            var response = Global.RequestsProcessor.Any(request);

            response.RequestID = request.RequestID;
            return(response);
        }
Exemple #3
0
        public void GetSessionInfo_Success(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            // 1. initializing the session
            InitSession request = new InitSession()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                RequestID    = "D3770630-9532-457D-8EBB-DBF99F6A23D3",
                SessionToken = null
            };

            InitSessionResponse response = Post <InitSession, InitSessionResponse>("InitSession", request);

            string sessionToken = response.SessionToken;

            // 2. getting session information
            GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name);

            getSesionInfo.SessionToken = sessionToken;

            GetSessionInfoResponse sessionInfo = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", getSesionInfo);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(sessionInfo.Success, true, "Session was not found");
            Assert.AreNotEqual(sessionInfo.Payload.SessionStart, DateTime.MinValue, "SessionStart time was not provided");
            Assert.IsEmpty(sessionInfo.Errors, "Errors are not empty");
        }
        public ResponseBase Any(InitSession request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: InitSession");
            InitSessionResponse response = new InitSessionResponse();

            try
            {
                // checking account key validity
                GetUserAccountInfoParams accParams = new GetUserAccountInfoParams();
                accParams.AccountKey = request.AccountKey;
                GetUserAccountInfoResult accResult = _dal.GetUserAccountInfo(accParams);
                if (accResult != null)
                {
                    string sessionId = Guid.NewGuid().ToString();

                    Interfaces.DAL.SessionInfo sinfo = new Interfaces.DAL.SessionInfo();
                    sinfo.AccountKey     = request.AccountKey;
                    sinfo.SessionStart   = DateTime.UtcNow;
                    sinfo.SessionExpires = DateTime.UtcNow
                                           + TimeSpan.FromMinutes(ConfigurationManager.AppSettings["SessionExpiresMins"] != null ? Int32.Parse(ConfigurationManager.AppSettings["SessionExpiresMins"]) : 60);
                    sinfo.SessionId = sessionId;

                    // if current session exists - we are just using current session token
                    Interfaces.DAL.SessionInfo existSession = _dal.GetSessionInfo(sinfo, true);
                    if (existSession == null)
                    {
                        _dal.InitSession(sinfo);

                        response.SessionToken = sessionId;
                    }
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.UserAccountNotFound, Type = EErrorType.Error, Message = "Invalid account key provided"
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unexpected error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: InitSession");

            return(response);
        }
Exemple #5
0
        public void TestClient_InitSession_Success()
        {
            ServiceClient client = new ServiceClient();

            InitSession request = new InitSession()
            {
                AccountKey = ConfigurationManager.AppSettings["AccountKey"],
                RequestID  = Guid.NewGuid().ToString()
            };
            var response = client.PostInitSession(request);
        }
Exemple #6
0
        public void InitSession_Success(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            InitSession request = PrepareRequest <InitSession>(name);

            InitSessionResponse response = Post <InitSession, InitSessionResponse>("InitSession", request);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(response.Success, true, "Session was not initialized");
            Assert.IsEmpty(response.Errors, "Errors are not empty");
        }
Exemple #7
0
        public void InitSession_InvalidAccountKey(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            InitSession request = PrepareRequest <InitSession>(name);

            InitSessionResponse response = Post <InitSession, InitSessionResponse>("InitSession", request);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(response.Success, false, "Session was initialized with invalid key");
            Assert.IsNotEmpty(response.Errors, "Errors are empty");
            Assert.AreEqual(response.Errors[0].Code, EErrorCodes.UserAccountNotFound, "Incorrect error code returned");
        }
        public EErrorCodes InitSession(string host, string accountKey)
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (Client == null)
                {
                    Host   = host;
                    Client = new JsonServiceClient(Host);
                }

                if (SessionToken == null || AccountKey != accountKey)
                {
                    AccountKey = accountKey;
                    InitSession reqInit = new InitSession();
                    reqInit.RequestID  = System.Guid.NewGuid().ToString();
                    reqInit.AccountKey = AccountKey;

                    InitSessionResponse resInit = Post <InitSession, InitSessionResponse>("/api/accounts/InitSession", reqInit);

                    if (resInit.Success)
                    {
                        SessionToken = resInit.SessionToken;
                        Indicators   = new Dictionary <string, IndicatorData>();
                        result       = EErrorCodes.Success;
                    }
                    else
                    {
                        result = resInit.Errors[0].Code;
                    }
                }
                else
                {
                    return(EErrorCodes.Success);
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }
Exemple #9
0
        protected void InitSession(string url)
        {
            // Initializing session
            using (var accountClient = new JsonServiceClient(url))
            {
                InitSession reqInit = new InitSession();
                reqInit.RequestID  = System.Guid.NewGuid().ToString();
                reqInit.AccountKey = AccountKey;

                InitSessionResponse resInit = accountClient.Post <InitSessionResponse>("InitSession", reqInit);

                if (resInit.Success)
                {
                    SessionToken = resInit.SessionToken;
                }
                else
                {
                    throw new Exception(string.Format("Init call error:{0}", resInit.Errors[0].Code));
                }
            }
        }
Exemple #10
0
        public void GetSessionInfo_Closed(string name)
        {
            RunInitSql(name, "ConnectionStringAccounts");

            // 1. initializing the session
            InitSession initReq = new InitSession()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                RequestID    = "D3770630-9532-457D-8EBB-DBF99F6A23D3",
                SessionToken = null
            };

            InitSessionResponse initResp = Post <InitSession, InitSessionResponse>("InitSession", initReq);

            string sessionToken = initResp.SessionToken;

            // 2. closing session
            CloseSession closeReq = new CloseSession()
            {
                SessionToken = sessionToken
            };

            CloseSessionResponse closeRes = Post <CloseSession, CloseSessionResponse>("CloseSession", closeReq);

            // 3. getting session information
            GetSessionInfo getSesionInfo = PrepareRequest <GetSessionInfo>(name);

            getSesionInfo.SessionToken = sessionToken;

            GetSessionInfoResponse sessionInfo = Post <GetSessionInfo, GetSessionInfoResponse>("GetSessionInfo", getSesionInfo);

            RunFinalizeSql(name, "ConnectionStringAccounts");

            Assert.AreEqual(sessionInfo.Success, true, "Session was not found");
            Assert.AreNotEqual(sessionInfo.Payload.SessionStart, DateTime.MinValue, "SessionStart time was not provided");
            Assert.AreNotEqual(sessionInfo.Payload.SessionEnd, DateTime.MinValue, "SessionEnd time was not provided");
            Assert.IsNotEmpty(sessionInfo.Errors, "Errors are empty");
            Assert.AreEqual(sessionInfo.Errors[0].Type, EErrorType.Warning, "Warning of closed session is expected");
            Assert.AreEqual(sessionInfo.Errors[0].Code, EErrorCodes.SessionClosed, "Invalid code returned");
        }
        public InitSessionResponse PostInitSession(InitSession request)
        {
            var response = Post <InitSession, InitSessionResponse>("InitSession", request);

            return(response);
        }