Skip to content

Commit

Permalink
chore!: remove obsolete interface members
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Jul 15, 2022
1 parent cfd4bf7 commit 25241de
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/MockHttp/DeprecationWarnings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

internal static class DeprecationWarnings
{
public const string RespondsResult = "Obsolete, will be removed in next major release.";
}
11 changes: 3 additions & 8 deletions src/MockHttp/Extensions/IRespondsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,20 @@ public static class IRespondsExtensions
public static TResult Respond<TResult>(this IResponds<TResult> responds, Func<HttpResponseMessage> response)
where TResult : IResponseResult
{
if (responds is null)
{
throw new ArgumentNullException(nameof(responds));
}

if (response is null)
{
throw new ArgumentNullException(nameof(response));
}

return responds.RespondUsing(new ResponseFuncStrategy((_, _) => Task.FromResult(response())));
return responds.Respond((_, _) => response());
}

/// <summary>
/// Specifies a function that returns the response for a request.
/// </summary>
/// <param name="responds"></param>
/// <param name="response">The function that provides the response message to return for given request.</param>
public static TResult Respond<TResult>(this IResponds<TResult> responds, Func<HttpRequestMessage, HttpResponseMessage> response)
public static TResult Respond<TResult>(this IResponds<TResult> responds, Func<HttpRequestMessage, CancellationToken, HttpResponseMessage> response)
where TResult : IResponseResult
{
if (responds is null)
Expand All @@ -50,7 +45,7 @@ public static TResult Respond<TResult>(this IResponds<TResult> responds, Func<Ht
throw new ArgumentNullException(nameof(response));
}

return responds.RespondUsing(new ResponseFuncStrategy((request, _) => Task.FromResult(response(request))));
return responds.RespondUsing(new ResponseFuncStrategy((request, ct) => Task.FromResult(response(request, ct))));
}

/// <summary>
Expand Down
15 changes: 0 additions & 15 deletions src/MockHttp/Language/Flow/SetupPhrase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ protected SetupPhrase(HttpCall setup)

protected HttpCall Setup { get; }

public TResponseResult Respond(Func<Task<HttpResponseMessage>> responseFunc)
{
return RespondUsing(new ResponseFuncStrategy((_, __) => responseFunc()));
}

public TResponseResult Respond(Func<HttpRequestMessage, Task<HttpResponseMessage>> responseFunc)
{
return RespondUsing(new ResponseFuncStrategy((r, __) => responseFunc(r)));
}

public TResponseResult Respond(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> responseFunc)
{
return RespondUsing(new ResponseFuncStrategy(responseFunc));
}

public TResponseResult RespondUsing(IResponseStrategy responseStrategy)
{
if (responseStrategy is null)
Expand Down
21 changes: 0 additions & 21 deletions src/MockHttp/Language/IResponds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ namespace MockHttp.Language;
public interface IResponds<out TResult> : IFluentInterface
where TResult : IResponseResult
{
/// <summary>
/// Specifies a function that returns the response for a request.
/// </summary>
/// <param name="responseFunc">The function returning an awaitable that when completed provides the response message to return for a request.</param>
[Obsolete(DeprecationWarnings.RespondsResult)]
TResult Respond(Func<Task<HttpResponseMessage>> responseFunc);

/// <summary>
/// Specifies a function that returns the response for a request.
/// </summary>
/// <param name="responseFunc">The function returning an awaitable that when completed provides the response message to return for given request.</param>
[Obsolete(DeprecationWarnings.RespondsResult)]
TResult Respond(Func<HttpRequestMessage, Task<HttpResponseMessage>> responseFunc);

/// <summary>
/// Specifies a function that returns the response for a request.
/// </summary>
/// <param name="responseFunc">The function returning an awaitable that when completed provides the response message to return for given request.</param>
[Obsolete(DeprecationWarnings.RespondsResult)]
TResult Respond(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> responseFunc);

/// <summary>
/// Specifies a strategy that returns the response for a request.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions test/MockHttp.Server.Tests/MockHttpServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ public static IEnumerable<object[]> RequestResponseTestCases()
.When(matching => matching
.Header(headerKey, headerValue)
)
.Respond((r) => new HttpResponseMessage
.Respond((req, _) => new HttpResponseMessage
{
Headers =
{
{ headerKey, r.Headers.GetValues(headerKey) }
{ headerKey, req.Headers.GetValues(headerKey) }
}
})
),
Expand Down
6 changes: 3 additions & 3 deletions test/MockHttp.Tests/Extensions/IRespondsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task When_responding_with_message_based_on_request_it_should_return
var request = new HttpRequestMessage(HttpMethod.Get, "http://0.0.0.0/controller/action?query=1");

// Act
_sut.Respond(r => new HttpResponseMessage { Headers = { { "query", r.RequestUri.Query } } });
_sut.Respond((req, _) => new HttpResponseMessage { Headers = { { "query", req.RequestUri.Query } } });
HttpResponseMessage actualResponse = await _httpCall.SendAsync(new MockHttpRequestContext(request), CancellationToken.None);

// Assert
Expand Down Expand Up @@ -207,10 +207,10 @@ public static IEnumerable<object[]> TestCases()
IRespondsExtensions.Respond,
responds,
() => new HttpResponseMessage()),
DelegateTestCase.Create<IResponds<IResponseResult>, Func<HttpRequestMessage, HttpResponseMessage>, IResponseResult>(
DelegateTestCase.Create<IResponds<IResponseResult>, Func<HttpRequestMessage, CancellationToken, HttpResponseMessage>, IResponseResult>(
IRespondsExtensions.Respond,
responds,
_ => new HttpResponseMessage()),
(_, _) => new HttpResponseMessage()),
DelegateTestCase.Create(
IRespondsExtensions.RespondUsing<FakeResponseStrategy, IResponseResult>,
responds),
Expand Down

0 comments on commit 25241de

Please sign in to comment.