public void TestNewEntry_ShouldCallAuthenticationProviderCurrentUserId() { // Arrange var model = new NewEntryViewModel(); var mockedService = new Mock <IEntryService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new EntriesController(mockedService.Object, mockedAuthenticationProvider.Object); // Act controller.NewEntry(model); // Assert mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Once); }
public void TestNewEntry_ModelStateIsNotValid_ShouldNotCallAuthenticationProviderCurrentUserId() { // Arrange var model = new NewEntryViewModel(); var mockedService = new Mock <IEntryService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new EntriesController(mockedService.Object, mockedAuthenticationProvider.Object); controller.ModelState.AddModelError("", ""); // Act controller.NewEntry(model); // Assert mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Never); }
public void TestNewEntry_ShouldCallEntryServiceAddEntryToLogCorrectly(int logId, string content, string userId) { // Arrange var model = new NewEntryViewModel { LogId = logId, Content = content }; var mockedService = new Mock <IEntryService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); mockedAuthenticationProvider.Setup(p => p.CurrentUserId).Returns(userId); var controller = new EntriesController(mockedService.Object, mockedAuthenticationProvider.Object); // Act controller.NewEntry(model); // Assert mockedService.Verify(s => s.AddEntryToLog(content, logId, userId), Times.Once); }