public async Task OnGetAsync_InvalidId() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidId)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; var role = new Role { Id = Guid.NewGuid() }; using (var context = new OidcDbContext(options)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } RolesModel model; IActionResult get; // Act using (var context = new OidcDbContext(options)) { _userManager.Setup(x => x.Users).Returns(context.Users); model = new RolesModel(_userManager.Object); get = await model.OnGetAsync(Guid.Empty).ConfigureAwait(false); } // Assert Assert.Null(model.UserModel); Assert.Null(model.Roles); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var user = new User(); var id = Guid.NewGuid(); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(user); await context.SaveChangesAsync().ConfigureAwait(false); } RolesModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _userManager.Setup(x => x.Users).Returns(context.Users); model = new RolesModel(_userManager.Object, _roleManager.Object); get = await model.OnGetAsync(id).ConfigureAwait(false); } // Assert Assert.Null(model.UserModel); Assert.Null(model.Roles); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; var user = new User { UserRoles = new List <UserRole> { new UserRole { Role = new Role() }, new UserRole { Role = new Role() }, new UserRole { Role = new Role() } } }; using (var context = new OidcDbContext(options)) { context.Add(user); await context.SaveChangesAsync().ConfigureAwait(false); var rolesList = await context.Roles.ToListAsync().ConfigureAwait(false); _roleManager.Setup(x => x.Roles).Returns(rolesList.AsQueryable()); } RolesModel model; IActionResult get; // Act using (var context = new OidcDbContext(options)) { _userManager.Setup(x => x.Users).Returns(context.Users); model = new RolesModel(_userManager.Object, _roleManager.Object); get = await model.OnGetAsync(user.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.UserModel); Assert.Equal(user.Id, model.UserModel.Id); var roles = Assert.IsAssignableFrom <IEnumerable <Role> >(model.Roles); Assert.Equal(user.UserRoles.Count, roles.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var user = new User { Id = Guid.NewGuid() }; user.UserRoles.Add(new UserRole { Role = new Role() }); user.UserRoles.Add(new UserRole { Role = new Role() }); user.UserRoles.Add(new UserRole { Role = new Role() }); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(user); await context.SaveChangesAsync().ConfigureAwait(false); } RolesModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _userManager.Setup(x => x.Users).Returns(context.Users); model = new RolesModel(_userManager.Object); get = await model.OnGetAsync(user.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.UserModel); Assert.Equal(user.Id, model.UserModel.Id); var roles = Assert.IsAssignableFrom <IEnumerable <Role> >(model.Roles); Assert.Equal(user.UserRoles.Count, roles.Count()); Assert.IsType <PageResult>(get); }