Esempio n. 1
0
        public async void Delete_ReturnServiceViewResult(int commentID)
        {
            var size    = Context.CommentAndEvaluation.Count();
            var comment = Context.CommentAndEvaluation.Find(commentID);


            var servicesController = new ServicesController(Context, UserManager);

            Controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = PrestadorLog
            };
            servicesController.ControllerContext.HttpContext = new DefaultHttpContext {
                User = PrestadorLog
            };

            var result = await Controller.Delete(commentID);

            Assert.IsType <ViewResult>(servicesController.Details(comment.ServiceID).Result);

            //Confirmar Index
            var resultIndex = await Controller.Index();

            var viewResultIndex = Assert.IsType <ViewResult>(resultIndex);
            var modelIndex      = Assert.IsAssignableFrom <IEnumerable <CommentAndEvaluation> >(viewResultIndex.ViewData.Model);

            Assert.NotNull(modelIndex);
            Assert.Equal(size - 1, modelIndex.Count());
        }
Esempio n. 2
0
        public async void Details_ReturnNotFound(int serviceID)
        {
            var controller = new ServicesController(Context, UserManager);

            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = ClientLog
            };
            var result = await controller.Details(serviceID);

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal("/Views/Shared/NotFound.cshtml", viewResult.ViewName);
        }
Esempio n. 3
0
        public async void Details_ReturnViewResult(int serviceID)
        {
            var controller = new ServicesController(Context, UserManager);

            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = PrestadorLog
            };
            var result = await controller.Details(serviceID);

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <Service>(viewResult.ViewData.Model);

            Assert.NotNull(model);
            Assert.Equal(serviceID, model.ServiceID);
        }
Esempio n. 4
0
        public void Details_Of_Nonexisting_Service()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, Service> >()))
            .Returns((Service)null);

            var controller = new ServicesController(nHbernateContextMock.Object, null, null);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/10", UserName));
            controller.SetUserInfo();

            var result = controller.Details(10);
            var view   = result as ViewResult;

            Assert.AreEqual("ServiceNotFound", view.ViewName);
        }
Esempio n. 5
0
        public void Details_Of_Existing_Service()
        {
            var service              = GetSampleServices()[0];
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, Service> >()))
            .Returns(service);

            var controller = new ServicesController(nHbernateContextMock.Object, null, null);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/1", UserName));
            controller.SetUserInfo();

            var result = controller.Details(1);

            Assert.AreEqual(service, controller.ViewData.Model);
        }
        public void Details_Of_Nonexisting_Service()
        {
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, Service>>()))
                .Returns((Service)null);

            var controller = new ServicesController(nHbernateContextMock.Object, null, null);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/10", UserName));
            controller.SetUserInfo();

            var result = controller.Details(10);
            var view = result as ViewResult;
            Assert.AreEqual("ServiceNotFound", view.ViewName);
        }
        public void Details_Of_Existing_Service()
        {
            var service = GetSampleServices()[0];
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, Service>>()))
                .Returns(service);

            var controller = new ServicesController(nHbernateContextMock.Object, null, null);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/1", UserName));
            controller.SetUserInfo();

            var result = controller.Details(1);
            Assert.AreEqual(service, controller.ViewData.Model);
        }