Skip to content

Commit

Permalink
test: update mocklogger to align with code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OswellHita committed Nov 13, 2024
1 parent 5525d0c commit ada6235
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public async Task Run_ShouldReturnInternalServerError_WhenExceptionIsThrownOnCal
var response = await _function.Run(_mockRequest.Object);

// Assert
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
_mockLogger.Verify(log => log.Log(
LogLevel.Error,
0,
It.Is<It.IsAnyType>((state, type) => state.ToString().Contains("Failed to deserialise or retrieve episode from http://localhost:6060/api/GetEpisode?EpisodeId=245395. ")),
null,
(Func<object, Exception, string>)It.IsAny<object>()),
_mockLogger.Verify(x => x.Log(It.Is<LogLevel>(l => l == LogLevel.Error),
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Failed to deserialise or retrieve episode from http://localhost:6060/api/GetEpisode?EpisodeId=245395.")),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);

_mockHttpRequestService.Verify(x => x.SendPost(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ public async Task Run_ShouldReturnInternalServerError_WhenExceptionIsThrownOnCal

// Assert
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
_mockLogger.Verify(log => log.Log(
LogLevel.Error,
0,
It.Is<It.IsAnyType>((state, type) => state.ToString().Contains("Failed to deserialise or retrieve participant from http://localhost:6061/api/GetParticipant?nhs_number=1111111112.")),
null,
(Func<object, Exception, string>)It.IsAny<object>()),
Times.Once);
_mockLogger.Verify(x => x.Log(It.Is<LogLevel>(l => l == LogLevel.Error),
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Failed to deserialise or retrieve participant from http://localhost:6061/api/GetParticipant?nhs_number=1111111112.")),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
_mockHttpRequestService.Verify(x => x.SendPost(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ public async Task Run_ShouldReturnInternalServerError_WhenExceptionIsThrown()

// Assert
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
_mockLogger.Verify(log => log.Log(
LogLevel.Error,
0,
It.Is<It.IsAnyType>((state, type) => state.ToString().Contains("Failed to get episode from database.") &&
state.ToString().Contains("Exception: System.Exception: Database error")),
null,
(Func<object, Exception, string>)It.IsAny<object>()),
_mockLogger.Verify(x => x.Log(It.Is<LogLevel>(l => l == LogLevel.Error),
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Failed to get episode from database.")),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,11 @@ public async Task Run_ShouldReturnInternalServerError_WhenExceptionIsThrown()

// Assert
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
_mockLogger.Verify(log => log.Log(
LogLevel.Error,
0,
It.Is<It.IsAnyType>((state, type) => state.ToString().Contains("Failed to call the GetEpisode Data Service.") &&
state.ToString().Contains("Exception: System.Net.Http.HttpRequestException:")),
null,
(Func<object, Exception, string>)It.IsAny<object>()),
_mockLogger.Verify(x => x.Log(It.Is<LogLevel>(l => l == LogLevel.Error),
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Failed to call the GetEpisode Data Service.")),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}
}

0 comments on commit ada6235

Please sign in to comment.