예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public static WhenStatement GetTimeSeriesMetadataByIdRequestIsSend(this WhenStatement whenStatement, string timeSeriesId,
                                                                           string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Getting user time-series by id", whenStatement.GetType().Name);

            var session = whenStatement.GetSessionFromData(testKey);

            var response = _facade.GetTimeSeriesMetadataById(session, timeSeriesId);

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

            try
            {
                var timeSeries = response.Map <TestTimeSeriesMetadataModel>();
                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got time-series {timeSeries}",
                             whenStatement.GetType().Name);

                whenStatement.AddResultData(timeSeries, BddKeyConstants.UserTimeSeriesById + testKey);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find time-series in response",
                             whenStatement.GetType().Name);
            }
            return(whenStatement);
        }
예제 #5
0
        private static TestTimeSeriesMetadataModel GetTimeSeriesFromDatas(this WhenStatement whenStatement,
                                                                          string testKey = null)
        {
            try
            {
                return(whenStatement.GetResultData <TestTimeSeriesMetadataModel>(BddKeyConstants.CreatedTimeSeries +
                                                                                 testKey));
            }
            catch (Exception e)
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find time-series in response data",
                             whenStatement.GetType().Name);
            }

            try
            {
                return(whenStatement.GetResultData <TestTimeSeriesMetadataModel>(BddKeyConstants.LastHttpResponse +
                                                                                 testKey));
            }
            catch (Exception e)
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find time-series in last response data",
                             whenStatement.GetType().Name);
                throw;
            }
        }
예제 #6
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);
        }
예제 #7
0
        public static WhenStatement GetAllTimeSeriesRequestIsSend(this WhenStatement whenStatement,
                                                                  string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Getting all user time-series", whenStatement.GetType().Name);

            var session = whenStatement.GetSessionFromData(testKey);

            var response = _facade.GetAllTimeSeries(session);

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

            try
            {
                var createdTimeSeries = response.Map <List <TestTimeSeriesMetadataModel> >();
                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got time-series {createdTimeSeries}",
                             whenStatement.GetType().Name);

                whenStatement.AddResultData(createdTimeSeries, BddKeyConstants.UserTimeSeries + testKey);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find list of time-series in response",
                             whenStatement.GetType().Name);
            }
            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");
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        public static WhenStatement GetApiKeysRequestIsSend(this WhenStatement whenStatement, string testKey = null)
        {
            var response = _facade.GetApiKeys(whenStatement.GetSessionFromData(testKey));

            whenStatement.AddResultData(response, BddKeyConstants.LastHttpResponse);
            try
            {
                var apiKeys = response.Map <TestApiKeysList>();
                whenStatement.GetStatementLogger()
                .Information($"[{{ContextStatement}}] Got api keys {apiKeys}", whenStatement.GetType().Name);

                whenStatement.AddResultData(apiKeys, BddKeyConstants.UserApiKeys + testKey);
            }
            catch
            {
                whenStatement.GetStatementLogger()
                .Information("[{ContextStatement}] Could not find api keys in response",
                             whenStatement.GetType().Name);
            }

            return(whenStatement);
        }
예제 #12
0
        public static WhenStatement LogoutRequestIsSend(this WhenStatement whenStatement, string testKey = null)
        {
            var session = whenStatement.GetSessionFromData(testKey);

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

            var response = _facade.PostLogout(session);

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

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

            var session = whenStatement.GetSessionFromData(testKey);

            var response = _facade.DeleteTimeSeriesById(session, timeSeriesId);

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

            return(whenStatement);
        }
예제 #14
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);
        }
예제 #15
0
        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);
        }
예제 #16
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);
        }
예제 #17
0
        public static WhenStatement UploadTimeSeriesDataRequestIsSend(this WhenStatement whenStatement, string fileContent,
                                                                      string testKey = null)
        {
            whenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Uploading .csv data to time-series", whenStatement.GetType().Name);

            var session       = whenStatement.GetSessionFromData(testKey);
            var newTimeSeries = whenStatement.GetTimeSeriesFromDatas(testKey);

            var response = _facade.PostUploadTimeSeries(session, newTimeSeries.Id, fileContent);

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

            return(whenStatement);
        }
예제 #18
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);
        }
예제 #19
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);
        }