public void GET_Edit_RedirectsToHome_When_IdNotFound() { var queryRoles = MockRepository.GenerateMock<IQueryService<Role>>(); queryRoles.Expect(c => c.Load(Arg<Guid>.Is.Anything)).IgnoreArguments().Return(null); var roleManager = new RoleManagerController(); roleManager.EditOutputModel = new RoleManagerEditOutput(queryRoles, null); var result = roleManager.Edit( Guid.Parse("CF6C6EDA-F16B-11DF-A057-E112E0D72085") ); Assert.IsInstanceOf<RedirectToRouteResult>(result); var redirect2Root = result as RedirectToRouteResult; Assert.AreEqual("Index", redirect2Root.RouteValues["action"]); Assert.AreEqual("Home", redirect2Root.RouteValues["controller"]); }
public void GET_Edit_Loads_Role_By_Id() { var fakeRole = MockRepository.GenerateMock<Role>(); fakeRole.Expect(f => f.Description).Return("The glorious role"); fakeRole.Expect(f => f.Name).Return("glorious"); fakeRole.Expect(f => f.Id).Return(Guid.Parse("CF6C6EDA-F16B-11DF-A057-E112E0D72085")); fakeRole.Expect(f => f.Functions).Return(new Permission[] { }); var roleManager = new RoleManagerController(); var builder = new TestControllerBuilder(); builder.InitializeController(roleManager); var queryRoles = MockRepository.GenerateMock<IQueryService<Role>>(); queryRoles.Expect(q => q.Load(fakeRole.Id)).Return(fakeRole); var queryFunctions = MockRepository.GenerateMock<IQueryService<Permission>>(); queryFunctions.Expect(q=>q.Query()).Return(new Permission[]{}.AsQueryable()); var queryFunction = MockRepository.GenerateMock<IQueryService<Permission>>(); queryFunction.Expect(f => f.Query()).Return(new Permission[] { }.AsQueryable()); // setup dependencies roleManager.EditOutputModel = new RoleManagerEditOutput(queryRoles, queryFunctions ); // Act var result = roleManager.Edit(fakeRole.Id); // Assert queryRoles.VerifyAllExpectations(); queryFunctions.VerifyAllExpectations(); Assert.IsInstanceOf<ViewResult>(result); var viewResult = result as ViewResult; Assert.IsInstanceOf<RoleManagerEditOutput>(viewResult.ViewData.Model); var model = viewResult.ViewData.Model as RoleManagerEditOutput; Assert.AreEqual(model.Role, fakeRole); }
public void GET_Edit_RedirectsToHome_WhenNoId_IsSupplied() { var roleManager = new RoleManagerController(); var result = roleManager.Edit(Guid.Empty); Assert.IsInstanceOf<RedirectToRouteResult>(result); var redirect2Root = result as RedirectToRouteResult; Assert.AreEqual("Index", redirect2Root.RouteValues["action"]); Assert.AreEqual("Home", redirect2Root.RouteValues["controller"]); }