public async Task OnGetAsync_InvalidId() { // Arrange var model = new SecretsModel(new Mock <IConfigurationDbContext>().Object); // Act var get = await model.OnGetAsync(0).ConfigureAwait(false); // Assert Assert.Null(model.ApiResource); Assert.Null(model.Secrets); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; var apiResource = new ApiResource { Id = Random.Next(), Secrets = new List <ApiSecret> { new ApiSecret(), new ApiSecret(), new ApiSecret() } }; SecretsModel model; IActionResult get; using (var context = new OidcDbContext(options)) { context.Add(apiResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { model = new SecretsModel(context); get = await model.OnGetAsync(apiResource.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.ApiResource); Assert.Equal(apiResource.Id, model.ApiResource.Id); var secrets = Assert.IsAssignableFrom <IEnumerable <ApiSecret> >(model.Secrets); Assert.Equal(apiResource.Secrets.Count, secrets.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var client = new Client { Id = Random.Next(), ClientSecrets = new List <ClientSecret> { new ClientSecret(), new ClientSecret(), new ClientSecret() } }; SecretsModel model; IActionResult get; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new SecretsModel(context); get = await model.OnGetAsync(client.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.Client); Assert.Equal(client.Id, model.Client.Id); var secrets = Assert.IsAssignableFrom <IEnumerable <ClientSecret> >(model.Secrets); Assert.Equal(client.ClientSecrets.Count, secrets.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; SecretsModel model; IActionResult get; // Act using (var context = new OidcDbContext(options)) { model = new SecretsModel(context); get = await model.OnGetAsync(Random.Next()).ConfigureAwait(false); } // Assert Assert.Null(model.ApiResource); Assert.Null(model.Secrets); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; SecretsModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new SecretsModel(context); get = await model.OnGetAsync(Random.Next()).ConfigureAwait(false); } // Assert Assert.Null(model.Client); Assert.Null(model.Secrets); Assert.IsType <NotFoundResult>(get); }