public async Task VerifyNoChangeIfNullYouTubePropertySpecified() { // Arrange string originalContent = "#Hello\n* world\n* 1234"; string youtube = null; string expectedLogOutput = "No YouTube ID provided, not embedding a YouTube Video."; mockHttpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(() => { return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }); }); var client = new HttpClient(mockHttpMessageHandler.Object); mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); // Act MediumService mediumService = new MediumService(mockFactory.Object, mockLogger.Object); string contentWithYouTube = await mediumService.AppendYouTubeInformation(originalContent, youtube); // Assert Assert.Equal(originalContent, contentWithYouTube); Func <object, Type, bool> state = (v, t) => v.ToString().CompareTo(expectedLogOutput) == 0; mockLogger.Verify(l => l.Log( LogLevel.Information, It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => state(v, t)), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Exactly(1)); }
public async Task VerifyYouTubeLiquidTagAddedAtEndOfBody() { // Arrange string originalContent = "#Hello\n* world\n* 1234"; string youtube = "abc123456"; string expectedLogOutput = $"Youtube ID {youtube} added"; mockHttpMessageHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(() => { return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }); }); var client = new HttpClient(mockHttpMessageHandler.Object); mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); // Act MediumService mediumService = new MediumService(mockFactory.Object, mockLogger.Object); string contentWithYouTube = await mediumService.AppendYouTubeInformation(originalContent, youtube); // Assert Assert.Contains($"https://youtu.be/{youtube}", contentWithYouTube); Func <object, Type, bool> state = (v, t) => v.ToString().CompareTo(expectedLogOutput) == 0; mockLogger.Verify(l => l.Log( LogLevel.Information, It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => state(v, t)), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Exactly(1)); }