public async Task Post_Create_Model_Not_Valid() { // Arrange var roleViewModel = new RoleViewModel { //Name ="admin" }; var validator = new ModelValidator <RoleViewModel>(roleViewModel); var service = Substitute.For <IRoleService>(); var mapper = Substitute.For <IMapper>(); var controller = new RoleManageController(service, mapper); // Act var valid = validator.IsValid(); validator.AddToModelError(controller); var result = await controller.Create(roleViewModel) as ViewResult; var viewName = result.ViewName; var model = result.Model; // Assert Assert.That(valid, Is.False); Assert.That(result, !Is.Null); Assert.That(model, !Is.Null); Assert.That("Create", Is.EqualTo(viewName)); }
public async Task Post_Create_Model_Is_Valid() { // Arrange string id = Guid.NewGuid().ToString(); var roleViewModel = new RoleViewModel() { Id = id, Name = "admin" }; var validator = new ModelValidator <RoleViewModel>(roleViewModel); var service = Substitute.For <IRoleService>(); var mapper = Substitute.For <IMapper>(); var controller = new RoleManageController(service, mapper); await service.CreateRoleAsync(roleViewModel.Name); // Act var valid = validator.IsValid(); validator.AddToModelError(controller); var result = await controller.Create(roleViewModel) 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(valid, Is.True); Assert.That("Index", Is.EqualTo(actionName)); Assert.That("UserManage", Is.EqualTo(controllerName)); Assert.That("admin", Is.EqualTo(areaName)); }
public void Get_Create() { // Arrange var mapper = Substitute.For <IMapper>(); var service = Substitute.For <IRoleService>(); var controller = new RoleManageController(service, mapper); // Act var result = controller.Create() as ViewResult; var viewName = result.ViewName; // Assert Assert.That("Create", Is.EqualTo(viewName)); }