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