コード例 #1
0
 public static ThenStatement LogoutIfSessionTokenIsPresent(this ThenStatement thenStatement,
                                                           string testKey = null)
 {
     try
     {
         thenStatement.GetStatementLogger()
         .Information(
             "[{ContextStatement}] Trying to logout" + (testKey != null ? $" with test key {testKey}" : ""),
             thenStatement.GetType().Name);
         var session = thenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey);
         _facade.PostLogout(session).AssertSuccess();
     }
     catch (KeyNotFoundException e)
     {
         thenStatement.GetStatementLogger()
         .Warning($"[{{ContextStatement}}] Could not find session token in 'When' results dictionary. {e}",
                  thenStatement.GetType().Name);
     }
     catch (Exception e)
     {
         thenStatement.GetStatementLogger()
         .Warning($"[{{ContextStatement}}] An error occured during logout. {e}",
                  thenStatement.GetType().Name);
     }
     return(thenStatement);
 }
コード例 #2
0
        public static ThenStatement SessionTokenIsPresent(this ThenStatement thenStatement, string testKey = null)
        {
            thenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Looking for session token in the 'When' dictionary",
                         thenStatement.GetType().Name);

            Assert.That(thenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey), Is.Not.Empty,
                        "Expected to have session token, but found none.");

            return(thenStatement);
        }
コード例 #3
0
        public static ThenStatement SessionTokenIsInvalid(this ThenStatement thenStatement, string testKey = null)
        {
            thenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Looking for session token in the 'When' dictionary",
                         thenStatement.GetType().Name);

            var session = thenStatement.GetResultData <string>(BddKeyConstants.SessionTokenKey + testKey);

            _facade.GetMe(session).AssertError(HttpStatusCode.Unauthorized);

            return(thenStatement);
        }
コード例 #4
0
        public static ThenStatement CurrentUserIsEqualTo(this ThenStatement thenStatement, TestUserModel expectedUser)
        {
            thenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Comparing 'GetMe' response with expected user model",
                         thenStatement.GetType().Name);

            var currentUser = thenStatement.GetResultData <TestUserModel>(BddKeyConstants.CurrentUserResponse);

            Assert.IsEmpty(ProfileHelper.CompareUserProfiles(expectedUser, currentUser));

            return(thenStatement);
        }
コード例 #5
0
        public static ThenStatement UsersApiKeysDoNotContainGiven(this ThenStatement thenStatement, string testKey = null)
        {
            thenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Looking for given apiKey in the 'When' dictionary",
                         thenStatement.GetType().Name);

            var givenApiKeyId = thenStatement.GetGivenData <string>(BddKeyConstants.ApiKeyToRemove + testKey);
            var userApiKeys   = thenStatement.GetResultData <TestApiKeysList>(BddKeyConstants.UserApiKeys + testKey);

            Assert.False(userApiKeys.Entities.Select(e => e.Id).Contains(givenApiKeyId), $"Expected '{givenApiKeyId}' api key to be absent in user keys.");

            return(thenStatement);
        }
コード例 #6
0
        public static ThenStatement UsersApiKeysContainGiven(this ThenStatement thenStatement, string testKey = null)
        {
            thenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Looking for given apiKey in the 'When' dictionary",
                         thenStatement.GetType().Name);

            var givenApiKey = thenStatement.GetGivenData <TestUserApiKeyJsonEntity>(BddKeyConstants.NewApiKey + testKey);
            var userApiKeys = thenStatement.GetResultData <TestApiKeysList>(BddKeyConstants.UserApiKeys + testKey);

            Assert.That(userApiKeys.Entities.Select(e => e.Description), Contains.Item(givenApiKey.Description));

            return(thenStatement);
        }
