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

Fix some SonarCloud issues #1058

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
using WireMock.Server;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions
namespace WireMock.FluentAssertions;

/// <summary>
/// Provides assertion methods to verify the number of calls made to a WireMock server.
/// This class is used in the context of FluentAssertions.
/// </summary>
public class WireMockANumberOfCallsAssertions
{
public class WireMockANumberOfCallsAssertions
{
private readonly IWireMockServer _server;
private readonly int _callsCount;
private readonly IWireMockServer _server;
private readonly int _callsCount;

public WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount)
{
_server = Guard.NotNull(server);
_callsCount = callsCount;
}
/// <summary>
/// Initializes a new instance of the <see cref="WireMockANumberOfCallsAssertions"/> class.
/// </summary>
/// <param name="server">The WireMock server to assert against.</param>
/// <param name="callsCount">The expected number of calls to assert.</param>
public WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount)
{
_server = Guard.NotNull(server);
_callsCount = callsCount;
}

public WireMockAssertions Calls()
{
return new WireMockAssertions(_server, _callsCount);
}
/// <summary>
/// Returns an instance of <see cref="WireMockAssertions"/> which can be used to assert the expected number of calls.
/// </summary>
/// <returns>A <see cref="WireMockAssertions"/> instance for asserting the number of calls to the server.</returns>
public WireMockAssertions Calls()
{
return new WireMockAssertions(_server, _callsCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,49 @@
using WireMock.Server;

// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions
namespace WireMock.FluentAssertions;

/// <summary>
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
/// </summary>
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
{
/// <summary>
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
/// Create a WireMockReceivedAssertions.
/// </summary>
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
/// <param name="server">The <see cref="IWireMockServer"/>.</param>
public WireMockReceivedAssertions(IWireMockServer server) : base(server)
{
/// <summary>
/// Create a WireMockReceivedAssertions.
/// </summary>
/// <param name="server">The <see cref="IWireMockServer"/>.</param>
public WireMockReceivedAssertions(IWireMockServer server) : base(server)
{
}

/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received no calls.
/// </summary>
/// <returns><see cref="WireMockAssertions"/></returns>
public WireMockAssertions HaveReceivedNoCalls()
{
return new WireMockAssertions(Subject, 0);
}
}

/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received a call.
/// </summary>
/// <returns><see cref="WireMockAssertions"/></returns>
public WireMockAssertions HaveReceivedACall()
{
return new WireMockAssertions(Subject, null);
}
/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received no calls.
/// </summary>
/// <returns><see cref="WireMockAssertions"/></returns>
public WireMockAssertions HaveReceivedNoCalls()
{
return new WireMockAssertions(Subject, 0);
}

/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received n-calls.
/// </summary>
/// <param name="callsCount"></param>
/// <returns><see cref="WireMockANumberOfCallsAssertions"/></returns>
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
{
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
}
/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received a call.
/// </summary>
/// <returns><see cref="WireMockAssertions"/></returns>
public WireMockAssertions HaveReceivedACall()
{
return new WireMockAssertions(Subject, null);
}

/// <inheritdoc />
protected override string Identifier => "wiremockserver";
/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received n-calls.
/// </summary>
/// <param name="callsCount"></param>
/// <returns><see cref="WireMockANumberOfCallsAssertions"/></returns>
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
{
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
}

/// <inheritdoc />
protected override string Identifier => "wiremockserver";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@ public interface IWireMockOpenApiParserExampleValues
/// <summary>
/// An example value for a Boolean.
/// </summary>
bool Boolean { get; set; }
bool Boolean { get; }

/// <summary>
/// An example value for an Integer.
/// </summary>
int Integer { get; set; }
int Integer { get; }

/// <summary>
/// An example value for a Float.
/// </summary>
float Float { get; set; }
float Float { get; }

/// <summary>
/// An example value for a Double.
/// </summary>
double Double { get; set; }
double Double { get; }

/// <summary>
/// An example value for a Date.
/// </summary>
Func<DateTime> Date { get; set; }
Func<DateTime> Date { get; }

/// <summary>
/// An example value for a DateTime.
/// </summary>
Func<DateTime> DateTime { get; set; }
Func<DateTime> DateTime { get; }

/// <summary>
/// An example value for Bytes.
/// </summary>
byte[] Bytes { get; set; }
byte[] Bytes { get; }

/// <summary>
/// An example value for a Object.
/// </summary>
object Object { get; set; }
object Object { get; }

/// <summary>
/// An example value for a String.
/// </summary>
string String { get; set; }
string String { get; }

/// <summary>
/// OpenApi Schema to generate dynamic examples more accurate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ namespace WireMock.Net.OpenApiParser.Settings;
public class WireMockOpenApiParserDynamicExampleValues : IWireMockOpenApiParserExampleValues
{
/// <inheritdoc />
public virtual bool Boolean { get => RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true; set { } }
public virtual bool Boolean => RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true;

/// <inheritdoc />
public virtual int Integer { get => RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42; set { } }
public virtual int Integer => RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42;

/// <inheritdoc />
public virtual float Float { get => RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f; set { } }
public virtual float Float => RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f;

/// <inheritdoc />
public virtual double Double { get => RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d; set { } }
public virtual double Double => RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d;

/// <inheritdoc />
public virtual Func<DateTime> Date { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date; } set { } }
public virtual Func<DateTime> Date { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date; } }

/// <inheritdoc />
public virtual Func<DateTime> DateTime { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow; } set { } }
public virtual Func<DateTime> DateTime { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow; } }

/// <inheritdoc />
public virtual byte[] Bytes { get => RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate(); set { } }
public virtual byte[] Bytes => RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate();

/// <inheritdoc />
public virtual object Object { get; set; } = "example-object";
public virtual object Object => "example-object";

/// <inheritdoc />
public virtual string String { get => RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; set { } }
public virtual string String => RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string";

/// <inheritdoc />
public virtual OpenApiSchema? Schema { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ namespace WireMock.Net.OpenApiParser.Settings;
public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleValues
{
/// <inheritdoc />
public virtual bool Boolean { get; set; } = true;
public virtual bool Boolean => true;

/// <inheritdoc />
public virtual int Integer { get; set; } = 42;
public virtual int Integer => 42;

/// <inheritdoc />
public virtual float Float { get; set; } = 4.2f;
public virtual float Float => 4.2f;

/// <inheritdoc />
public virtual double Double { get; set; } = 4.2d;
public virtual double Double => 4.2d;

/// <inheritdoc />
public virtual Func<DateTime> Date { get; set; } = () => System.DateTime.UtcNow.Date;
public virtual Func<DateTime> Date { get; } = () => System.DateTime.UtcNow.Date;

/// <inheritdoc />
public virtual Func<DateTime> DateTime { get; set; } = () => System.DateTime.UtcNow;
public virtual Func<DateTime> DateTime { get; } = () => System.DateTime.UtcNow;

/// <inheritdoc />
public virtual byte[] Bytes { get; set; } = { 48, 49, 50 };
public virtual byte[] Bytes { get; } = { 48, 49, 50 };

/// <inheritdoc />
public virtual object Object { get; set; } = "example-object";
public virtual object Object => "example-object";

/// <inheritdoc />
public virtual string String { get; set; } = "example-string";
public virtual string String => "example-string";

/// <inheritdoc />
public virtual OpenApiSchema? Schema { get; set; } = new();
Expand Down
Loading
Loading