-
Notifications
You must be signed in to change notification settings - Fork 0
4. Request response logging
Michal Motyčka edited this page Jul 9, 2023
·
4 revisions
All requests generated by Ridge can be logged. Logging is dependent on test framework used.
Use package RidgeDotNet.Extensions.Xunit
and
call UseXunitLogWriter
in WithRidge
method:
public class XunitLoggerTests
{
private readonly ITestOutputHelper _testOutputHelper;
public XunitLoggerTests(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
public void Test(){
//...
using var webApplicationFactory = WebApplicationFactory = webApplicationFactory.WithRidge(x =>
{
x.UseXunitLogWriter(_testOutputHelper);
});
var ridgeHttpClient = ridgeApplicationFactory.CreateRidgeClient();
//...
}
}
Use package RidgeDotNet.Extensions.Nunit
and
call UseNunitLogWriter
in WithRidge
method:
//--------------------------- Nunit --------------------------------------
public void Test(){
//...
using var webApplicationFactory = WebApplicationFactory = webApplicationFactory.WithRidge(x =>
{
x.UseNunitLogWriter();
});
var ridgeHttpClient = ridgeApplicationFactory.CreateRidgeClient();
//...
}
Call UseCustomLogWriter
in WithRidge
method:
//--------------------------- Custom implementation --------------------------------------
public class CustomLogWriter : ILogWriter
{
public void WriteLine(string text)
{
// log
}
}
public void Test(){
//...
using var webApplicationFactory = WebApplicationFactory = webApplicationFactory.WithRidge(x =>
{
x.UseCustomLogWriter(new CustomLogWriter());
});
var ridgeHttpClient = ridgeApplicationFactory.CreateRidgeClient();
//...
}
Request:
Time when request was sent: 15:35:58:167
Method: GET, RequestUri: 'http://localhost/ReturnGivenNumber?input=10', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
ridgeCallId: 2bca4d2d-0cd3-4293-8aae-4c3772db1eb1
Content-Type: application/json; charset=utf-8
Content-Length: 2
}
Body:
{}
Response:
Time when response was received: 15:35:58:258
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Content-Type: application/json; charset=utf-8
Content-Length: 2
}
Body:
10