コード例 #7
0
        public static ThenStatement CurrentUserIsEqualToExpected(this ThenStatement thenStatement)
        {
            thenStatement.GetStatementLogger()
            .Information("[{ContextStatement}] Comparing given user credentials with response from 'GetMe'",
                         thenStatement.GetType().Name);

            var currentUser  = thenStatement.GetResultData <TestUserModel>(BddKeyConstants.CurrentUserResponse);
            var expectedUser = thenStatement.GetGivenData <TestLoginModel>();

            Assert.That(currentUser.Email, Is.EqualTo(expectedUser.Email));
            Assert.That(currentUser.Password, Is.Null, "Expected user password to be hidden");
            Assert.That(currentUser.Id, Is.Not.Null, "Expected current user to have any Id");

            return(thenStatement);
        }
コード例 #8
0
        public static ThenStatement TimeSeriesIsNotPresentInUserTimeSeries(this ThenStatement thenStatement,
                                                                           TestTimeSeriesMetadataModel expected,
                                                                           string testKey = null)
        {
            List <TestTimeSeriesMetadataModel> actual = null;

            try
            {
                actual =
                    thenStatement.GetResultData <List <TestTimeSeriesMetadataModel> >(
                        BddKeyConstants.UserTimeSeries + testKey);
            }
            catch (KeyNotFoundException e)
            {
                Assert.Fail("Was unable to get user time-series due to request failure.");
            }

            Assert.That(!actual.Any(model => Equals(model, expected)), $"Expected {expected} to be removed from user time-series");

            return(thenStatement);
        }
コード例 #9
0
        public static ThenStatement TimeSeriesIsPresentInUserTimeSeries(this ThenStatement thenStatement,
                                                                        TestTimeSeriesMetadataModel expected,
                                                                        string testKey = null)
        {
            List <TestTimeSeriesMetadataModel> actual = null;

            try
            {
                actual =
                    thenStatement.GetResultData <List <TestTimeSeriesMetadataModel> >(
                        BddKeyConstants.UserTimeSeries + testKey);
            }
            catch (KeyNotFoundException e)
            {
                Assert.Fail("Was unable to get user time-series due to request failure.");
            }

            Assert.Contains(expected, actual);

            return(thenStatement);
        }
コード例 #10
0
        public static ThenStatement TimeSeriesByIdIsEqualTo(this ThenStatement thenStatement,
                                                            TestTimeSeriesMetadataModel expected,
                                                            string testKey = null)
        {
            TestTimeSeriesMetadataModel actual = null;

            try
            {
                actual =
                    thenStatement.GetResultData <TestTimeSeriesMetadataModel>(
                        BddKeyConstants.UserTimeSeriesById + testKey);
            }
            catch (KeyNotFoundException e)
            {
                Assert.Fail("Was unable to get user time-series due to request failure.");
            }

            Assert.That(actual, Is.EqualTo(expected));

            return(thenStatement);
        }
コード例 #11
0
        public static ThenStatement CreatedTimeSeriesIsEqualToExpected(this ThenStatement thenStatement,
                                                                       string testKey = null)
        {
            var expected =
                thenStatement.GetGivenData <TestTimeSeriesMetadataModel>(BddKeyConstants.TimeSeriesToCreate + testKey);

            TestTimeSeriesMetadataModel actual = null;

            try
            {
                actual =
                    thenStatement.GetResultData <TestTimeSeriesMetadataModel>(
                        BddKeyConstants.CreatedTimeSeries + testKey);
            }
            catch (KeyNotFoundException e)
            {
                Assert.Fail("Was unable to get created time-series due to request failure.");
            }

            var currentUser =
                _profileApiFacade.GetMe(thenStatement.GetGivenData <string>(BddKeyConstants.SessionTokenKey + testKey))
                .Map <TestUserModel>();

            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(actual.DateCreated, Is.Not.Empty);
            Assert.That(actual.InfluxId, Is.Not.Empty);
            Assert.That(actual.UserId, Is.EqualTo(currentUser.Id));

            try
            {
                var creationTime = DateTimeOffset.Parse(actual.DateCreated);
                Assert.That(DateTimeOffset.UtcNow - creationTime, Is.LessThan(TimeSpan.FromHours(1)));
            }
            catch
            {
                Assert.Fail($"Could not parse createdDate {actual.DateCreated}");
            }

            return(thenStatement);
        }