Skip to content

Commit

Permalink
feat: convert to file-scoped namespaces, use latest c# language synta…
Browse files Browse the repository at this point in the history
…x, fix spelling mistakes, utilize GlobalUsings, sealing test classes and fixing 1 failing test
  • Loading branch information
Per Kops committed May 7, 2024
1 parent 821a40b commit 090d8a5
Show file tree
Hide file tree
Showing 23 changed files with 1,109 additions and 1,146 deletions.
33 changes: 18 additions & 15 deletions src/Atc.Rest.Client/Builder/HttpMessageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
using System.Net.Http;
using Atc.Rest.Client.Serialization;
namespace Atc.Rest.Client.Builder;

namespace Atc.Rest.Client.Builder
internal class HttpMessageFactory : IHttpMessageFactory
{
internal class HttpMessageFactory : IHttpMessageFactory
{
private readonly IContractSerializer serializer;
private readonly IContractSerializer serializer;

public HttpMessageFactory(IContractSerializer serializer)
{
this.serializer = serializer;
}
public HttpMessageFactory(
IContractSerializer serializer)
{
this.serializer = serializer;
}

public IMessageRequestBuilder FromTemplate(string pathTemplate)
=> new MessageRequestBuilder(pathTemplate, serializer);
public IMessageRequestBuilder FromTemplate(
string pathTemplate)
=> new MessageRequestBuilder(
pathTemplate,
serializer);

public IMessageResponseBuilder FromResponse(HttpResponseMessage? response)
=> new MessageResponseBuilder(response, serializer);
}
public IMessageResponseBuilder FromResponse(
HttpResponseMessage? response)
=> new MessageResponseBuilder(
response,
serializer);
}
40 changes: 19 additions & 21 deletions src/Atc.Rest.Client/Builder/IHttpMessageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
using System;
using System.Net.Http;
namespace Atc.Rest.Client.Builder;

namespace Atc.Rest.Client.Builder
/// <summary>
/// Represents an HTTP message factory that can create both the <see cref="IMessageRequestBuilder"/>
/// and <see cref="IMessageRequestBuilder"/>, used to provide input to
/// and processes responses from an HTTP exchange.
/// </summary>
public interface IHttpMessageFactory
{
/// <summary>
/// Represents a HTTP message factory that can create both the <see cref="IMessageRequestBuilder"/>
/// and <see cref="IMessageRequestBuilder"/>, used to provide input to
/// and processes responses from an HTTP exchange.
/// Start building a <see cref="HttpRequestMessage"/> with the
/// returned <see cref="IMessageRequestBuilder"/>, which will use the provided
/// <paramref name="pathTemplate"/> as the request URI.
/// </summary>
public interface IHttpMessageFactory
{
/// <summary>
/// Start building a <see cref="HttpRequestMessage"/> with the
/// returned <see cref="IMessageRequestBuilder"/>, which will use the provided
/// <paramref name="pathTemplate"/> as the request URI.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="pathTemplate"/> is null.</exception>
/// <param name="pathTemplate">The relative URI to request. Can contain tokens,
/// that will be replaced with real values passed to the <see cref="IMessageRequestBuilder.WithPathParameter(string, object?)"/>
/// method.</param>
/// <returns>A new <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder FromTemplate(string pathTemplate);
/// <exception cref="ArgumentNullException">Thrown when <paramref name="pathTemplate"/> is null.</exception>
/// <param name="pathTemplate">The relative URI to request. Can contain tokens,
/// that will be replaced with real values passed to the <see cref="IMessageRequestBuilder.WithPathParameter(string, object?)"/>
/// method.</param>
/// <returns>A new <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder FromTemplate(
string pathTemplate);

IMessageResponseBuilder FromResponse(HttpResponseMessage? response);
}
IMessageResponseBuilder FromResponse(
HttpResponseMessage? response);
}
107 changes: 51 additions & 56 deletions src/Atc.Rest.Client/Builder/IMessageRequestBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
using System;
using System.Net.Http;
using Atc.Rest.Client.Serialization;
namespace Atc.Rest.Client.Builder;

