Fix Sonarqube issues

This commit is contained in:
Stef Heyenrath
2020-08-13 14:14:04 +02:00
parent 9665729e58
commit 7abf56eafa
15 changed files with 63 additions and 93 deletions

View File

@@ -45,7 +45,18 @@ namespace WireMock
/// </summary> /// </summary>
object StatusCode { get; } object StatusCode { get; }
//void AddHeader(string name, params string[] values); /// <summary>
//void AddHeader(string name, string value); /// Adds the header.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
void AddHeader(string name, string value);
/// <summary>
/// Adds the header.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="values">The values.</param>
void AddHeader(string name, params string[] values);
} }
} }

View File

@@ -3,78 +3,54 @@ using WireMock.Matchers.Request;
namespace WireMock.Logging namespace WireMock.Logging
{ {
/// <summary>
/// ILogEntry
/// </summary>
public interface ILogEntry public interface ILogEntry
{ {
/// <summary> /// <summary>
/// Gets the unique identifier. /// Gets the unique identifier.
/// </summary> /// </summary>
/// <value>
/// The unique identifier.
/// </value>
Guid Guid { get; } Guid Guid { get; }
/// <summary> /// <summary>
/// Gets the mapping unique identifier. /// Gets the mapping unique identifier.
/// </summary> /// </summary>
/// <value>
/// The mapping unique identifier.
/// </value>
Guid? MappingGuid { get; } Guid? MappingGuid { get; }
/// <summary> /// <summary>
/// Gets the mapping unique title. /// Gets the mapping unique title.
/// </summary> /// </summary>
/// <value>
/// The mapping unique title.
/// </value>
string MappingTitle { get; } string MappingTitle { get; }
/// <summary> /// <summary>
/// Gets the partial mapping unique identifier. /// Gets the partial mapping unique identifier.
/// </summary> /// </summary>
/// <value>
/// The mapping unique identifier.
/// </value>
Guid? PartialMappingGuid { get; } Guid? PartialMappingGuid { get; }
/// <summary> /// <summary>
/// Gets the partial mapping unique title. /// Gets the partial mapping unique title.
/// </summary> /// </summary>
/// <value>
/// The mapping unique title.
/// </value>
string PartialMappingTitle { get; } string PartialMappingTitle { get; }
/// <summary> /// <summary>
/// Gets the partial match result. /// Gets the partial match result.
/// </summary> /// </summary>
/// <value>
/// The request match result.
/// </value>
IRequestMatchResult PartialMatchResult { get; } IRequestMatchResult PartialMatchResult { get; }
/// <summary> /// <summary>
/// Gets the request match result. /// Gets the request match result.
/// </summary> /// </summary>
/// <value>
/// The request match result.
/// </value>
IRequestMatchResult RequestMatchResult { get; } IRequestMatchResult RequestMatchResult { get; }
/// <summary> /// <summary>
/// Gets the request message. /// Gets the request message.
/// </summary> /// </summary>
/// <value>
/// The request message.
/// </value>
IRequestMessage RequestMessage { get; } IRequestMessage RequestMessage { get; }
/// <summary> /// <summary>
/// Gets the response message. /// Gets the response message.
/// </summary> /// </summary>
/// <value>
/// The response message.
/// </value>
IResponseMessage ResponseMessage { get; } IResponseMessage ResponseMessage { get; }
} }
} }

View File

@@ -2,10 +2,19 @@
namespace WireMock.Matchers.Request namespace WireMock.Matchers.Request
{ {
/// <summary>
/// MatchDetail
/// </summary>
public class MatchDetail public class MatchDetail
{ {
/// <summary>
/// Gets or sets the type of the matcher.
/// </summary>
public Type MatcherType { get; set; } public Type MatcherType { get; set; }
/// <summary>
/// Gets or sets the score between 0.0 and 1.0
/// </summary>
public double Score { get; set; } public double Score { get; set; }
} }
} }

View File

@@ -7,8 +7,6 @@ using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using RandomDataGenerator.FieldOptions; using RandomDataGenerator.FieldOptions;
using RandomDataGenerator.Randomizers; using RandomDataGenerator.Randomizers;
using WireMock.Exceptions;
using WireMock.Handlers;
using WireMock.Http; using WireMock.Http;
using WireMock.ResponseBuilders; using WireMock.ResponseBuilders;
using WireMock.Types; using WireMock.Types;

View File

@@ -2,9 +2,7 @@ using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using WireMock.Logging; using WireMock.Logging;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using WireMock.Matchers; using WireMock.Matchers;
using Newtonsoft.Json;
using WireMock.Http; using WireMock.Http;
using WireMock.Owin.Mappers; using WireMock.Owin.Mappers;
using WireMock.Serialization; using WireMock.Serialization;

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using WireMock.Handlers; using WireMock.Handlers;
using WireMock.Logging; using WireMock.Logging;
using WireMock.Matchers; using WireMock.Matchers;

View File

@@ -60,7 +60,7 @@ namespace WireMock.ResponseBuilders
[PublicAPI] [PublicAPI]
public static IResponseBuilder Create([CanBeNull] ResponseMessage responseMessage = null) public static IResponseBuilder Create([CanBeNull] ResponseMessage responseMessage = null)
{ {
var message = responseMessage ?? new ResponseMessage(); // { StatusCode = (int)HttpStatusCode.OK }; var message = responseMessage ?? new ResponseMessage();
return new Response(message); return new Response(message);
} }

View File

