Пример #1
0
        public void CreateNotePartialParamOverloadSuccessCreate()
        {
            NotesController controller = new NotesController(_service);
            SetupControllerContext(controller, TestUser3);

            ViewModel<Note> model = new ViewModel<Note>(new Note
                                                            {
                                                                Text = "new note"
                                                            });
            PartialViewResult viewResult = controller.CreateNotePartial(model);
            Note note = _service.MockNotes.List.Last();

            Assert.AreEqual(21, _service.MockNotes.List.Count);
            Assert.AreEqual(TestUser3, note.User);
            Assert.AreEqual("new note", note.Text);
            Assert.IsTrue(_saveCalled);

            Assert.IsNotNull(viewResult, "viewResult");

            ViewModel<List<Note>> viewModel = viewResult.Model as ViewModel<List<Note>>;
            Assert.IsNotNull(viewModel, "viewModel");

            Assert.AreEqual(1, viewModel.Model.Count);
        }
Пример #2
0
        public void CreateNotePartialWithParamOverloadFailCreate()
        {
            NotesController controller = new NotesController(_service);
            SetupControllerContext(controller, TestUser3);

            ViewModel<Note> note = new ViewModel<Note>();
            controller.ModelState.AddModelError("testError", "Test error message");

            PartialViewResult viewResult = controller.CreateNotePartial(note);

            Assert.AreEqual(20, _service.MockNotes.List.Count);
            Assert.IsFalse(_saveCalled);
            Assert.IsNotNull(viewResult, "viewResult");

            ViewModel<Note> viewModel = viewResult.Model as ViewModel<Note>;
            Assert.IsNotNull(viewModel, "viewModel");
        }
Пример #3
0
        public void CreateNotePartialEmptyParamOverload()
        {
            NotesController controller = new NotesController(_service);
            SetupControllerContext(controller, TestUser2);

            PartialViewResult viewResult = controller.CreateNotePartial();
            Assert.IsNotNull(viewResult, "viewResult");

            ViewModel<Note> viewModel = viewResult.Model as ViewModel<Note>;
            Assert.IsNotNull(viewModel, "viewModel");
        }