Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reorganize internals #118

Merged
merged 2 commits into from
Sep 29, 2024
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
5 changes: 0 additions & 5 deletions src/MockHttp.Json/DeprecationWarnings.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/MockHttp/Responses/BitRate.cs → src/MockHttp/BitRate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using MockHttp.IO;

// ReSharper disable once CheckNamespace
namespace MockHttp;
Expand Down Expand Up @@ -85,7 +84,7 @@ public static BitRate OneGigabit()
/// </summary>
/// <param name="bitRate"></param>
/// <returns></returns>
public static explicit operator int (BitRate bitRate)
public static explicit operator int(BitRate bitRate)
{
return ToInt32(bitRate);
}
Expand All @@ -95,7 +94,7 @@ public static explicit operator int (BitRate bitRate)
/// </summary>
/// <param name="bitRate"></param>
/// <returns></returns>
public static explicit operator BitRate (int bitRate)
public static explicit operator BitRate(int bitRate)
{
return FromInt32(bitRate);
}
Expand Down
5 changes: 0 additions & 5 deletions src/MockHttp/DeprecationWarnings.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/MockHttp/Extensions/IRespondsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MockHttp.Language;
using MockHttp.Language.Flow;
using MockHttp.Language.Flow.Response;
using MockHttp.Response;
using MockHttp.Responses;

namespace MockHttp;
Expand All @@ -16,7 +17,7 @@
/// </summary>
/// <param name="responds"></param>
/// <param name="response">The function that provides the response message to return for a request.</param>
public static TResult Respond<TResult>(this IResponds<TResult> responds, Func<HttpResponseMessage> response)

Check warning on line 20 in src/MockHttp/Extensions/IRespondsExtensions.cs

View workflow job for this annotation

GitHub Actions / analysis

