public async Task <IActionResult> Delete(int id) { var model = new DeleteModel(_context); await model.OnGetAsync(id); return(View(model)); }
public async Task OnGet_MissingId_ReturnsNotFound() { var mockRepo = new Mock <IFacilityRepository>(); var pageModel = new DeleteModel(mockRepo.Object); var result = await pageModel.OnGetAsync(null).ConfigureAwait(false); result.Should().BeOfType <NotFoundResult>(); pageModel.Id.Should().Be(Guid.Empty); pageModel.FacilityDetail.ShouldBeNull(); }
public async Task OnGet_NonexistentId_ReturnsNotFound() { var mockRepo = new Mock <IFacilityRepository>(); mockRepo.Setup(l => l.GetFacilityAsync(It.IsAny <Guid>())) .ReturnsAsync((FacilityDetailDto)null) .Verifiable(); var pageModel = new DeleteModel(mockRepo.Object); var result = await pageModel.OnGetAsync(Guid.Empty).ConfigureAwait(false); result.Should().BeOfType <NotFoundResult>(); pageModel.Id.Should().Be(Guid.Empty); pageModel.FacilityDetail.ShouldBeNull(); }
public async Task OnGetAsync() { // Arrange var user = new User { Id = Guid.NewGuid() }; _userManager.Setup(x => x.FindByIdAsync($"{user.Id}")).ReturnsAsync(user); var delete = new DeleteModel(_userManager.Object); // Act var get = await delete.OnGetAsync(user.Id).ConfigureAwait(false); // Assert _userManager.Verify(x => x.FindByIdAsync($"{user.Id}"), Times.Once); Assert.Equal(user, delete.UserModel); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync() { // Arrange var role = new Role { Id = Guid.NewGuid() }; _roleManager.Setup(x => x.FindByIdAsync($"{role.Id}")).ReturnsAsync(role); var delete = new DeleteModel(_roleManager.Object, _userManager.Object); // Act var get = await delete.OnGetAsync(role.Id).ConfigureAwait(false); // Assert _roleManager.Verify(x => x.FindByIdAsync($"{role.Id}"), Times.Once); Assert.Equal(role, delete.Role); Assert.IsType <PageResult>(get); }
public async Task OnGet_PopulatesThePageModel() { var facilityId = RepositoryData.Facilities()[0].Id; var facility = ResourceHelper.GetFacilityDetail(facilityId); var mockRepo = new Mock <IFacilityRepository>(); mockRepo.Setup(l => l.GetFacilityAsync(It.IsAny <Guid>())) .ReturnsAsync(facility) .Verifiable(); var pageModel = new DeleteModel(mockRepo.Object); var result = await pageModel.OnGetAsync(facility.Id).ConfigureAwait(false); result.Should().BeOfType <PageResult>(); pageModel.Id.Should().Be(facility.Id); pageModel.FacilityDetail.Should().BeEquivalentTo(facility); }
public async Task OnGetAsync_InvalidId() { // Arrange var user = new User { Id = Guid.NewGuid() }; _userManager.Setup(x => x.FindByIdAsync($"{user.Id}")).ReturnsAsync(user); var delete = new DeleteModel(_userManager.Object); var id = Guid.Empty; // Act var get = await delete.OnGetAsync(id).ConfigureAwait(false); // Assert _userManager.Verify(x => x.FindByIdAsync($"{id}"), Times.Never); Assert.Null(delete.UserModel); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync_InvalidId() { // Arrange var identityResource = new IdentityResource { Id = Random.Next() }; var identityResources = new Mock <DbSet <IdentityResource> >(); identityResources.Setup(x => x.FindAsync(identityResource.Id)).ReturnsAsync(identityResource); var context = new Mock <IConfigurationDbContext>(); context.Setup(x => x.IdentityResources).Returns(identityResources.Object); var delete = new DeleteModel(context.Object); // Act var get = await delete.OnGetAsync(0).ConfigureAwait(false); // Assert identityResources.Verify(x => x.FindAsync(identityResource.Id), Times.Never); Assert.Null(delete.IdentityResource); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync() { // Arrange var apiResource = new ApiResource { Id = Random.Next() }; var apiResources = new Mock <DbSet <ApiResource> >(); apiResources.Setup(x => x.FindAsync(apiResource.Id)).ReturnsAsync(apiResource); var context = new Mock <IConfigurationDbContext>(); context.Setup(x => x.ApiResources).Returns(apiResources.Object); var delete = new DeleteModel(context.Object); // Act var get = await delete.OnGetAsync(apiResource.Id).ConfigureAwait(false); // Assert apiResources.Verify(x => x.FindAsync(apiResource.Id), Times.Once); Assert.Equal(apiResource, delete.ApiResource); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync_InvalidUserCode() { // Arrange var deviceFlowCode = new DeviceFlowCodes { UserCode = $"{Guid.NewGuid()}" }; var deviceFlowCodes = new Mock <DbSet <DeviceFlowCodes> >(); deviceFlowCodes.Setup(x => x.FindAsync(deviceFlowCode.UserCode)).ReturnsAsync(deviceFlowCode); var context = new Mock <IPersistedGrantDbContext>(); context.Setup(x => x.DeviceFlowCodes).Returns(deviceFlowCodes.Object); var delete = new DeleteModel(context.Object); // Act var get = await delete.OnGetAsync(string.Empty).ConfigureAwait(false); // Assert deviceFlowCodes.Verify(x => x.FindAsync(deviceFlowCode.UserCode), Times.Never); Assert.Null(delete.DeviceFlowCode); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync() { // Arrange var client = new Client { Id = Random.Next() }; var clients = new Mock <DbSet <Client> >(); clients.Setup(x => x.FindAsync(client.Id)).ReturnsAsync(client); var context = new Mock <IConfigurationDbContext>(); context.Setup(x => x.Clients).Returns(clients.Object); var delete = new DeleteModel(context.Object); // Act var get = await delete.OnGetAsync(client.Id).ConfigureAwait(false); // Assert clients.Verify(x => x.FindAsync(client.Id), Times.Once); Assert.Equal(client, delete.Client); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync_InvalidKey() { // Arrange var persistedGrant = new PersistedGrant { Key = $"{Guid.NewGuid()}" }; var persistedGrants = new Mock <DbSet <PersistedGrant> >(); persistedGrants.Setup(x => x.FindAsync(persistedGrant.Key)).ReturnsAsync(persistedGrant); var context = new Mock <IPersistedGrantDbContext>(); context.Setup(x => x.PersistedGrants).Returns(persistedGrants.Object); var delete = new DeleteModel(context.Object); // Act var get = await delete.OnGetAsync(string.Empty).ConfigureAwait(false); // Assert persistedGrants.Verify(x => x.FindAsync(persistedGrant.Key), Times.Never); Assert.Null(delete.PersistedGrant); Assert.IsType <NotFoundResult>(get); }