Exemplo n.º 1
0
        public void CreateRecordShouldReturnPropperResultIfModelStateIsInvalid()
        {
            var areasFake = new Mock <IAreasServices>();

            areasFake.Setup(a => a.GetByUserId(It.IsAny <string>())).Returns(areas);

            var recordsFake = new Mock <IRecordsServices>();

            recordsFake.Setup(x => x.GetByAreaId(It.IsAny <int>())).Returns(this.records);

            var documentsFake = new Mock <IDocumentsServices>().Object;
            var usersFake     = new Mock <IUsersServices>().Object;

            var controller = new AreasController(areasFake.Object, recordsFake.Object, documentsFake, usersFake);

            controller.ModelState.AddModelError("Invalid model", "Error message");

            Mapper.CreateMap <Area, AreaShortViewModel>();
            Mapper.CreateMap <Area, AreaListViewModel>();
            Mapper.CreateMap <User, UserShortViewModel>();
            Mapper.CreateMap <Record, RecordListViewModel>();

            ViewResult viewResult       = controller.Index() as ViewResult;
            var        invalidViewModel = new RecordCreateViewModel();

            controller.WithCallTo(c => c.CreateRecord(1, invalidViewModel))
            .ShouldRenderView(string.Empty)
            .WithModel <RecordCreateViewModel>(x => Assert.AreSame(invalidViewModel, x));
        }
Exemplo n.º 2
0
        public void IndexShouldReturnProperResult()
        {
            var request = new Mock <HttpRequestBase>();

            var areasFake = new Mock <IAreasServices>();

            areasFake.Setup(a => a.all()).Returns(areas);

            var recordsFake   = new Mock <IRecordsServices>().Object;
            var documentsFake = new Mock <IDocumentsServices>().Object;
            var usersFake     = new Mock <IUsersServices>().Object;

            request.SetupGet(x => x.IsAuthenticated).Returns(false);

            var controller = new AreasController(areasFake.Object, recordsFake, documentsFake, usersFake);

            Mapper.CreateMap <Area, AreaListViewModel>();
            Mapper.CreateMap <User, UserShortViewModel>();

            ViewResult viewResult = controller.Index() as ViewResult;

            controller.WithCallTo(c => c.Index(1))
            .ShouldRenderView("Index")
            .WithModel <IQueryable <AreaListViewModel> >(x => Assert.AreEqual(4, x.Count()));
        }
Exemplo n.º 3
0
        public void GetCurrentUserAreasShouldReturnProperResult()
        {
            var userId  = Guid.NewGuid().ToString();
            var request = new Mock <HttpRequestBase>();

            request.SetupGet(x => x.IsAuthenticated).Returns(true);

            var areasFake = new Mock <IAreasServices>();

            areasFake.Setup(a => a.GetByUserId(It.IsAny <string>())).Returns(areas);

            var recordsFake   = new Mock <IRecordsServices>().Object;
            var documentsFake = new Mock <IDocumentsServices>().Object;
            var usersFake     = new Mock <IUsersServices>().Object;

            request.SetupGet(x => x.IsAuthenticated).Returns(false);

            var controller = new AreasController(areasFake.Object, recordsFake, documentsFake, usersFake)
            {
                ControllerContext = FakeControllerContext.GetFakeControllerContextWithFakeIdentity()
            };

            Mapper.CreateMap <Area, AreaShortViewModel>();
            Mapper.CreateMap <Area, AreaListViewModel>();
            Mapper.CreateMap <User, UserShortViewModel>();

            ViewResult viewResult = controller.Index() as ViewResult;

            controller.WithCallTo(c => c.GetCurrentUserAreas())
            .ShouldRenderPartialView("_UserAreasDropDownList")
            .WithModel <List <AreaShortViewModel> >(x => Assert.AreEqual(4, x.Count()));
        }
Exemplo n.º 4
0
        public void MyAreasShouldReturnProperResult()
        {
            var userId  = Guid.NewGuid().ToString();
            var request = new Mock <HttpRequestBase>();

            request.SetupGet(x => x.IsAuthenticated).Returns(true);

            var areasFake = new Mock <IAreasServices>();

            areasFake.Setup(a => a.GetByUserId(It.IsAny <string>())).Returns(areas);

            var recordsFake   = new Mock <IRecordsServices>().Object;
            var documentsFake = new Mock <IDocumentsServices>().Object;
            var usersFake     = new Mock <IUsersServices>().Object;

            request.SetupGet(x => x.IsAuthenticated).Returns(false);

            var principalFake = new Mock <IPrincipal>();

            principalFake.Setup(x => x.Identity).Returns(new IdentityFake());

            var fakeHttpContext = new Mock <HttpContextBase>();

            fakeHttpContext.Setup(x => x.User).Returns(principalFake.Object);
            var controllerContext = new Mock <ControllerContext>();

            controllerContext.Setup(t => t.HttpContext).Returns(fakeHttpContext.Object);

            var controller = new AreasController(areasFake.Object, recordsFake, documentsFake, usersFake)
            {
                ControllerContext = controllerContext.Object
            };

            Mapper.CreateMap <Area, AreaListViewModel>();
            Mapper.CreateMap <User, UserShortViewModel>();

            ViewResult viewResult = controller.Index() as ViewResult;

            controller.WithCallTo(c => c.MyAreas())
            .ShouldRenderView("Index")
            .WithModel <IQueryable <AreaListViewModel> >(x => Assert.AreEqual(4, x.Count()));
        }