public async Task ShouldAddNewApi() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); _database.ApiResources.FirstOrDefault(s => s.Name == command.Name).Should().NotBeNull(); }
public async Task ShouldNotAddNewApiSecretWhenClientDoesntExist() { var command = ApiResourceFaker.GenerateApiResource().Generate(); var secret = ApiResourceFaker.GenerateSaveClientSecret(command.Name).Generate(); var result = await _apiResourceAppService.SaveSecret(secret); _notifications.GetNotifications().Select(s => s.Value).ToList().ForEach(_output.WriteLine); _database.ApiSecrets.Include(i => i.ApiResource).Where(f => f.ApiResource.Name == command.Name).Should().NotBeNull(); result.Should().BeFalse(); }
public async Task ShouldNotAddAnotherApiWithSameName() { var command = ApiResourceFaker.GenerateApiResource().Generate(); var firstCall = await _apiResourceAppService.Save(command); var result = await _apiResourceAppService.Save(command); _notifications.GetNotifications().Select(s => s.Value).ToList().ForEach(_output.WriteLine); firstCall.Should().BeTrue(); result.Should().BeFalse(); }
public async Task ShouldApiResourceHaveAtLeastOneScope() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); var api = _database.ApiResources.FirstOrDefault(s => s.Name == command.Name); api.Should().NotBeNull(); api.Scopes.Should().HaveCountGreaterOrEqualTo(1); api.Scopes.Should().Contain(a => a.Name == api.Name); }
public async Task Should_Remove_Api() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); _database.ApiResources.FirstOrDefault(s => s.Name == command.Name).Should().NotBeNull(); await _apiResourceAppService.Remove(new RemoveApiResourceViewModel(command.Name)); _database.ApiResources.FirstOrDefault(s => s.Name == command.Name).Should().BeNull(); }
public async Task Should_ApiResource_Have_At_Least_One_Scope_With_His_Name_When_Register() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); var api = _database.ApiResources.FirstOrDefault(s => s.Name == command.Name); api.Should().NotBeNull(); api.Scopes.Should().HaveCountGreaterOrEqualTo(1); api.Scopes.Should().Contain(a => a.Name == api.Name); }
public async Task ShouldAddNewApiScope() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); var scope = ApiResourceFaker.GenerateSaveScopeViewModer(command.Name).Generate(); await _apiResourceAppService.SaveScope(scope); _database.ApiResources.FirstOrDefault(f => f.Name == command.Name).Should().NotBeNull(); _database.ApiScopes.Include(i => i.ApiResource).Where(f => f.ApiResource.Name == command.Name).Should().NotBeNull(); }
public async Task ShouldAddNewApiSecret() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); var secret = ApiResourceFaker.GenerateSaveClientSecret(command.Name); await _apiResourceAppService.SaveSecret(secret); _database.ApiResources.FirstOrDefault(f => f.Name == command.Name).Should().NotBeNull(); _database.ApiSecrets.Include(i => i.ApiResource).Where(f => f.ApiResource.Name == command.Name).Should().NotBeNull(); }
public async Task ShouldAddIdentityResources() { await Login(); _client.SetBearerToken(_token.AccessToken); var command = ApiResourceFaker.GenerateApiResource().Generate(); var response = await _client.PostAsync("/api-resources", new StringContent(command.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); response.Headers.Location.PathAndQuery.Should().Contain("/api-resources"); }
public async Task Should_Add_New_ApiSecret_Without_Description() { var command = ApiResourceFaker.GenerateApiResource(name: "teste", addApiSecrets: false).Generate(); await _apiResourceAppService.Save(command); var secret = ApiResourceFaker.GenerateSaveClientSecret(command.Name, HashType.Sha256, type: "SharedSecret").Generate(); secret.Description = null; secret.Expiration = null; await _apiResourceAppService.SaveSecret(secret); _database.ApiResources.FirstOrDefault(f => f.Name == command.Name).Should().NotBeNull(); _database.ApiSecrets.Include(i => i.ApiResource).Where(f => f.ApiResource.Name == command.Name).Should().NotBeNull(); }
public async Task ShouldUpdateApi() { var command = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Save(command); var client = _database.ApiResources.FirstOrDefault(s => s.Name == command.Name); client.Should().NotBeNull(); InMemoryData.DetachAll(); var updateCommand = ApiResourceFaker.GenerateApiResource().Generate(); await _apiResourceAppService.Update(command.Name, updateCommand); _database.ApiResources.FirstOrDefault(f => f.Name == updateCommand.Name).Should().NotBeNull(); }
public async Task ShouldGetAllApiResources() { await Login(); _client.SetBearerToken(_token.AccessToken); var command = ApiResourceFaker.GenerateApiResource().Generate(); var response = await _client.PostAsync("/api-resources", new StringContent(command.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); response.Headers.Location.PathAndQuery.Should().Contain("/api-resources"); // Get content response = await _client.GetAsync("/api-resources"); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); var resources = content.FromJson <IEnumerable <ApiResourceListViewModel> >(); resources.Should().HaveCountGreaterThan(0); }
public async Task ShouldHaveDefaultScope() { await Login(); _client.SetBearerToken(_token.AccessToken); var command = ApiResourceFaker.GenerateApiResource().Generate(); var response = await _client.PostAsync("/api-resources", new StringContent(command.ToJson(), Encoding.UTF8, MediaTypeNames.Application.Json)); response.EnsureSuccessStatusCode(); response.Headers.Location.PathAndQuery.Should().Contain("/api-resources"); // Get content response = await _client.GetAsync($"/api-resources/{command.Name}/scopes"); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); var scope = content.FromJson <IEnumerable <Scope> >(); scope.Should().HaveCountGreaterOrEqualTo(1); }