예제 #1
0
        public void TestUpdateANote()
        {
            //DB mit Daten füllen
            int noteID = 1;

            FillDBWithNode(noteID);

            var style          = _serviceProvider.GetService <IStyle>();
            var noteController = new NoteController(_dbContext, style);

            //Note editieren
            IActionResult result     = noteController.Edit(noteID);
            ViewResult    viewResult = Assert.IsType <ViewResult>(result);
            Note          noteModel  = Assert.IsType <Note>(viewResult.Model);

            string modifizierterTitle = "Modifizierter Titel";

            noteModel.Title = modifizierterTitle;
            noteController.Edit(1, noteModel);

            //DB query auf modifizierte Note
            var query = from n in _dbContext.Note
                        where n.ID == noteID
                        select n;

            var updatedNote = query.Single();

            Assert.Equal(1, updatedNote.ID);
            Assert.Equal(modifizierterTitle, updatedNote.Title);
        }
예제 #2
0
        public void TestGetting404Error()
        {
            var style          = _serviceProvider.GetService <IStyle>();
            var noteController = new NoteController(_dbContext, style);

            int noteId = 99;
            var result = noteController.Edit(noteId);
            StatusCodeResult statusCodeResult = Assert.IsAssignableFrom <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.NotFound, statusCodeResult.StatusCode);
        }
예제 #3
0
        public void UpdateShouldReturnToIndex()
        {
            var mockRepo = new Mock <INoteRepository>();
            var note     = new Note {
                NoteId = 1, NoteTitle = "Tech-Stack", NoteContent = "DotNet", NoteStatus = "Started"
            };

            mockRepo.Setup(repo => repo.UpdateNote(note)).Returns(1);
            var noteController = new NoteController(mockRepo.Object);

            var actual = noteController.Edit(note);

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

            Assert.Null(actionResult.ControllerName);
            Assert.Equal("Index", actionResult.ActionName);
        }
예제 #4
0
        public void Can_Edit_Note()
        {
            // Arrange
            var context = new TestContext();

            context.Users.Add(user);

            context.Notes.Add(new Note()
            {
                Id = 1, Title = "Note 1", DueDate = DateTime.Parse("02-01-17"), User = user
            });

            // Arrange - create the controller
            NoteController target = new NoteController(context)
            {
                GetUserId = () => user.Id
            };

            // Act
            EditNoteViewModel model = ((ViewResult)target.Edit(1, null)).ViewData.Model as EditNoteViewModel;

            // Assert - ensure correct note is passed to View
            Assert.AreEqual("Note 1", model.Title);
        }
예제 #5
0
        public void GetNote_NoteFound_ReturnNote()
        {
            var view = controller.Edit(1) as ViewResult;

            Assert.IsType(typeof(Note), view.ViewData.Model);
        }