mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-28 20:01:46 +01:00
* Create WireMock.Net.MimePart project * . * REFACTOR * ILRepack * -- * ... * x * x * . * fix * public class MimePartMatcher * shared * min * . * <!--<DelaySign>true</DelaySign>--> * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace WireMock.Matchers.Request;
|
|
|
|
/// <summary>
|
|
/// RequestMatchResult
|
|
/// </summary>
|
|
public class RequestMatchResult : IRequestMatchResult
|
|
{
|
|
/// <inheritdoc />
|
|
public double TotalScore => MatchDetails.Sum(md => md.Score);
|
|
|
|
/// <inheritdoc />
|
|
public int TotalNumber => MatchDetails.Count;
|
|
|
|
/// <inheritdoc />
|
|
public bool IsPerfectMatch => Math.Abs(TotalScore - TotalNumber) < MatchScores.Tolerance;
|
|
|
|
/// <inheritdoc />
|
|
public double AverageTotalScore => TotalNumber == 0 ? MatchScores.Mismatch : TotalScore / TotalNumber;
|
|
|
|
/// <inheritdoc />
|
|
public IList<MatchDetail> MatchDetails { get; } = new List<MatchDetail>();
|
|
|
|
/// <inheritdoc />
|
|
public double AddScore(Type matcherType, double score, Exception? exception)
|
|
{
|
|
MatchDetails.Add(new MatchDetail { MatcherType = matcherType, Score = score, Exception = exception });
|
|
|
|
return score;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
|
|
/// </summary>
|
|
/// <param name="obj">An object to compare with this instance.</param>
|
|
/// <returns>
|
|
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes <paramref name="obj" /> in the sort order. Zero This instance occurs in the same position in the sort order as <paramref name="obj" />. Greater than zero This instance follows <paramref name="obj" /> in the sort order.
|
|
/// </returns>
|
|
public int CompareTo(object? obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
var compareObj = (RequestMatchResult)obj;
|
|
|
|
var averageTotalScoreResult = compareObj.AverageTotalScore.CompareTo(AverageTotalScore);
|
|
|
|
// In case the score is equal, prefer the one with the most matchers.
|
|
return averageTotalScoreResult == 0 ? compareObj.TotalNumber.CompareTo(TotalNumber) : averageTotalScoreResult;
|
|
}
|
|
} |