Skip to content

Commit

Permalink
Fix Sonarqube issues
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Aug 13, 2020
1 parent 9665729 commit 7abf56e
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 93 deletions.
15 changes: 13 additions & 2 deletions src/WireMock.Net.Abstractions/IResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ public interface IResponseMessage
/// </summary>
object StatusCode { get; }

//void AddHeader(string name, params string[] values);
//void AddHeader(string name, string value);
/// <summary>
/// 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);
}
}
30 changes: 3 additions & 27 deletions src/WireMock.Net.Abstractions/Logging/ILogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,54 @@

namespace WireMock.Logging
{
/// <summary>
/// ILogEntry
/// </summary>
public interface ILogEntry
{
/// <summary>
/// Gets the unique identifier.
/// </summary>
/// <value>
/// The unique identifier.
/// </value>
Guid Guid { get; }

/// <summary>
/// Gets the mapping unique identifier.
/// </summary>
/// <value>
/// The mapping unique identifier.
/// </value>
Guid? MappingGuid { get; }

/// <summary>
/// Gets the mapping unique title.
/// </summary>
/// <value>
/// The mapping unique title.
/// </value>
string MappingTitle { get; }

/// <summary>
/// Gets the partial mapping unique identifier.
/// </summary>
/// <value>
/// The mapping unique identifier.
/// </value>
Guid? PartialMappingGuid { get; }

/// <summary>
/// Gets the partial mapping unique title.
/// </summary>
/// <value>
/// The mapping unique title.
/// </value>
string PartialMappingTitle { get; }

/// <summary>
/// Gets the partial match result.
/// </summary>
/// <value>
/// The request match result.
/// </value>
IRequestMatchResult PartialMatchResult { get; }

/// <summary>
/// Gets the request match result.
/// </summary>
/// <value>
/// The request match result.
/// </value>
IRequestMatchResult RequestMatchResult { get; }

/// <summary>
/// Gets the request message.
/// </summary>
/// <value>
/// The request message.
/// </value>
IRequestMessage RequestMessage { get; }

/// <summary>
/// Gets the response message.
/// </summary>
/// <value>
/// The response message.
/// </value>
IResponseMessage ResponseMessage { get; }
}
}
9 changes: 9 additions & 0 deletions src/WireMock.Net.Abstractions/Matchers/Request/MatchDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

namespace WireMock.Matchers.Request
{
/// <summary>
/// MatchDetail
/// </summary>
public class MatchDetail
{
/// <summary>
/// Gets or sets the type of the matcher.
/// </summary>
public Type MatcherType { get; set; }

/// <summary>
/// Gets or sets the score between 0.0 and 1.0
/// </summary>
public double Score { get; set; }
}
}
2 changes: 0 additions & 2 deletions src/WireMock.Net/Owin/Mappers/OwinResponseMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Newtonsoft.Json;
using RandomDataGenerator.FieldOptions;
using RandomDataGenerator.Randomizers;
using WireMock.Exceptions;
using WireMock.Handlers;
using WireMock.Http;
using WireMock.ResponseBuilders;
using WireMock.Types;
Expand Down
2 changes: 0 additions & 2 deletions src/WireMock.Net/Owin/WireMockMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Threading.Tasks;
using WireMock.Logging;
using System.Linq;
using System.Text.RegularExpressions;
using WireMock.Matchers;
using Newtonsoft.Json;
using WireMock.Http;
using WireMock.Owin.Mappers;
using WireMock.Serialization;
Expand Down
1 change: 0 additions & 1 deletion src/WireMock.Net/Owin/WireMockMiddlewareOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/ResponseBuilders/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public partial class Response : IResponseBuilder
[PublicAPI]
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);
}

Expand Down
12 changes: 2 additions & 10 deletions src/WireMock.Net/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,13 @@ public class ResponseMessage : IResponseMessage
/// <inheritdoc cref="IResponseMessage.FaultPercentage" />
public double? FaultPercentage { get; set; }

/// <summary>
/// Adds the header.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <inheritdoc cref="IResponseMessage.AddHeader(string, string)" />
public void AddHeader(string name, string value)
{
Headers.Add(name, new WireMockList<string>(value));
}

/// <summary>
/// Adds the header.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="values">The values.</param>
/// <inheritdoc cref="IResponseMessage.AddHeader(string, string[])" />
public void AddHeader(string name, params string[] values)
{
Check.NotNullOrEmpty(values, nameof(values));
Expand Down
30 changes: 15 additions & 15 deletions src/WireMock.Net/Serialization/MatcherMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,6 @@ public IMatcher Map([CanBeNull] MatcherModel matcher)
}
}

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)
{
return matchers?.Select(Map).Where(m => m != null).ToArray();
Expand Down Expand Up @@ -154,5 +139,20 @@ public MatcherModel Map([CanBeNull] IMatcher matcher)
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);
}
}
}
4 changes: 2 additions & 2 deletions src/WireMock.Net/Server/WireMockServer.Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,9 @@ private IRequestBuilder InitRequestBuilder(RequestModel requestModel, bool pathO

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());
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/WireMock.Net/Server/WireMockServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ public static WireMockServer StartWithAdminInterfaceAndReadStaticMappings(params
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)
{
_settings = settings;
Expand Down Expand Up @@ -422,7 +433,7 @@ public void ResetScenarios()
{
_options.Scenarios.Clear();
}

/// <inheritdoc cref="IWireMockServer.WithMapping(MappingModel[])" />
[PublicAPI]
public IWireMockServer WithMapping(params MappingModel[] mappings)
Expand Down
3 changes: 3 additions & 0 deletions src/WireMock.Net/Settings/IWebProxySettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace WireMock.Settings
{
/// <summary>
/// IWebProxySettings
/// </summary>
public interface IWebProxySettings
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/WireMock.Net/Settings/WebProxySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace WireMock.Settings
{
/// <seealso cref="IWebProxySettings" />
public class WebProxySettings : IWebProxySettings
{
/// <inheritdoc cref="IWebProxySettings.Address"/>
Expand Down
6 changes: 2 additions & 4 deletions src/WireMock.Net/Transformers/IHandlebarsContextFactory.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using HandlebarsDotNet;

namespace WireMock.Transformers
namespace WireMock.Transformers
{
interface IHandlebarsContextFactory
{
IHandlebarsContext Create();
}
}
}
26 changes: 0 additions & 26 deletions src/WireMock.Net/Validation/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;

// Copied from https:/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
Expand Down Expand Up @@ -96,19 +95,6 @@ public static string NotNullOrEmpty(string value, [InvokerParameterName, Validat
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)
where T : class
{
Expand All @@ -123,17 +109,5 @@ public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName, Vali

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;
//}
}
}

0 comments on commit 7abf56e

Please sign in to comment.