Add link to TIOBE Index on main page + fix issues (#1137)

* Add TIOBE + include SonarAnalyzer.CSharp

* .

* cp

* Copyright © WireMock.Net

* more fixes

* fix

* xpath

* if (Matchers == null || !Matchers.Any())

* if (Matchers != null)

* ?

* .

* .
This commit is contained in:
Stef Heyenrath
2024-07-18 18:06:04 +02:00
committed by GitHub
parent baac83c9b9
commit 54edf0bebc
573 changed files with 1294 additions and 172 deletions

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if !NETSTANDARD1_3
using System;
using System.Globalization;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Text;
using WireMock.Matchers;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// ReSharper disable once CheckNamespace
namespace System;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if NET451 || NET452 || NET46 || NET451 || NET461 || NETSTANDARD1_3 || NETSTANDARD2_0
using System.Text.RegularExpressions;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if NETSTANDARD1_3
// ReSharper disable once CheckNamespace

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Constants;
internal static class WireMockConstants

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
namespace WireMock.Exceptions;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using System.Linq;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Reflection;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
namespace WireMock.Extensions;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using WireMock.Models;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using System.IO;
using WireMock.Util;
@@ -72,8 +74,8 @@ public class LocalFileSystemHandler : IFileSystemHandler
/// <inheritdoc cref="IFileSystemHandler.WriteMappingFile(string, string)"/>
public virtual void WriteMappingFile(string path, string text)
{
Guard.NotNullOrEmpty(path, nameof(path));
Guard.NotNull(text, nameof(text));
Guard.NotNullOrEmpty(path);
Guard.NotNull(text);
File.WriteAllText(path, text);
}
@@ -144,7 +146,7 @@ public class LocalFileSystemHandler : IFileSystemHandler
/// <inheritdoc cref="IFileSystemHandler.ReadFileAsString"/>
public virtual string ReadFileAsString(string filename)
{
return File.ReadAllText(AdjustPathForMappingFolder(Guard.NotNullOrEmpty(filename, nameof(filename))));
return File.ReadAllText(AdjustPathForMappingFolder(Guard.NotNullOrEmpty(filename)));
}
/// <inheritdoc cref="IFileSystemHandler.GetUnmatchedRequestsFolder"/>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Net.Http;
using System.Net.Http.Headers;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Net;
using System.Net.Http;
using WireMock.HttpsCertificate;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Linq;
using System.Net.Http;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Net.Http;
using System.Net.Http.Headers;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Security.Cryptography.X509Certificates;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Threading.Tasks;
using WireMock.Matchers.Request;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using WireMock.Admin.Mappings;
using WireMock.Matchers.Request;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq
namespace WireMock.Json;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq
using System.Linq.Dynamic.Core;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq
namespace WireMock.Json;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq
namespace WireMock.Json;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
// Copied from https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/src/Handlebars.Net.Helpers.DynamicLinq
using System;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using WireMock.Matchers.Request;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using Newtonsoft.Json;
using System;
using WireMock.Admin.Requests;
@@ -19,7 +21,10 @@ public class WireMockConsoleLogger : IWireMockLogger
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
}
catch { }
catch
{
// Ignored
}
}
/// <see cref="IWireMockLogger.Debug"/>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using WireMock.Admin.Requests;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Threading.Tasks;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using System.Text;

View File