All 'Respond' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
where TResult : IResponseResult
{
if (response is null)
Expand Down
2 changes: 2 additions & 0 deletions src/MockHttp/Extensions/RequestMatchingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Linq.Expressions;
using System.Net.Http.Headers;
using System.Text;
using MockHttp.Extensions;
using MockHttp.Http;
using MockHttp.Matchers;
using MockHttp.Patterns;
using MockHttp.Request;
using static MockHttp.Http.UriExtensions;

namespace MockHttp;
Expand Down
3 changes: 2 additions & 1 deletion src/MockHttp/Extensions/ResponseBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using MockHttp.Extensions;
using MockHttp.Http;
using MockHttp.IO;
using MockHttp.Language.Flow.Response;
using MockHttp.Language.Response;
using MockHttp.Responses;
using MockHttp.Response.Behaviors;

namespace MockHttp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics.CodeAnalysis;

namespace MockHttp;
namespace MockHttp.Extensions;

internal static class HttpContentExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MockHttp.Matchers;
using MockHttp.Responses;

namespace MockHttp;
namespace MockHttp.Extensions;

internal static class HttpRequestMatcherExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MockHttp;
namespace MockHttp.Extensions;

internal static class ListExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Specialized;

namespace MockHttp;
namespace MockHttp.Extensions;

internal static class NameValueCollectionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MockHttp;
namespace MockHttp.Extensions;

internal static class ReadOnlyListExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma warning disable S4136
using System.Net;

namespace MockHttp.Responses;
namespace MockHttp.Http;

internal class EmptyContent : HttpContent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@

namespace MockHttp.Http;

internal enum HttpHeaderMatchType
{
/// <summary>
/// Header and value(s) match exactly.
/// </summary>
Exact,
/// <summary>
/// Header name matches, values are ignored.
/// </summary>
HeaderNameOnly,
/// <summary>
/// Header name matches and all values of left comparand must be in right.
/// </summary>
HeaderNameAndPartialValues
}

internal sealed class HttpHeaderEqualityComparer : IEqualityComparer<KeyValuePair<string, IEnumerable<string>>>
{
private readonly HttpHeaderMatchType? _matchType;
Expand Down Expand Up @@ -62,8 +46,8 @@ public bool Equals(KeyValuePair<string, IEnumerable<string>> x, KeyValuePair<str
.All(xValue =>
{
string[] headerValues = HttpHeadersCollection.ParseHttpHeaderValue(yValue).ToArray();
return !_valuePatternMatcher.HasValue && headerValues.Contains(xValue)
|| (_valuePatternMatcher.HasValue && headerValues.Any(_valuePatternMatcher.Value.IsMatch));
return (!_valuePatternMatcher.HasValue && headerValues.Contains(xValue))
|| (_valuePatternMatcher.HasValue && headerValues.Any(_valuePatternMatcher.Value.IsMatch));
})
))
{
Expand Down
19 changes: 19 additions & 0 deletions src/MockHttp/Internal/Http/HttpHeaderMatchType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace MockHttp.Http;

internal enum HttpHeaderMatchType
{
/// <summary>
/// Header and value(s) match exactly.
/// </summary>
Exact,

/// <summary>
/// Header name matches, values are ignored.
/// </summary>
HeaderNameOnly,

/// <summary>
/// Header name matches and all values of left comparand must be in right.
/// </summary>
HeaderNameAndPartialValues
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MockHttp.Matchers;

namespace MockHttp;
namespace MockHttp.Request;

/// <summary>
/// A builder to configure request matchers, accepting all matchers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MockHttp.Matchers;

namespace MockHttp;
namespace MockHttp.Request;

internal sealed class InvertRequestMatching : RequestMatching
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MockHttp.Responses;
using MockHttp.Responses;

namespace MockHttp.Response.Behaviors;

internal sealed class HttpContentBehavior
: IResponseBehavior
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MockHttp.Http;
using MockHttp.Responses;

namespace MockHttp.Responses;
namespace MockHttp.Response.Behaviors;

internal sealed class HttpHeaderBehavior
: IResponseBehavior
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MockHttp.Responses;
using MockHttp.Responses;

internal class NetworkLatencyBehavior
namespace MockHttp.Response.Behaviors;

internal sealed class NetworkLatencyBehavior
: IResponseBehavior
{
private readonly NetworkLatency _networkLatency;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net;
using MockHttp.Responses;

namespace MockHttp.Responses;
namespace MockHttp.Response.Behaviors;

internal sealed class StatusCodeBehavior
: IResponseBehavior
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Runtime.InteropServices;
using MockHttp.Responses;
using MockHttp.Threading;

namespace MockHttp.Responses;
namespace MockHttp.Response.Behaviors;

internal sealed class TimeoutBehavior
: IResponseBehavior
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Net;
using MockHttp.IO;
using MockHttp.Responses;

namespace MockHttp.Responses;
namespace MockHttp.Response.Behaviors;

internal sealed class TransferRateBehavior : IResponseBehavior
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MockHttp.Responses;
using MockHttp.Responses;

namespace MockHttp.Response;

internal sealed class ExceptionStrategy : IResponseStrategy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MockHttp.Responses;
using MockHttp.Responses;

namespace MockHttp.Response;

internal sealed class ResponseFuncStrategy : IResponseStrategy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MockHttp.Responses;
using MockHttp.Http;
using MockHttp.Responses;

namespace MockHttp.Language.Flow.Response;

Expand Down
2 changes: 2 additions & 0 deletions src/MockHttp/Language/Flow/Response/ResponseBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Http.Headers;
using MockHttp.Extensions;
using MockHttp.Http;
using MockHttp.Response.Behaviors;
using MockHttp.Responses;

namespace MockHttp.Language.Flow.Response;
Expand Down
1 change: 1 addition & 0 deletions src/MockHttp/Language/Flow/SetupPhrase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using MockHttp.Response;
using MockHttp.Responses;

namespace MockHttp.Language.Flow;
Expand Down
1 change: 1 addition & 0 deletions src/MockHttp/Matchers/AnyMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using MockHttp.Extensions;
using MockHttp.Responses;

namespace MockHttp.Matchers;
Expand Down
1 change: 1 addition & 0 deletions src/MockHttp/Matchers/PartialContentMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using MockHttp.Extensions;

namespace MockHttp.Matchers;

Expand Down
3 changes: 2 additions & 1 deletion src/MockHttp/MockHttp.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=internal/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
1 change: 1 addition & 0 deletions src/MockHttp/MockHttpHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using System.Net;
using System.Text;
using MockHttp.Extensions;
using MockHttp.Language;
using MockHttp.Language.Flow;
using MockHttp.Matchers;
Expand Down
1 change: 1 addition & 0 deletions src/MockHttp/RequestMatching.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using MockHttp.Matchers;
using MockHttp.Request;

namespace MockHttp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using static MockHttp.BitRate;

namespace MockHttp.Responses;
namespace MockHttp;

public sealed class BitRateTests
{
Expand Down
2 changes: 1 addition & 1 deletion test/MockHttp.Tests/Extensions/IRespondsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using MockHttp.Language.Flow;
using MockHttp.Responses;

namespace MockHttp.Extensions;
namespace MockHttp;

public class IRespondsExtensionsTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Specialized;
using System.Collections.Specialized;
using System.Linq.Expressions;
using System.Net.Http.Headers;
using System.Text;
using System.Xml;
using MockHttp.Extensions;
using MockHttp.Http;
using MockHttp.Matchers;
using MockHttp.Responses;
using static MockHttp.Http.UriExtensions;

namespace MockHttp.Extensions;
namespace MockHttp;

public abstract class RequestMatchingExtensionsTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics;
using MockHttp.IO;
using Xunit.Abstractions;

namespace MockHttp;
namespace MockHttp.IO;

public sealed class RateLimitedStreamTests : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;

namespace MockHttp.Responses;
namespace MockHttp.Http;

public class EmptyContentTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MockHttp.Responses;
using MockHttp.Response;
using MockHttp.Responses;

namespace MockHttp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MockHttp.Matchers;

namespace MockHttp;
namespace MockHttp.Request;

public class AnyRequestMatchingTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;

namespace MockHttp;
namespace MockHttp.Request;

public sealed class InvertRequestMatchingTests : IDisposable
{
Expand Down
Loading
Loading