public async Task Good_Delete() { // Arrange string id = Guid.NewGuid().ToString(); var role = new IdentityRole() { Id = id, Name = "admin" }; var service = Substitute.For <IRoleService>(); var mapper = Substitute.For <IMapper>(); var controller = new RoleManageController(service, mapper); service.FindByIdAsync(id).Returns(Task.FromResult(role)); await service.DeleteRoleAcync(role); // Act var result = await controller.Delete(id) as RedirectToRouteResult; var areaName = result.RouteValues.Values.ElementAt(0); var actionName = result.RouteValues.Values.ElementAt(1); var controllerName = result.RouteValues.Values.ElementAt(2); // Assert Assert.That(result, !Is.Null); Assert.That("Index", Is.EqualTo(actionName)); Assert.That("UserManage", Is.EqualTo(controllerName)); Assert.That("admin", Is.EqualTo(areaName)); }
public async Task Delete_Id_Is_Null() { // Arrange string id = string.Empty; var service = Substitute.For <IRoleService>(); var mapper = Substitute.For <IMapper>(); var controller = new RoleManageController(service, mapper); // Act var result = await controller.Delete(id) as HttpStatusCodeResult; var statusCode = result.StatusCode; // Assert Assert.That(result, !Is.Null); Assert.That(400, Is.EqualTo(statusCode)); }
public async Task Delete_Role_Is_Null() { // Arrange string id = "hkddkj"; IdentityRole role = null; var service = Substitute.For <IRoleService>(); var mapper = Substitute.For <IMapper>(); var controller = new RoleManageController(service, mapper); service.FindByIdAsync(id).Returns(Task.FromResult(role)); // Act var result = await controller.Delete(id) as HttpNotFoundResult; var statusCode = result.StatusCode; // Assert Assert.That(result, !Is.Null); Assert.That(404, Is.EqualTo(statusCode)); }