Esempio n. 1
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;
            }
        }
        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);
        }