Код: Выделить всё
try
{
var response = await client.GetAsync(url, cancellationToken);
}
catch(Exception e)
{
_logger.LogError(e)
}
Код: Выделить всё
var factory = new Mock();
var httpClient = new HttpClient(handler)
{
BaseAddress = new Uri("http://localhost:7100")
}
factory.Setup(_ => _.CreateClient(It.IsAny()))
.Returns(httpClient)
.Verifiable();
Код: Выделить всё
var handler = new Mock();
handler
.Protected()
.Setup(
"SendAsync",
ItExpr.IsAny(),
ItExpr.IsAny()
)
.Returns(GetHttpResponseMessage())
.Verifiable();
Код: Выделить всё
HttpResponseMessage GetHttpResponseMessage(int code)
{
if(code == 200)
{
return new HttpResponseMessage{ StatusCode = HttpStatusCode.OK };
}
else if(code == 500)
{
//StatusCode.InternalServerError ???
//throw new Exception() ???
}
}
Спасибо за помощь
Подробнее здесь: https://stackoverflow.com/questions/791 ... s-an-excep