Beispiel #1
0
        public void TestEditEntry_ShouldCallEntryServiceEditEntryCorrectly(int entryId, string content)
        {
            // Arrange
            var mockedService  = new Mock <IEntryService>();
            var mockedProvider = new Mock <IAuthenticationProvider>();

            var controller = new EntriesController(mockedService.Object, mockedProvider.Object);

            var model = new LogEntryViewModel {
                EntryId = entryId, Content = content
            };

            // Act
            controller.EditEntry(model);

            // Assert
            mockedService.Verify(s => s.EditEntry(entryId, content), Times.Once);
        }
Beispiel #2
0
        public void TestEditEntry_ShouldSetViewModelContentCorrectly(int entryId, string content)
        {
            // Arrange
            var mockedService = new Mock <IEntryService>();

            mockedService.Setup(s => s.EditEntry(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new LogEntry {
                Content = content
            });

            var mockedProvider = new Mock <IAuthenticationProvider>();

            var controller = new EntriesController(mockedService.Object, mockedProvider.Object);

            var model = new LogEntryViewModel {
                EntryId = entryId, Content = content
            };

            // Act
            var result = controller.EditEntry(model);

            // Assert
            Assert.AreEqual(content, ((LogEntryViewModel)result.Model).Content);
        }
Beispiel #3
0
        public void TestEditEntry_ModelStateIsNotValid_ShouldNotCallEntryServiceEditEntryCorrectly(int entryId, string content)
        {
            // Arrange
            var mockedService = new Mock <IEntryService>();

            mockedService.Setup(s => s.EditEntry(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new LogEntry());

            var mockedProvider = new Mock <IAuthenticationProvider>();

            var controller = new EntriesController(mockedService.Object, mockedProvider.Object);

            controller.ModelState.AddModelError("", "");

            var model = new LogEntryViewModel {
                EntryId = entryId, Content = content
            };

            // Act
            controller.EditEntry(model);

            // Assert
            mockedService.Verify(s => s.EditEntry(It.IsAny <int>(), It.IsAny <string>()), Times.Never);
        }