@@ -1,4 +1,6 @@
namespace WireMock
// Copyright © WireMock.Net
namespace WireMock
{
/// <summary>
/// The registration callback.

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Net.Http.Headers;
using AnyOfTypes;
using WireMock.Models;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Linq;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if GRAPHQL
using System;
using System.Collections.Generic;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using Stef.Validation;
using WireMock.Types;
using WireMock.Util;
@@ -10,9 +12,14 @@ internal static class BodyDataMatchScoreCalculator
{
Guard.NotNull(matcher);
if (requestMessage == null)
{
return default;
}
if (matcher is NotNullOrEmptyMatcher notNullOrEmptyMatcher)
{
switch (requestMessage?.DetectedBodyType)
switch (requestMessage.DetectedBodyType)
{
case BodyType.Json:
case BodyType.String:
@@ -30,10 +37,10 @@ internal static class BodyDataMatchScoreCalculator
if (matcher is ExactObjectMatcher exactObjectMatcher)
{
// If the body is a byte array, try to match.
var detectedBodyType = requestMessage?.DetectedBodyType;
var detectedBodyType = requestMessage.DetectedBodyType;
if (detectedBodyType is BodyType.Bytes or BodyType.String or BodyType.FormUrlEncoded)
{
return exactObjectMatcher.IsMatch(requestMessage?.BodyAsBytes);
return exactObjectMatcher.IsMatch(requestMessage.BodyAsBytes);
}
}
@@ -41,26 +48,22 @@ internal static class BodyDataMatchScoreCalculator
if (matcher is IObjectMatcher objectMatcher)
{
// If the body is a JSON object, try to match.
if (requestMessage?.DetectedBodyType == BodyType.Json)
if (requestMessage.DetectedBodyType == BodyType.Json)
{
return objectMatcher.IsMatch(requestMessage.BodyAsJson);
}
// If the body is a byte array, try to match.
if (requestMessage?.DetectedBodyType == BodyType.Bytes)
if (requestMessage.DetectedBodyType == BodyType.Bytes)
{
return objectMatcher.IsMatch(requestMessage.BodyAsBytes);
}
}
// Check if the matcher is a IStringMatcher
if (matcher is IStringMatcher stringMatcher)
// In case the matcher is a IStringMatcher and If body is a Json or a String, use the BodyAsString to match on.
if (matcher is IStringMatcher stringMatcher && requestMessage.DetectedBodyType is BodyType.Json or BodyType.String or BodyType.FormUrlEncoded)
{
// If the body is a Json or a String, use the BodyAsString to match on.
if (requestMessage?.DetectedBodyType is BodyType.Json or BodyType.String or BodyType.FormUrlEncoded)
{
return stringMatcher.IsMatch(requestMessage.BodyAsString);
}
return stringMatcher.IsMatch(requestMessage.BodyAsString);
}
return default;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Threading;
using System.Threading.Tasks;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Threading;
using System.Threading.Tasks;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using AnyOfTypes;
using WireMock.Models;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using System.Linq.Dynamic.Core;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
internal static class MatchBehaviourHelper

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if MIMEKIT
using System;
using MimeKit;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if GRAPHQL
using System;
using GraphQL.Types;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if PROTOBUF
using System;
using System.Threading;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using System.Text.RegularExpressions;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers.Request;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using System.Linq;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using Stef.Validation;
using System;
using System.Collections.Generic;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;
@@ -76,8 +78,7 @@ public class RequestMessageGraphQLMatcher : IRequestMatcher
private static MatchResult CalculateMatchResult(IRequestMessage requestMessage, IMatcher matcher)
{
// Check if the matcher is a IStringMatcher
// If the body is a Json or a String, use the BodyAsString to match on.
// In case the matcher is a IStringMatcher and the body is a Json or a String, use the BodyAsString to match on.
if (matcher is IStringMatcher stringMatcher && requestMessage.BodyData?.DetectedBodyType is BodyType.Json or BodyType.String or BodyType.FormUrlEncoded)
{
return stringMatcher.IsMatch(requestMessage.BodyData.BodyAsString);

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Linq;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;
@@ -103,19 +105,14 @@ public class RequestMessageParamMatcher : IRequestMatcher
return MatchScores.Mismatch;
}
if (Matchers != null && Matchers.Any())
{
// Return the score based on Matchers and valuesPresentInRequestMessage
return CalculateScore(Matchers, valuesPresentInRequestMessage);
}
if (Matchers == null || !Matchers.Any())
{
// Matchers are null or not defined, and Key is present, just return Perfect.
return MatchScores.Perfect;
}
return MatchScores.Mismatch;
// Return the score based on Matchers and valuesPresentInRequestMessage
return CalculateScore(Matchers, valuesPresentInRequestMessage);
}
private static double CalculateScore(IReadOnlyList<IStringMatcher> matchers, WireMockList<string> valuesPresentInRequestMessage)

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using WireMock.Models;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Matchers.Request;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Linq;
using AnyOfTypes;
using SimMetrics.Net;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Linq;
using System.Text.RegularExpressions;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;
@@ -76,7 +78,7 @@ public class XPathMatcher : IStringMatcher
{
return CreateMatchResult(score);
}
score = MatchScores.ToScore(xPathEvaluator.Evaluate(_patterns, XmlNamespaceMap), MatchOperator);
}
catch (Exception exception)
@@ -86,7 +88,7 @@ public class XPathMatcher : IStringMatcher
return CreateMatchResult(score);
}
private MatchResult CreateMatchResult(double score, Exception? exception = null)
{
return new MatchResult(MatchBehaviourHelper.Convert(MatchBehaviour, score), exception);
@@ -103,8 +105,8 @@ public class XPathMatcher : IStringMatcher
/// <inheritdoc />
public string Name => nameof(XPathMatcher);
private class XPathEvaluator
private sealed class XPathEvaluator
{
private XmlDocument? _xmlDocument;
private XPathNavigator? _xpathNavigator;
@@ -126,15 +128,27 @@ public class XPathMatcher : IStringMatcher
public bool[] Evaluate(AnyOf<string, StringPattern>[] patterns, IEnumerable<XmlNamespace>? xmlNamespaceMap)
{
XmlNamespaceManager? xmlNamespaceManager = GetXmlNamespaceManager(xmlNamespaceMap);
return patterns
.Select(p =>
return _xpathNavigator == null ? [] : patterns.Select(pattern => true.Equals(Evaluate(_xpathNavigator, pattern, xmlNamespaceMap))).ToArray();
}
private object Evaluate(XPathNavigator navigator, AnyOf<string, StringPattern> pattern, IEnumerable<XmlNamespace>? xmlNamespaceMap)
{
var xpath = $"boolean({pattern.GetPattern()})";
var xmlNamespaceManager = GetXmlNamespaceManager(xmlNamespaceMap);
if (xmlNamespaceManager == null)
{
#if NETSTANDARD1_3
true.Equals(_xpathNavigator.Evaluate($"boolean({p.GetPattern()})", xmlNamespaceManager)))
return navigator.Evaluate(xpath);
#else
true.Equals(_xpathNavigator.XPath2Evaluate($"boolean({p.GetPattern()})", xmlNamespaceManager)))
return navigator.XPath2Evaluate(xpath);
#endif
}
#if NETSTANDARD1_3
return navigator.Evaluate(xpath, xmlNamespaceManager);
#else
return navigator.XPath2Evaluate(xpath, xmlNamespaceManager);
#endif
.ToArray();
}
private XmlNamespaceManager? GetXmlNamespaceManager(IEnumerable<XmlNamespace>? xmlNamespaceMap)
@@ -145,7 +159,7 @@ public class XPathMatcher : IStringMatcher
}
var nsManager = new XmlNamespaceManager(_xpathNavigator.NameTable);
foreach (XmlNamespace xmlNamespace in xmlNamespaceMap)
foreach (var xmlNamespace in xmlNamespaceMap)
{
nsManager.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri);
}

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Text;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using AnyOfTypes;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Models;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
namespace WireMock.Models;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using Stef.Validation;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Models;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using WireMock.Types;
using WireMock.Util;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if USE_ASPNETCORE && !NETSTANDARD1_3
using System;
using System.Collections.Generic;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if USE_ASPNETCORE && NETSTANDARD1_3
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
#if USE_ASPNETCORE
using System;
using System.Collections.Generic;

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
@@ -24,21 +26,15 @@ namespace WireMock.Owin
#if !USE_ASPNETCORE
public GlobalExceptionMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinResponseMapper responseMapper) : base(next)
{
Guard.NotNull(options, nameof(options));
Guard.NotNull(responseMapper, nameof(responseMapper));
_options = options;
_responseMapper = responseMapper;
_options = Guard.NotNull(options);
_responseMapper = Guard.NotNull(responseMapper);;
}
#else
public GlobalExceptionMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinResponseMapper responseMapper)
{
Guard.NotNull(options, nameof(options));
Guard.NotNull(responseMapper, nameof(responseMapper));
Next = next;
_options = options;
_responseMapper = responseMapper;
_options = Guard.NotNull(options);
_responseMapper = Guard.NotNull(responseMapper);
}
#endif

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
namespace WireMock.Owin;
/// <summary>

View File

@@ -1,3 +1,5 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using WireMock.Types;
using WireMock.Util;

Some files were not shown because too many files have changed in this diff Show More