public async Task OnPostAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; IActionResult post; var identityResource = new IdentityResource { Id = Random.Next() }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(identityResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { var properties = new PropertiesModel(context) { IdentityResource = new IdentityResource { Id = Random.Next() } }; post = await properties.OnPostAsync().ConfigureAwait(false); } // Assert Assert.IsType <PageResult>(post); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; PropertiesModel properties; IActionResult post; var identityResourceId = Random.Next(); var identityResource = new IdentityResource { Id = identityResourceId, Properties = new List <IdentityResourceProperty> { new IdentityResourceProperty { Id = Random.Next() } } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(identityResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { properties = new PropertiesModel(context) { IdentityResource = new IdentityResource { Id = identityResourceId } }; post = await properties.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { identityResource = await context.IdentityResources .Include(x => x.Properties) .SingleOrDefaultAsync(x => x.Id.Equals(identityResourceId)) .ConfigureAwait(false); Assert.Empty(identityResource.Properties); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Properties", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(IdentityResource.Id), key); Assert.Equal(properties.IdentityResource.Id, value); }); }
public async Task OnPostAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; IActionResult post; var client = new Client { Id = Random.Next() }; using (var context = new OidcDbContext(options)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { var properties = new PropertiesModel(context) { Client = new Client { Id = Random.Next() } }; post = await properties.OnPostAsync().ConfigureAwait(false); } // Assert Assert.IsType <PageResult>(post); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; PropertiesModel properties; IActionResult post; var client = new Client { Id = Random.Next(), Properties = new List <ClientProperty> { new ClientProperty { Id = Random.Next() } } }; using (var context = new OidcDbContext(options)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { properties = new PropertiesModel(context) { Client = new Client { Id = client.Id } }; post = await properties.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new OidcDbContext(options)) { client = await context.Clients .Include(x => x.Properties) .SingleOrDefaultAsync(x => x.Id.Equals(client.Id)) .ConfigureAwait(false); Assert.Empty(client.Properties); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Properties", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Client.Id), key); Assert.Equal(properties.Client.Id, value); }); }
public async Task OnPostAsync_InvalidId() { // Arrange var context = new Mock <IConfigurationDbContext>(); var properties = new PropertiesModel(context.Object) { IdentityResource = new IdentityResource { Id = 0 } }; // Act var post = await properties.OnPostAsync().ConfigureAwait(false); // Assert context.Verify(x => x.SaveChangesAsync(), Times.Never); Assert.IsType <PageResult>(post); }
public async Task OnPostAsync() { // Arrange const string property1OriginalValue = "Original Value"; const string property1EditedValue = "Edited Value"; const string newPropertyValue = "New Value"; var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; PropertiesModel properties; IActionResult post; var property1 = new IdentityResourceProperty { Id = Random.Next(), Value = property1OriginalValue }; var property2 = new IdentityResourceProperty { Id = Random.Next() }; var identityResourceId = Random.Next(); var identityResource = new IdentityResource { Id = identityResourceId, Properties = new List <IdentityResourceProperty> { property1, property2 } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(identityResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { properties = new PropertiesModel(context) { IdentityResource = new IdentityResource { Id = identityResourceId, Properties = new List <IdentityResourceProperty> { new IdentityResourceProperty { Id = property1.Id, Value = property1EditedValue }, new IdentityResourceProperty { Value = newPropertyValue } } } }; post = await properties.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { identityResource = await context.IdentityResources .Include(x => x.Properties) .SingleOrDefaultAsync(x => x.Id.Equals(identityResourceId)) .ConfigureAwait(false); property1 = identityResource.Properties.SingleOrDefault(x => x.Id.Equals(property1.Id)); property2 = identityResource.Properties.SingleOrDefault(x => x.Id.Equals(property2.Id)); var newProperty = identityResource.Properties.SingleOrDefault(x => x.Value.Equals(newPropertyValue)); Assert.NotNull(property1); Assert.Equal(property1EditedValue, property1.Value); Assert.Null(property2); Assert.NotNull(newProperty); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Properties", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(IdentityResource.Id), key); Assert.Equal(properties.IdentityResource.Id, value); }); }