Пример #1
0
        public void GetToNewShouldReturnNewViewWithUninitializedViewModel()
        {
            var mockCommandInvoker = new Mock<ICommandInvoker>();
            var mockUserRepository = new Mock<IUserRepository>();
            var mockNoteRepository = new Mock<INoteRepository>();

            var controller = new NotesController(mockCommandInvoker.Object, mockNoteRepository.Object, mockUserRepository.Object);
            var result = controller.New() as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual("new", result.ViewName);
            var model = result.ViewData.Model as EditNoteViewModel;
            Assert.IsNotNull(model);
            Assert.IsNull(model.Content);
            Assert.IsNull(model.Title);
        }
Пример #2
0
 private static NotesController GetNotesController(Mock<ICommandInvoker> mockCommandInvoker, Mock<INoteRepository> mockNoteRepository, Mock<IUserRepository> mockUserRepository)
 {
     var mockHttpContext = new Mock<ControllerContext>();
     mockHttpContext.Setup(x => x.HttpContext.User.Identity.Name).Returns("boco");
     var notesController = new NotesController(mockCommandInvoker.Object, mockNoteRepository.Object,
                                               mockUserRepository.Object) { ControllerContext = mockHttpContext.Object };
     return notesController;
 }
Пример #3
0
        public void PostToEditShouldRedirectToIndexForNonExistantNote()
        {
            var mockCommandInvoker = new Mock<ICommandInvoker>();
            var mockUserRepository = new Mock<IUserRepository>();
            var mockNoteRepository = new Mock<INoteRepository>();
            mockNoteRepository.Setup(x => x.GetNote(It.IsAny<Guid>())).Returns((Core.Entities.Note)null);
            var notesController = new NotesController(mockCommandInvoker.Object, mockNoteRepository.Object, mockUserRepository.Object);
            var result = notesController.Edit(null, Guid.NewGuid().ToString()) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("index", result.RouteValues["action"]);
        }