public void IndexTest04()
        {
            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;

            var result = controller.Index(null);

            var actionResult = Assert.IsType <RedirectToActionResult>(result);
            var model        = Assert.IsType <RedirectToActionResult>(actionResult);

            Assert.Equal("Index", actionResult.ActionName);
            Assert.Equal("Menu", actionResult.ControllerName);
            Assert.Equal("日記が見つかりませんでした。", controller.TempData["notification"]);

            controller.Dispose();
        }
        public void EditTest002()
        {
            var editViewModel = new EditViewModel()
            {
                Id = "1", Title = "たいとる更新(テスト)", Content = "ほんぶん更新(てすと)"
            };

            mockService.Setup(x => x.UpdateDiary(editViewModel)).Returns(true);

            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;
            controller.ModelState.AddModelError("key", "ERROR");
            var result = controller.Edit(editViewModel);
            var model  = Assert.IsType <ViewResult>(result);

            Assert.Equal("Index", model.ViewName);
            controller.Dispose();
        }
        public void DeleteTest002()
        {
            var editViewModel = new EditViewModel()
            {
                Id = "16777216", Title = string.Empty, Content = string.Empty
            };
            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;
            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.ControllerContext.HttpContext.Request.Headers["test"] = "test";

            var result = controller.Delete(editViewModel);

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

            Assert.Equal("Views/Shared/Error.cshtml", model.ViewName);

            controller.Dispose();
        }
        public void IndexTest01()
        {
            var editViewModel = new EditViewModel()
            {
                Id = "1", Title = "たいとる更新(テスト)", Content = "ほんぶん更新(てすと)"
            };

            mockService.Setup(x => x.GetDiary(1)).Returns(editViewModel);
            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;

            var result = controller.Index("1");

            var actionResult = Assert.IsType <ViewResult>(result);
            var model        = Assert.IsType <EditViewModel>(actionResult.ViewData.Model);

            Assert.Null(controller.TempData["notification"]);

            controller.Dispose();
        }
        public void DeleteTest003()
        {
            var editViewModel = new EditViewModel()
            {
                Id = "2", Title = "たいとる更新(テスト)", Content = "ほんぶん更新(てすと)"
            };

            mockService.Setup(x => x.DeleteDiary(2)).Returns(false);
            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;

            var result = controller.Delete(editViewModel);

            var model = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", model.ActionName);
            Assert.Equal("Menu", model.ControllerName);
            Assert.Equal("すでに削除されています。", controller.TempData["notification"]);

            controller.Dispose();
        }
        public void EditTest001()
        {
            var editViewModel = new EditViewModel()
            {
                Id = "1", Title = "たいとる更新(テスト)", Content = "ほんぶん更新(てすと)"
            };

            mockService.Setup(x => x.UpdateDiary(editViewModel)).Returns(true);
            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;

            var result = controller.Edit(editViewModel);

            var model = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", model.ActionName);
            Assert.Equal("Refer", model.ControllerName);
            Assert.Null(controller.TempData["notification"]);

            controller.Dispose();
        }
        public void IndexTest02()
        {
            var editViewModel = new EditViewModel()
            {
                Id = "1", Title = "たいとる更新(テスト)", Content = "ほんぶん更新(てすと)"
            };

            mockService.Setup(x => x.GetDiary(1)).Returns(editViewModel);
            var controller = new EditController(mockService.Object);

            controller.TempData = tempData;

            var result = controller.Index("2");

            var actionResult = Assert.IsType <RedirectToActionResult>(result);
            var model        = Assert.IsType <RedirectToActionResult>(actionResult);

            Assert.Equal("Index", actionResult.ActionName);
            Assert.Equal("Menu", actionResult.ControllerName);
            Assert.Equal("日記が見つかりませんでした。", controller.TempData["notification"]);

            controller.Dispose();
        }