namespace Atc.Rest.Client.Builder
/// <summary>
/// A message request builder can be used to build a <see cref="HttpRequestMessage"/>.
/// </summary>
public interface IMessageRequestBuilder
{
/// <summary>
/// A message request builder can be used to build a <see cref="HttpRequestMessage"/>.
/// Adds a value to a path parameter in a path template passed to the constructor of the <see cref="IMessageRequestBuilder"/>.
/// </summary>
public interface IMessageRequestBuilder
{
/// <summary>
/// Adds a value to a path parameter in a path template passed to the constructor of the <see cref="IMessageRequestBuilder"/>.
/// </summary>
/// <remarks>
/// A <see cref="IMessageRequestBuilder"/> implementation is expected to get passed a path template with
/// optional path parameters inside, which this method will replace with the <paramref name="value"/>.
/// </remarks>
/// <param name="name">Name of the path parameter in the template path.</param>
/// <param name="value">Value to use as the path parameter.</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is null or whitespace.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="value"/> is null or whitespace.</exception>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithPathParameter(string name, object? value);
/// <remarks>
/// A <see cref="IMessageRequestBuilder"/> implementation is expected to get passed a path template with
/// optional path parameters inside, which this method will replace with the <paramref name="value"/>.
/// </remarks>
/// <param name="name">Name of the path parameter in the template path.</param>
/// <param name="value">Value to use as the path parameter.</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is null or whitespace.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="value"/> is null or whitespace.</exception>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithPathParameter(string name, object? value);

/// <summary>
/// Adds a value to a header parameter in the headers.
/// </summary>
/// <param name="name">Name of the header parameter.</param>
/// <param name="value">Value to use as the header parameter.</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is null or whitespace.</exception>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithHeaderParameter(string name, object? value);
/// <summary>
/// Adds a value to a header parameter in the headers.
/// </summary>
/// <param name="name">Name of the header parameter.</param>
/// <param name="value">Value to use as the header parameter.</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is null or whitespace.</exception>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithHeaderParameter(string name, object? value);

/// <summary>
/// Adds a query parameter to the created request URL.
/// </summary>
/// <remarks>
/// If the <paramref name="value"/> is null, the query parameter is not added.
/// </remarks>
/// <param name="name">Name of the query parameter.</param>
/// <param name="value">Value of the query parameter.</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is null or whitespace.</exception>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithQueryParameter(string name, object? value);
/// <summary>
/// Adds a query parameter to the created request URL.
/// </summary>
/// <remarks>
/// If the <paramref name="value"/> is null, the query parameter is not added.
/// </remarks>
/// <param name="name">Name of the query parameter.</param>
/// <param name="value">Value of the query parameter.</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is null or whitespace.</exception>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithQueryParameter(string name, object? value);

/// <summary>
/// Adds the body of the request.
/// </summary>
/// <remarks>
/// The builder should use a <see cref="IContractSerializer"/> to serialize <paramref name="body"/>.
/// </remarks>
/// <typeparam name="TBody">The type of object to add as the body of the request.</typeparam>
/// <param name="body">The body to add to the request.</param>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithBody<TBody>(TBody body);
/// <summary>
/// Adds the body of the request.
/// </summary>
/// <remarks>
/// The builder should use a <see cref="IContractSerializer"/> to serialize <paramref name="body"/>.
/// </remarks>
/// <typeparam name="TBody">The type of object to add as the body of the request.</typeparam>
/// <param name="body">The body to add to the request.</param>
/// <returns>The <see cref="IMessageRequestBuilder"/>.</returns>
IMessageRequestBuilder WithBody<TBody>(TBody body);

/// <summary>
/// Builds a <see cref="HttpRequestMessage"/> with the added content.
/// </summary>
/// <param name="method">The <see cref="HttpMethod"/> to use in the request.</param>
/// <returns>The created <see cref="HttpRequestMessage"/>.</returns>
HttpRequestMessage Build(HttpMethod method);
}
/// <summary>
/// Builds a <see cref="HttpRequestMessage"/> with the added content.
/// </summary>
/// <param name="method">The <see cref="HttpMethod"/> to use in the request.</param>
/// <returns>The created <see cref="HttpRequestMessage"/>.</returns>
HttpRequestMessage Build(HttpMethod method);
}
44 changes: 22 additions & 22 deletions src/Atc.Rest.Client/Builder/IMessageResponseBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace Atc.Rest.Client.Builder;

namespace Atc.Rest.Client.Builder
public interface IMessageResponseBuilder
{
public interface IMessageResponseBuilder
{
IMessageResponseBuilder AddSuccessResponse(HttpStatusCode statusCode);
IMessageResponseBuilder AddSuccessResponse(
HttpStatusCode statusCode);

IMessageResponseBuilder AddSuccessResponse<TResponseContent>(HttpStatusCode statusCode);
IMessageResponseBuilder AddSuccessResponse<TResponseContent>(
HttpStatusCode statusCode);

IMessageResponseBuilder AddErrorResponse(HttpStatusCode statusCode);
IMessageResponseBuilder AddErrorResponse(
HttpStatusCode statusCode);

IMessageResponseBuilder AddErrorResponse<TResponseContent>(HttpStatusCode statusCode);
IMessageResponseBuilder AddErrorResponse<TResponseContent>(
HttpStatusCode statusCode);

Task<TResult> BuildResponseAsync<TResult>(
Func<EndpointResponse, TResult> factory,
CancellationToken cancellationToken);
Task<TResult> BuildResponseAsync<TResult>(
Func<EndpointResponse, TResult> factory,
CancellationToken cancellationToken);

Task<EndpointResponse<TSuccessContent>>
BuildResponseAsync<TSuccessContent>(CancellationToken cancellationToken)
where TSuccessContent : class;
Task<EndpointResponse<TSuccessContent>>
BuildResponseAsync<TSuccessContent>(
CancellationToken cancellationToken)
where TSuccessContent : class;

Task<EndpointResponse<TSuccessContent, TErrorContent>>
BuildResponseAsync<TSuccessContent, TErrorContent>(CancellationToken cancellationToken)
where TSuccessContent : class
where TErrorContent : class;
}
Task<EndpointResponse<TSuccessContent, TErrorContent>>
BuildResponseAsync<TSuccessContent, TErrorContent>(
CancellationToken cancellationToken)
where TSuccessContent : class
where TErrorContent : class;
}
Loading

0 comments on commit 090d8a5

Please sign in to comment.