Exemplo n.º 1
0
        public void CurrentTypesShouldReturnSameViewWithEmptyStringOnPost()
        {
            //arrange

            diaryService.Setup(x => x.Types()).Returns(new List <DiaryTypeOutputModel>
            {
                new DiaryTypeOutputModel
                {
                    Id   = 1,
                    Type = "Cutting"
                },
                new DiaryTypeOutputModel
                {
                    Id   = 2,
                    Type = "Bulking"
                }
            });

            var adminController = new Web.Areas.Administration.Controllers
                                  .AdminsController(adminService.Object, diaryService.Object);

            //act
            var result = adminController.CurrentTypes(null);

            //assert

            result.As <ViewResult>().ViewData.ContainsKey(GlobalConstants.Error).Equals(GlobalConstants.NullName);
        }
Exemplo n.º 2
0
        public async Task DeleteDiaryShouldRedirectToAllDiaries()
        {
            //arrange
            string username = "******";
            var    user     = new Mock <ClaimsPrincipal>();

            user.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(true);
            user.Setup(x => x.Identity.Name).Returns(username);

            var adminsController = new Web.Areas.Administration.Controllers
                                   .AdminsController(adminService.Object, diaryService.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext {
                        User = user.Object
                    }
                }
            };

            //act
            int id     = 1;
            var result = await adminsController.DeleteDiary(id);

            //assert
            Assert.AreEqual(((RedirectToActionResult)result)
                            .ActionName, nameof(Web.Controllers.DiariesController.AllDiaries));
        }
Exemplo n.º 3
0
        public void CurrentTypesShouldRedirectBackWhenTypeAlreadyExists()
        {
            //arrange
            diaryService.Setup(x => x.Types()).Returns(new List <DiaryTypeOutputModel>
            {
                new DiaryTypeOutputModel
                {
                    Id   = 1,
                    Type = "Cutting"
                },
                new DiaryTypeOutputModel
                {
                    Id   = 2,
                    Type = "Bulking"
                }
            });
            string name = "TypeTests";

            adminService.Setup(x => x.AddDiaryType(name)).Returns(GlobalConstants.Failed);

            var adminController = new Web.Areas.Administration.Controllers
                                  .AdminsController(adminService.Object, diaryService.Object);

            //act

            var result = adminController.CurrentTypes(name);

            //assert
            string expected = string.Join(GlobalConstants.AlreadyExistsInDatabase, name);

            result.As <ViewResult>().ViewData.ContainsKey(GlobalConstants.Error).Equals(expected);
        }
Exemplo n.º 4
0
        public async Task DeleteDiaryShouldRedirectToErrorWhenRoleIsMissing()
        {
            //arrange
            var user = new Mock <ClaimsPrincipal>();

            user.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(false);
            var adminsController = new Web.Areas.Administration.Controllers
                                   .AdminsController(adminService.Object, diaryService.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext {
                        User = user.Object
                    }
                }
            };

            //act
            int id     = 1;
            var result = await adminsController.DeleteDiary(id);

            //assert
            Assert.AreEqual(((RedirectToActionResult)result).ActionName, nameof(HomeController.Error));
        }