-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,374 additions
and
1,029 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
using Moq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NetDaemon.Common; | ||
// using Moq; | ||
// using System.Net; | ||
// using System.Net.Http; | ||
// using System.Text; | ||
// using System.Threading; | ||
// using System.Threading.Tasks; | ||
// using NetDaemon.Common; | ||
|
||
namespace NetDaemon.Daemon.Tests.Daemon | ||
{ | ||
public class HttpClientFactoryMock : Mock<IHttpClientFactory> | ||
{ | ||
private HttpClient? _httpClient; | ||
private MockHttpMessageHandler? _handler; | ||
public MockHttpMessageHandler? MessageHandler => _handler; | ||
// namespace NetDaemon.Daemon.Tests.Daemon | ||
// { | ||
// public class HttpClientFactoryMock : Mock<IHttpClientFactory> | ||
// { | ||
// private HttpClient? _httpClient; | ||
// private MockHttpMessageHandler? _handler; | ||
// public MockHttpMessageHandler? MessageHandler => _handler; | ||
|
||
public HttpClientFactoryMock() | ||
{ | ||
} | ||
// public HttpClientFactoryMock() | ||
// { | ||
// } | ||
|
||
public void SetResponse(string response, HttpStatusCode statusCode = HttpStatusCode.OK) | ||
{ | ||
_handler = new MockHttpMessageHandler(response, statusCode); | ||
_httpClient = new HttpClient(_handler); | ||
Setup(x => x.CreateClient(It.IsAny<string>())).Returns(_httpClient!); | ||
} | ||
} | ||
// public void SetResponse(string response, HttpStatusCode statusCode = HttpStatusCode.OK) | ||
// { | ||
// _handler = new MockHttpMessageHandler(response, statusCode); | ||
// _httpClient = new HttpClient(_handler); | ||
// Setup(x => x.CreateClient(It.IsAny<string>())).Returns(_httpClient!); | ||
// } | ||
// } | ||
|
||
public class HttpHandlerMock : Mock<IHttpHandler> | ||
{ | ||
private HttpClient? _httpClient; | ||
private MockHttpMessageHandler? _handler; | ||
// public class HttpHandlerMock : Mock<IHttpHandler> | ||
// { | ||
// private HttpClient? _httpClient; | ||
// private MockHttpMessageHandler? _handler; | ||
|
||
public MockHttpMessageHandler? MessageHandler => _handler; | ||
// public MockHttpMessageHandler? MessageHandler => _handler; | ||
|
||
public HttpHandlerMock() | ||
{ | ||
} | ||
// public HttpHandlerMock() | ||
// { | ||
// } | ||
|
||
public void SetResponse(string response, HttpStatusCode statusCode = HttpStatusCode.OK) | ||
{ | ||
_handler = new MockHttpMessageHandler(response, statusCode); | ||
_httpClient = new HttpClient(_handler); | ||
Setup(x => x.CreateHttpClient(It.IsAny<string>())).Returns(_httpClient!); | ||
} | ||
} | ||
// public void SetResponse(string response, HttpStatusCode statusCode = HttpStatusCode.OK) | ||
// { | ||
// _handler = new MockHttpMessageHandler(response, statusCode); | ||
// _httpClient = new HttpClient(_handler); | ||
// Setup(x => x.CreateHttpClient(It.IsAny<string>())).Returns(_httpClient!); | ||
// } | ||
// } | ||
|
||
public class MockHttpMessageHandler : HttpMessageHandler | ||
{ | ||
private readonly string _response; | ||
private readonly HttpStatusCode _StatusCode; | ||
// public class MockHttpMessageHandler : HttpMessageHandler | ||
// { | ||
// private readonly string _response; | ||
// private readonly HttpStatusCode _StatusCode; | ||
|
||
private string? _requestContent; | ||
// private string? _requestContent; | ||
|
||
public string? RequestContent => _requestContent; | ||
// public string? RequestContent => _requestContent; | ||
|
||
public MockHttpMessageHandler(string response, HttpStatusCode statusCode = HttpStatusCode.OK) | ||
{ | ||
_response = response; | ||
_StatusCode = statusCode; | ||
} | ||
// public MockHttpMessageHandler(string response, HttpStatusCode statusCode = HttpStatusCode.OK) | ||
// { | ||
// _response = response; | ||
// _StatusCode = statusCode; | ||
// } | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
var responseMessage = new HttpResponseMessage(_StatusCode); | ||
// protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
// { | ||
// var responseMessage = new HttpResponseMessage(_StatusCode); | ||
|
||
if (request is not null && request.Content is not null) | ||
_requestContent = await request.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
// if (request is not null && request.Content is not null) | ||
// _requestContent = await request.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
|
||
responseMessage.Content = new ByteArrayContent(Encoding.ASCII.GetBytes(_response)); | ||
return responseMessage; | ||
} | ||
} | ||
} | ||
// responseMessage.Content = new ByteArrayContent(Encoding.ASCII.GetBytes(_response)); | ||
// return responseMessage; | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.