public async Task TestThat_WriteMessage_When_MessageIsNull_Throws_ArgumentNullException() { // Arrange var outputProviderMock = new Mock <IConsoleOutputProvider>(); var dataWriter = new ConsoleMessageDataWriter(outputProviderMock.Object); // Act async Task Act() => await dataWriter.WriteMessage(MockObjects.NullMessage); // Assert await Assert.ThrowsAsync <ArgumentNullException>(Act); }
public async Task TestThat_WriteMessage_When_MessageIsValid_Calls_OutputProviderOutputMethod_Once() { // Arrange var outputProviderMock = new Mock <IConsoleOutputProvider>(); var mockMessage = MockObjects.ValidMessage; var dataWriter = new ConsoleMessageDataWriter(outputProviderMock.Object); // Act await dataWriter.WriteMessage(mockMessage); // Assert outputProviderMock.Verify(x => x.OutputStringLine(mockMessage), Times.Once); }
public async Task TestThat_WriteMessage_When_OutputProviderThrowsException_Throws_SameException() { // Arrange var mockException = MockObjects.GenericException; var outputProviderMock = new Mock <IConsoleOutputProvider>(); outputProviderMock .Setup(x => x.OutputStringLine(It.IsAny <string>())) .Throws(mockException); var dataWriter = new ConsoleMessageDataWriter(outputProviderMock.Object); // Act async Task Act() => await dataWriter.WriteMessage(MockObjects.ValidMessage); // Assert var exception = await Assert.ThrowsAnyAsync <Exception>(Act); Assert.Equal(mockException, exception); }