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

Feature Query String Matcher Comparisons #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pbolduc
Copy link

@pbolduc pbolduc commented Feb 17, 2024

This is initial version of being able to add string comparisons for query strings. It is to address #134. There is still more work that will need to be done before this should be merged. Additional unit tests and examples should be added as well. I still need to add optional parameters to the extension methods. Please consider this PR as draft. I would appreciate any feedback on the design and any changes you would like to see.

Example

Proposed extension method change:

public static MockedRequest WithQueryString(this MockedRequest source, string name, string value, QueryStringMatcherOptions? options = null);

Usage

mockHttp.Expect("/users/me")
        .WithQueryString("access_token", "Old_Token", options: new QueryStringMatcherOptions(value: StringComparer.OrdinalIgnoreCase))
        .Respond(HttpStatusCode.Unauthorized);

QueryStringMatcherOptions

/// <summary>
/// Provides options on how to match query strings.
/// </summary>
public sealed class QueryStringMatcherOptions
{
    /// <summary>
    /// Constructs a new instance of QueryStringMatcherOptions using the default ordinal comparison on keys and values.
    /// </summary>
    public QueryStringMatcherOptions() : this(StringComparer.Ordinal, StringComparer.Ordinal)
    {
    }

    /// <summary>
    /// Constructs a new instance of QueryStringMatcherOptions using the default ordinal comparison on keys and values.
    /// </summary>
    public QueryStringMatcherOptions(IEqualityComparer<string>? key = null, IEqualityComparer<string>? value = null)
    {
        KeyComparer = key ?? StringComparer.Ordinal;
        ValueComparer = value ?? StringComparer.Ordinal;
    }

    /// <summary>
    /// The comparer to use for keys
    /// </summary>
    public IEqualityComparer<string> KeyComparer { get; }

    /// <summary>
    /// The comparer to use for values
    /// </summary>
    public IEqualityComparer<string> ValueComparer { get; }
}

@pbolduc pbolduc changed the title Feature Query String Somparisons Feature Query String Matcher Comparisons Feb 17, 2024
@pbolduc pbolduc force-pushed the feature/query-string-comparisons branch from 724544b to e622845 Compare February 17, 2024 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant