예제 #1
0
        public static WhenStatement CreateNewTimeSeriesRequestIsSend(this WhenStatement whenStatement,
                                                                     string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Creating new time-series", whenStatement.GetType().Name);

            var session       = whenStatement.GetSessionFromData(testKey);
            var newTimeSeries =
                whenStatement.GetGivenData <TestTimeSeriesMetadataModel>(BddKeyConstants.TimeSeriesToCreate + testKey);

            var response = _facade.PostCreateTimeSeries(session, newTimeSeries);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse + testKey);
            try
            {
                var createdTimeSeries = response.Map <TestTimeSeriesMetadataModel>();
                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got time-series {createdTimeSeries}",
                             whenStatement.GetType().Name);
                newTimeSeries.Id       = createdTimeSeries.Id;
                newTimeSeries.InfluxId = createdTimeSeries.InfluxId;
                newTimeSeries.UserId   = createdTimeSeries.UserId;
                whenStatement.AddResultData(createdTimeSeries, BddKeyConstants.CreatedTimeSeries + testKey);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find new time-series in response",
                             whenStatement.GetType().Name);
            }

            return(whenStatement);
        }
예제 #2
0
        public static WhenStatement LoginRequestIsSend(this WhenStatement whenStatement, string testKey = null)
        {
            var loginCredentials = whenStatement.GetGivenData <TestLoginModel>(testKey);

            whenStatement.GetStatementLogger()
            .Information($"[{{ContextStatement}}] Logging in with {loginCredentials}",
                         whenStatement.GetType().Name);

            var response = _facade.PostLogin(loginCredentials);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse + testKey);
            try
            {
                var session = response.GetTokenFromResponse();

                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got session {session}", whenStatement.GetType().Name);

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

            return(whenStatement);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public static WhenStatement DeleteApiKeyRequestIsSend(this WhenStatement whenStatement, string testKey = null)
        {
            var apiKey = whenStatement.GetGivenData <string>(BddKeyConstants.ApiKeyToRemove + testKey);

            whenStatement.GetStatementLogger()
            .Information($"[{{ContextStatement}}] Removing api key '{apiKey}'",
                         whenStatement.GetType().Name);

            var response = _facade.DeleteApiKey(whenStatement.GetSessionFromData(testKey), apiKey);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse);

            return(whenStatement);
        }
예제 #5
0
        public static WhenStatement CreateNewApiKeyRequestIsSend(this WhenStatement whenStatement,
                                                                 string testKey = null)
        {
            var apiKey = whenStatement.GetGivenData <TestUserApiKeyJsonEntity>(BddKeyConstants.NewApiKey + testKey);

            whenStatement.GetStatementLogger()
            .Information($"[{{ContextStatement}}] Creating new api key '{apiKey}'",
                         whenStatement.GetType().Name);

            var response = _facade.PostApiKeys(whenStatement.GetSessionFromData(testKey), apiKey);

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse);

            return(whenStatement);
        }
예제 #6
0
        public static WhenStatement UpdateGivenUpdateTimeSeriesIdsFromModel(this WhenStatement whenStatement, TestTimeSeriesMetadataModel model,
                                                                            string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Updating time-series update params Ids", whenStatement.GetType().Name);

            var session    = whenStatement.GetSessionFromData(testKey);
            var timeSeries =
                whenStatement.GetGivenData <TestTimeSeriesMetadataModel>(BddKeyConstants.TimeSeriesToUpdate + testKey);

            timeSeries.Id       = model.Id;
            timeSeries.InfluxId = model.InfluxId;
            timeSeries.UserId   = model.UserId;

            return(whenStatement);
        }
예제 #7
0
        public static WhenStatement UpdateTimeSeriesRequestIsSend(this WhenStatement whenStatement,
                                                                  string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Updating time-series", whenStatement.GetType().Name);

            var session    = whenStatement.GetSessionFromData(testKey);
            var timeSeries =
                whenStatement.GetGivenData <TestTimeSeriesMetadataModel>(BddKeyConstants.TimeSeriesToUpdate + testKey);

            var response = _facade.PostUpdateTimeSeries(session, timeSeries.Id, timeSeries);

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

            return(whenStatement);
        }
예제 #8
0
        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");
        }