public static WhenStatement GetCurrentUserRequestIsSend(this WhenStatement whenStatement, string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Getting current user", whenStatement.GetType().Name);

            var session = whenStatement.GetSessionFromData(testKey);

            var response = _facade.GetMe(session);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse + testKey);
            try
            {
                var currentUser = response.Map <TestUserModel>();
                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got user {currentUser}", whenStatement.GetType().Name);

                whenStatement.AddResultData(currentUser, BddKeyConstants.CurrentUserResponse + testKey);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find current user in response",
                             whenStatement.GetType().Name);
            }

            return(whenStatement);
        }
        public static WhenStatement CreateUserRequestIsSend(this WhenStatement whenStatement, string testKey = null)
        {
            var userModel = whenStatement.GetGivenData <TestUserModel>(testKey);

            whenStatement.GetStatementLogger()
            .Information($"[{{ContextStatement}}] Creating user {userModel}", whenStatement.GetType().Name);

            var response = _facade.PostCreateNewProfile(userModel);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse + testKey);
            try
            {
                var createdUser = response.Map <TestUserModel>();
                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got new user {createdUser}", whenStatement.GetType().Name);

                whenStatement.AddResultData(createdUser, BddKeyConstants.CreatedUserResponse + testKey);
            }
            catch (Exception e)
            {
                whenStatement.GetStatementLogger()
                .Warning($"[{{ContextStatement}}] {e}", whenStatement.GetType().Name);
            }

            return(whenStatement);
        }
        public static string GetSessionFromData(this WhenStatement whenStatement, string testKey = null)
        {
            string session;

            try
            {
                session = whenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey);
                return(session);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find user session in 'When' data, looking in 'Given'",
                             whenStatement.GetType().Name);
            }

            try
            {
                session = whenStatement.GetGivenData <string>(BddKeyConstants.SessionTokenKey + testKey);
                return(session);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information(
                    "[{ContextStatement}] Could not find user session in 'Given' data, looking in last response data",
                    whenStatement.GetType().Name);
            }

            try
            {
                session = whenStatement.GetResultData <HttpResponseMessage>(BddKeyConstants.LastHttpResponse + testKey)
                          .GetTokenFromResponse();
                return(session);
            }
            catch (Exception e)
            {
                whenStatement.GetStatementLogger()
                .Information(
                    "[{ContextStatement}] Could not find user session in 'LastResponse' data, terminating",
                    whenStatement.GetType().Name);
            }

            throw new KeyNotFoundException(
                      "Could not find user session. Probably you should login as a user or provide session itself");
        }
        public static WhenStatement WithSuccess(this WhenStatement whenStatement)
        {
            whenStatement.GetStatementLogger()
            .Information("[{{ContextStatement}}] Expecting last response to have 2XX code",
                         whenStatement.GetType().Name);

            whenStatement.GetResultData <HttpResponseMessage>(BddKeyConstants.LastHttpResponse).AssertSuccess();

            return(whenStatement);
        }
        public static WhenStatement WithCode(this WhenStatement whenStatement, HttpStatusCode code)
        {
            whenStatement.GetStatementLogger()
            .Information($"[{{ContextStatement}}] Expecting last response to have code '{code}'",
                         whenStatement.GetType().Name);

            whenStatement.GetResultData <HttpResponseMessage>(BddKeyConstants.LastHttpResponse).AssertError(code);

            return(whenStatement);
        }
        public static WhenStatement UpdateUserRequestIsSend(this WhenStatement whenStatement,
                                                            TestUserUpdateModel updateModel, string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Getting current user", whenStatement.GetType().Name);

            var session = whenStatement.GetSessionFromData(testKey);

            var response = _facade.PostUpdateProfileNames(session, updateModel);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse + testKey);

            return(whenStatement);
        }