@@ -35,21 +35,13 @@ namespace WireMock
/// <inheritdoc cref="IResponseMessage.FaultPercentage" /> /// <inheritdoc cref="IResponseMessage.FaultPercentage" />
public double? FaultPercentage { get; set; } public double? FaultPercentage { get; set; }
/// <summary> /// <inheritdoc cref="IResponseMessage.AddHeader(string, string)" />
/// Adds the header.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddHeader(string name, string value) public void AddHeader(string name, string value)
{ {
Headers.Add(name, new WireMockList<string>(value)); Headers.Add(name, new WireMockList<string>(value));
} }
/// <summary> /// <inheritdoc cref="IResponseMessage.AddHeader(string, string[])" />
/// Adds the header.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="values">The values.</param>
public void AddHeader(string name, params string[] values) public void AddHeader(string name, params string[] values)
{ {
Check.NotNullOrEmpty(values, nameof(values)); Check.NotNullOrEmpty(values, nameof(values));

View File

@@ -95,21 +95,6 @@ namespace WireMock.Serialization
} }
} }
private ExactObjectMatcher CreateExactObjectMatcher(MatchBehaviour matchBehaviour, string stringPattern, bool throwException)
{
byte[] bytePattern;
try
{
bytePattern = Convert.FromBase64String(stringPattern);
}
catch
{
throw new ArgumentException($"Matcher 'ExactObjectMatcher' has invalid pattern. The pattern value '{stringPattern}' is not a Base64String.", nameof(stringPattern));
}
return new ExactObjectMatcher(matchBehaviour, bytePattern, throwException);
}
public MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers) public MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers)
{ {
return matchers?.Select(Map).Where(m => m != null).ToArray(); return matchers?.Select(Map).Where(m => m != null).ToArray();
@@ -154,5 +139,20 @@ namespace WireMock.Serialization
Patterns = patterns.Length > 1 ? patterns : null Patterns = patterns.Length > 1 ? patterns : null
}; };
} }
private ExactObjectMatcher CreateExactObjectMatcher(MatchBehaviour matchBehaviour, string stringPattern, bool throwException)
{
byte[] bytePattern;
try
{
bytePattern = Convert.FromBase64String(stringPattern);
}
catch
{
throw new ArgumentException($"Matcher 'ExactObjectMatcher' has invalid pattern. The pattern value '{stringPattern}' is not a Base64String.", nameof(stringPattern));
}
return new ExactObjectMatcher(matchBehaviour, bytePattern, throwException);
}
} }
} }

View File

@@ -833,9 +833,9 @@ namespace WireMock.Server
if (requestModel.Params != null) if (requestModel.Params != null)
{ {
foreach (var paramModel in requestModel.Params.Where(c => c.Matchers != null)) foreach (var paramModel in requestModel.Params.Where(p => p != null && p.Matchers != null))
{ {
bool ignoreCase = paramModel?.IgnoreCase ?? false; bool ignoreCase = paramModel.IgnoreCase == true;
requestBuilder = requestBuilder.WithParam(paramModel.Name, ignoreCase, paramModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray()); requestBuilder = requestBuilder.WithParam(paramModel.Name, ignoreCase, paramModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
} }
} }

View File

@@ -184,6 +184,17 @@ namespace WireMock.Server
ReadStaticMappings = true ReadStaticMappings = true
}); });
} }
/// <summary>
/// Initializes a new instance of the <see cref="WireMockServer"/> class.
/// </summary>
/// <param name="settings">The settings.</param>
/// <exception cref="WireMockException">
/// Service start failed with error: {_httpServer.RunningException.Message}
/// or
/// Service start failed with error: {startTask.Exception.Message}
/// </exception>
/// <exception cref="TimeoutException">Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}</exception>
protected WireMockServer(IWireMockServerSettings settings) protected WireMockServer(IWireMockServerSettings settings)
{ {
_settings = settings; _settings = settings;
@@ -422,7 +433,7 @@ namespace WireMock.Server
{ {
_options.Scenarios.Clear(); _options.Scenarios.Clear();
} }
/// <inheritdoc cref="IWireMockServer.WithMapping(MappingModel[])" /> /// <inheritdoc cref="IWireMockServer.WithMapping(MappingModel[])" />
[PublicAPI] [PublicAPI]
public IWireMockServer WithMapping(params MappingModel[] mappings) public IWireMockServer WithMapping(params MappingModel[] mappings)

View File

@@ -1,5 +1,8 @@
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <summary>
/// IWebProxySettings
/// </summary>
public interface IWebProxySettings public interface IWebProxySettings
{ {
/// <summary> /// <summary>

View File

@@ -2,6 +2,7 @@
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <seealso cref="IWebProxySettings" />
public class WebProxySettings : IWebProxySettings public class WebProxySettings : IWebProxySettings
{ {
/// <inheritdoc cref="IWebProxySettings.Address"/> /// <inheritdoc cref="IWebProxySettings.Address"/>

View File

@@ -1,9 +1,7 @@
using HandlebarsDotNet; namespace WireMock.Transformers
namespace WireMock.Transformers
{ {
interface IHandlebarsContextFactory interface IHandlebarsContextFactory
{ {
IHandlebarsContext Create(); IHandlebarsContext Create();
} }
} }

View File

@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection;
using JetBrains.Annotations; using JetBrains.Annotations;
// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs // Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
@@ -96,19 +95,6 @@ namespace WireMock.Validation
return value; return value;
} }
//public static string NullButNotEmpty(string value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
//{
// if (!ReferenceEquals(value, null)
// && (value.Length == 0))
// {
// NotNullOrEmpty(parameterName, nameof(parameterName));
// throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
// }
// return value;
//}
public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName) public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
where T : class where T : class
{ {
@@ -123,17 +109,5 @@ namespace WireMock.Validation
return value; return value;
} }
//public static Type ValidEntityType(Type value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
//{
// if (!value.GetTypeInfo().IsClass)
// {
// NotNullOrEmpty(parameterName, nameof(parameterName));
// throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
// }
// return value;
//}
} }
} }