Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions Source/Mockolate/Web/HttpClientExtensions.Setup.Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Mockolate.Exceptions;
using Mockolate.Parameters;
using Mockolate.Setup;

Expand Down Expand Up @@ -43,28 +44,19 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<string?>? requestUri,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Delete,
new HttpStringUriParameter(requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Delete,
new HttpStringUriParameter(requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}

/// <summary>
Expand All @@ -76,28 +68,19 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<Uri?>? requestUri,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Delete,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Delete,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}
}
}
Expand Down
39 changes: 11 additions & 28 deletions Source/Mockolate/Web/HttpClientExtensions.Setup.Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Mockolate.Exceptions;
using Mockolate.Parameters;
using Mockolate.Setup;

Expand Down Expand Up @@ -43,28 +44,19 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<string?>? requestUri,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Get,
new HttpStringUriParameter(requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Get,
new HttpStringUriParameter(requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}

/// <summary>
Expand All @@ -76,28 +68,19 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<Uri?>? requestUri,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Get,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Get,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}
}
}
Expand Down
41 changes: 11 additions & 30 deletions Source/Mockolate/Web/HttpClientExtensions.Setup.Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Mockolate.Exceptions;
using Mockolate.Parameters;
using Mockolate.Setup;

Expand Down Expand Up @@ -47,30 +48,20 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<HttpContent?>? content,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Patch,
new HttpStringUriParameter(requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Patch,
new HttpStringUriParameter(requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}

/// <summary>
Expand All @@ -83,30 +74,20 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<HttpContent?>? content,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Patch,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Patch,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}
}
}
Expand Down
41 changes: 11 additions & 30 deletions Source/Mockolate/Web/HttpClientExtensions.Setup.Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Mockolate.Exceptions;
using Mockolate.Parameters;
using Mockolate.Setup;

Expand Down Expand Up @@ -46,30 +47,20 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<HttpContent?>? content,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Post,
new HttpStringUriParameter(requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Post,
new HttpStringUriParameter(requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}

/// <summary>
Expand All @@ -82,30 +73,20 @@ public IReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, Cancell
IParameter<HttpContent?>? content,
IParameter<CancellationToken> cancellationToken)
{
if (setup is Mock<HttpClient> httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock &&
httpMessageHandlerMock.Mock is IMockMethodSetup<HttpMessageHandler> httpMessageHandlerSetup)
if (setup is Mock<HttpClient> { ConstructorParameters.Length: > 0, } httpClientMock &&
httpClientMock.ConstructorParameters[0] is IMockSubject<HttpMessageHandler> httpMessageHandlerMock)
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageHandler.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Post,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(httpMessageHandlerSetup).SetupMethod(methodSetup);
return methodSetup;
}
else
{
ReturnMethodSetup<Task<HttpResponseMessage>, HttpRequestMessage, CancellationToken> methodSetup =
new("System.Net.Http.HttpMessageInvoker.SendAsync",
new NamedParameter("request", new HttpRequestMessageParameters(HttpMethod.Post,
new HttpRequestMessageParameter<Uri?>(r => r.RequestUri, requestUri),
new HttpRequestMessageParameter<HttpContent?>(r => r.Content, content))),
new NamedParameter("cancellationToken", (IParameter)cancellationToken));
CastToMockRegistrationOrThrow(setup).SetupMethod(methodSetup);
httpMessageHandlerMock.Mock.Registrations.SetupMethod(methodSetup);
return methodSetup;
}

throw new MockException("Cannot setup HttpClient when it is not mocked with a mockable HttpMessageHandler.");
}
}
}
Expand Down
Loading
Loading