public async Task CanRetrieveOnlyEnabledTokens() { var enabledToken = AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(true, DatabaseContext); AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(false, DatabaseContext); //add disabled token var expectedResponse = new TokensListResponse() { Tokens = new List <AuthToken>() { enabledToken } }; var url = new Uri($"/api/v1/tokens?enabled=true", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var data = await response.Content.ReadAsStringAsync().ConfigureAwait(true); var tokens = JsonConvert.DeserializeObject <TokensListResponse>(data); tokens.Tokens.Count.Should().Be(1); tokens.Should().BeEquivalentTo(expectedResponse); }
public void ShouldGetAllTokensFromDatabase() { var token = AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(null, DatabaseContext); var disabledToken = AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(false, DatabaseContext); var result = _classUnderTest.GetAllTokens(10, 0, null); result.Should().NotBeNull(); result.Count.Should().Be(2); result.Find(x => x.Id == token.Id).ApiEndpointName.Should().Be(token.ApiEndpointName); result.Find(x => x.Id == token.Id).ApiName.Should().Be(token.ApiName); result.Find(x => x.Id == token.Id).ConsumerName.Should().Be(token.ConsumerName); result.Find(x => x.Id == token.Id).ConsumerType.Should().Be(token.ConsumerType); result.Find(x => x.Id == token.Id).Enabled.Should().Be(token.Enabled); result.Find(x => x.Id == token.Id).Environment.Should().Be(token.Environment); result.Find(x => x.Id == token.Id).ExpirationDate.Should().Be(token.ExpirationDate); result.Find(x => x.Id == token.Id).HttpMethodType.Should().Be(token.HttpMethodType); result.Find(x => x.Id == token.Id).Id.Should().Be(token.Id); result.Find(x => x.Id == disabledToken.Id).ApiEndpointName.Should().Be(disabledToken.ApiEndpointName); result.Find(x => x.Id == disabledToken.Id).ApiName.Should().Be(disabledToken.ApiName); result.Find(x => x.Id == disabledToken.Id).ConsumerName.Should().Be(disabledToken.ConsumerName); result.Find(x => x.Id == disabledToken.Id).ConsumerType.Should().Be(disabledToken.ConsumerType); result.Find(x => x.Id == disabledToken.Id).Enabled.Should().Be(disabledToken.Enabled); result.Find(x => x.Id == disabledToken.Id).Environment.Should().Be(disabledToken.Environment); result.Find(x => x.Id == disabledToken.Id).ExpirationDate.Should().Be(disabledToken.ExpirationDate); result.Find(x => x.Id == disabledToken.Id).HttpMethodType.Should().Be(disabledToken.HttpMethodType); result.Find(x => x.Id == disabledToken.Id).Id.Should().Be(disabledToken.Id); }
public void ShouldGetOnlyDisabledTokensFromDatabase() { AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(true, DatabaseContext); AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(false, DatabaseContext); var result = _classUnderTest.GetAllTokens(10, 0, false); result.Should().NotBeNull(); result.Count.Should().Be(1); }
public void CanGetADatabaseEntity() { var databaseEntity = AuthTokenDatabaseEntityHelper.CreateDatabaseEntity(DatabaseContext); DatabaseContext.Add(databaseEntity); DatabaseContext.SaveChanges(); var result = DatabaseContext.Tokens.ToList().FirstOrDefault(); result.Should().Be(databaseEntity); }
public void CanGetADatabaseEntity() { //remove any record that might be left in the table DatabaseContext.RemoveRange(DatabaseContext.Tokens); var databaseEntity = AuthTokenDatabaseEntityHelper.CreateDatabaseEntity(); DatabaseContext.Add(databaseEntity); DatabaseContext.SaveChanges(); var result = DatabaseContext.Tokens.ToList().FirstOrDefault(); result.Should().Be(databaseEntity); }
public async Task GettingTokensWithNoCursorAndLimitShouldReturnDefaultLimitAndNextCursor() { var addMultipleTokensToDb = Enumerable.Range(0, 25) .Select(x => AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(false, DatabaseContext, x + 1)) .ToList(); var url = new Uri($"/api/v1/tokens?enabled=false", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var data = await response.Content.ReadAsStringAsync().ConfigureAwait(true); var tokens = JsonConvert.DeserializeObject <TokensListResponse>(data); tokens.Tokens.Count.Should().Be(20); tokens.Tokens.Should().BeEquivalentTo(addMultipleTokensToDb.Take(20)); tokens.NextCursor.Should().Be("20"); }
public async Task IfManyTokensInDbAndLimitAndCursorIsSuppliedShouldReturnCorrectSetOfTokens() { var addMultipleTokensToDb = Enumerable.Range(0, 35) //insert multiple tokens that will require a 'NextCursor' to be returned .Select(x => AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(false, DatabaseContext, x + 1)) .ToList(); var url = new Uri($"/api/v1/tokens?limit=11&cursor=11", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var data = await response.Content.ReadAsStringAsync().ConfigureAwait(true); var tokens = JsonConvert.DeserializeObject <TokensListResponse>(data); tokens.Tokens.Count.Should().Be(11); tokens.Tokens.Should().BeEquivalentTo(addMultipleTokensToDb.Skip(11).Take(11)); tokens.NextCursor.Should().Be("22"); }
public async Task IfNumberOfTokensInDbIsLessThanMaxLimitNextCursorShouldBeNull() { var addMultipleTokensToDb = Enumerable.Range(0, 10) .Select(x => AuthTokenDatabaseEntityHelper.AddTokenRecordToTheDatabase(false, DatabaseContext, x + 1)) .ToList(); var url = new Uri($"/api/v1/tokens?enabled=false", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var data = await response.Content.ReadAsStringAsync().ConfigureAwait(true); var tokens = JsonConvert.DeserializeObject <TokensListResponse>(data); tokens.Tokens.Count.Should().Be(10); tokens.Tokens.Should().BeEquivalentTo(addMultipleTokensToDb); tokens.NextCursor.Should().Be(null); }