public async void Create_ReturnRedirect() { var size = Context.Service.Count(); var service = new Service() { ServiceID = 3, UserID = "2", ServiceCategoryID = 1, ServiceName = "Limpeza de Chaminés", Description = "Limpeza de Chaminés de Manhã" }; var controller = new ServicesController(Context, UserManager); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await controller.Create(service); Assert.IsType <RedirectToActionResult>(result); //Confirmar UserServices var resultIndex = await controller.UserServices(1); var viewResultIndex = Assert.IsType <ViewResult>(resultIndex); var modelIndex = Assert.IsAssignableFrom <IEnumerable <Service> >(viewResultIndex.ViewData.Model); Assert.NotNull(modelIndex); Assert.Equal(size + 1, modelIndex.Count()); }
public void CreateServiceTestView() { var controller = new ServicesController(); var result = controller.Create() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("", result.ViewName); }
public async void Create_ReturnViewResult() { var controller = new ServicesController(Context, UserManager); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await controller.Create(false); Assert.IsType <ViewResult>(result); }
public void Create_Post_valid() { var sessionMock = new Mock <ISession>(); var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName); var createServiceModel = new CreateServiceModel(); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >())) .Returns(categories); var fileSystemMock = new Mock <IFileSystem>(); var geoCodingServicemMock = new Mock <IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Create/", UserName)); controller.SetUserInfo(); controller.Create(createServiceModel); nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand>())); }
public void Create_Get() { var sessionMock = new Mock <ISession>(); var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >())) .Returns(categories); var fileSystemMock = new Mock <IFileSystem>(); var geoCodingServicemMock = new Mock <IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Services/Create/", UserName)); controller.Create(); var actualCategories = (IList <GroupedSelectListItem>)controller.ViewData[ViewDataKeys.Categories]; Assert.AreEqual(3, actualCategories.Count); }
public void Create_Get() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>())) .Returns(categories); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Services/Create/", UserName)); controller.Create(); var actualCategories = (IList<GroupedSelectListItem>)controller.ViewData[ViewDataKeys.Categories]; Assert.AreEqual(3, actualCategories.Count); }
public void Create_Post_valid() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var createServiceModel = new CreateServiceModel(); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>())) .Returns(categories); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Create/", UserName)); controller.SetUserInfo(); controller.Create(createServiceModel); nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny<ICommand>())); }