Skip to content
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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageVersion Include="aweXpect" Version="2.31.0"/>
<PackageVersion Include="aweXpect.Core" Version="2.28.0"/>
<PackageVersion Include="aweXpect.Chronology" Version="1.0.0"/>
<PackageVersion Include="Mockolate" Version="2.4.0"/>
<PackageVersion Include="Mockolate" Version="3.0.0-pre.2"/>
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Nullable" Version="1.3.1"/>
Expand Down
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);1701;1702</NoWarn>
<WarningsNotAsErrors>CS1591;NU5104</WarningsNotAsErrors>
<WarningsNotAsErrors>CS1591;CS1711;NU5104</WarningsNotAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<ConstraintResult> IsMetBy(VerificationResult<TVerify> actual,
}
catch (MockVerificationTimeoutException)
{
string interactionsText = Formatter.Format(((IVerificationResult)actual).MockInteractions,
string interactionsText = Formatter.Format(((IVerificationResult)actual).Interactions,
FormattingOptions.MultipleLines);
expectationBuilder.UpdateContexts(contexts => contexts
.Remove("Matching Interactions")
Expand Down
27 changes: 22 additions & 5 deletions Source/aweXpect.Mockolate/ThatVerificationResult.Then.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@
private List<string>? _expectations;
private string? _error;

public ConstraintResult IsMetBy(VerificationResult<T> actual)

Check failure on line 38 in Source/aweXpect.Mockolate/ThatVerificationResult.Then.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=aweXpect_aweXpect.Mockolate&issues=AZ3IU1btbEa5FZo2kyGa&open=AZ3IU1btbEa5FZo2kyGa&pullRequest=103
{
Actual = actual;
_expectations = new List<string>();
bool result = true;
T verify = ((IVerificationResult<T>)actual).Object;
IVerificationResult verificationResult = actual;
IInteraction[] snapshot = verificationResult.Interactions.ToArray();
Dictionary<IInteraction, int> positions = new(snapshot.Length);
for (int i = 0; i < snapshot.Length; i++)
{
positions[snapshot[i]] = i;
}

int after = -1;
foreach (Func<T, VerificationResult<T>> check in interactions)
{
Expand All @@ -60,7 +67,7 @@
Outcome = result ? Outcome.Success : Outcome.Failure;
if (!result)
{
string context = Formatter.Format(((IVerificationResult)actual).MockInteractions,
string context = Formatter.Format(((IVerificationResult)actual).Interactions,
FormattingOptions.MultipleLines);
expectationBuilder.UpdateContexts(contexts => contexts.Add(
new ResultContext.SyncCallback("Matching Interactions", () => context)));
Expand All @@ -72,12 +79,22 @@

bool VerifyInteractions(IInteraction[] filteredInteractions, IVerificationResult currentVerificationResult)
{
bool hasInteractionAfter = filteredInteractions.Any(x => x.Index > after);
if (hasInteractionAfter)
int bestPosition = int.MaxValue;
IInteraction? firstInteraction = null;
foreach (IInteraction candidate in filteredInteractions)
{
after = filteredInteractions.Where(x => x.Index > after).Min(x => x.Index);
if (positions.TryGetValue(candidate, out int position) &&
position > after &&
position < bestPosition)
{
bestPosition = position;
firstInteraction = candidate;
}
}
else if (_error is null)

bool hasInteractionAfter = firstInteraction is not null;
after = hasInteractionAfter ? bestPosition : int.MaxValue;
if (!hasInteractionAfter && _error is null)
{
_error = filteredInteractions.Length > 0
? $"{currentVerificationResult.Expectation} too early"
Expand Down
2 changes: 1 addition & 1 deletion Source/aweXpect.Mockolate/ThatVerificationResult.Times.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<ConstraintResult> IsMetBy(VerificationResult<TVerify> actual,
}
catch (MockVerificationTimeoutException)
{
string interactionsText = Formatter.Format(((IVerificationResult)actual).MockInteractions,
string interactionsText = Formatter.Format(((IVerificationResult)actual).Interactions,
FormattingOptions.MultipleLines);
expectationBuilder.UpdateContexts(contexts => contexts
.Remove("Matching Interactions")
Expand Down
6 changes: 3 additions & 3 deletions Source/aweXpect.Mockolate/ThatVerificationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static void AppendAllInteractions(ExpectationBuilder expectationBuilder,
return;
}

MockInteractions allInteractions = mock.MockRegistry.Interactions;
IMockInteractions allInteractions = mock.MockRegistry.Interactions;
string interactionsText = Formatter.Format(allInteractions, FormattingOptions.MultipleLines);
expectationBuilder.UpdateContexts(contexts => contexts
.Remove("All Interactions")
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task<ConstraintResult> IsMetBy(VerificationResult<TVerify> actual,
}
catch (MockVerificationTimeoutException)
{
string interactionsText = Formatter.Format(((IVerificationResult)actual).MockInteractions,
string interactionsText = Formatter.Format(((IVerificationResult)actual).Interactions,
FormattingOptions.MultipleLines);
expectationBuilder.UpdateContexts(contexts => contexts
.Remove("Matching Interactions")
Expand Down Expand Up @@ -308,7 +308,7 @@ public async Task<ConstraintResult> IsMetBy(VerificationResult<TVerify> actual,
}
catch (MockVerificationTimeoutException)
{
string interactionsText = Formatter.Format(((IVerificationResult)actual).MockInteractions,
string interactionsText = Formatter.Format(((IVerificationResult)actual).Interactions,
FormattingOptions.MultipleLines);
expectationBuilder.UpdateContexts(contexts => contexts
.Remove("Matching Interactions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
IJsonContentBodyParameter IgnoringAdditionalProperties(bool ignoreAdditionalProperties = true);
}

private sealed class JsonContentParameter : IJsonContentBodyParameter, IParameter

Check warning on line 67 in Source/aweXpect.Mockolate/Web/ItExtensions.HttpContent.IsJsonContent.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'IJsonContentBodyParameter' implements 'IParameter' so 'IParameter' can be removed from the inheritance list.

See more on https://sonarcloud.io/project/issues?id=aweXpect_aweXpect.Mockolate&issues=AZ3IU1ZUbEa5FZo2kyGZ&open=AZ3IU1ZUbEa5FZo2kyGZ&pullRequest=103
{
private readonly ItExtensions.IHttpContentParameter _parameter;

Expand All @@ -84,7 +84,7 @@
return this;
}

public IParameter<HttpContent?> Do(Action<HttpContent?> callback)
public IParameterWithCallback<HttpContent?> Do(Action<HttpContent?> callback)
=> _parameter.Do(callback);

public ItExtensions.IHttpContentHeaderParameter WithHeaders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Mockolate.Web
{
public static class AweXpectItExtensions
{
public interface IJsonContentBodyParameter : Mockolate.Parameters.IParameter<System.Net.Http.HttpContent?>, Mockolate.Web.ItExtensions.IHttpContentParameter, Mockolate.Web.ItExtensions.IHttpHeaderParameter<Mockolate.Web.ItExtensions.IHttpContentHeaderParameter>
public interface IJsonContentBodyParameter : Mockolate.Parameters.IParameter, Mockolate.Parameters.IParameterWithCallback<System.Net.Http.HttpContent?>, Mockolate.Parameters.IParameter<System.Net.Http.HttpContent?>, Mockolate.Web.ItExtensions.IHttpContentParameter, Mockolate.Web.ItExtensions.IHttpHeaderParameter<Mockolate.Web.ItExtensions.IHttpContentHeaderParameter>
{
Mockolate.Web.AweXpectItExtensions.IJsonContentBodyParameter IgnoringAdditionalProperties(bool ignoreAdditionalProperties = true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Mockolate.Web
{
public static class AweXpectItExtensions
{
public interface IJsonContentBodyParameter : Mockolate.Parameters.IParameter<System.Net.Http.HttpContent?>, Mockolate.Web.ItExtensions.IHttpContentParameter, Mockolate.Web.ItExtensions.IHttpHeaderParameter<Mockolate.Web.ItExtensions.IHttpContentHeaderParameter>
public interface IJsonContentBodyParameter : Mockolate.Parameters.IParameter, Mockolate.Parameters.IParameterWithCallback<System.Net.Http.HttpContent?>, Mockolate.Parameters.IParameter<System.Net.Http.HttpContent?>, Mockolate.Web.ItExtensions.IHttpContentParameter, Mockolate.Web.ItExtensions.IHttpHeaderParameter<Mockolate.Web.ItExtensions.IHttpContentHeaderParameter>
{
Mockolate.Web.AweXpectItExtensions.IJsonContentBodyParameter IgnoringAdditionalProperties(bool ignoreAdditionalProperties = true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task Negated_WhenAllAreVerified_ShouldThrow()
sut.DoWork(1);
sut.DoWork(2);

sut.Mock.Verify.DoWork(It.IsAny<int>()).AtLeastOnce();
await That(sut.Mock.Verify.DoWork(It.IsAny<int>())).AtLeastOnce();

async Task Act()
{
Expand All @@ -39,7 +39,7 @@ public async Task WhenAllInvocationsWereVerified_ShouldNotThrow()
sut.DoWork(1);
sut.DoWork(2);

sut.Mock.Verify.DoWork(It.IsAny<int>()).AtLeastOnce();
await That(sut.Mock.Verify.DoWork(It.IsAny<int>())).AtLeastOnce();

async Task Act()
{
Expand All @@ -58,7 +58,7 @@ public async Task WhenMultipleInvocationIsNotVerified_ShouldThrow()
sut.DoWork(2);
sut.DoWork(3);

sut.Mock.Verify.DoWork(It.Is(2)).AtLeastOnce();
await That(sut.Mock.Verify.DoWork(It.Is(2))).AtLeastOnce();

async Task Act()
{
Expand All @@ -70,8 +70,8 @@ await That(Act).Throws<XunitException>()
Expected that the aweXpect.Mockolate.Tests.ThatMockVerifyIs.IMyService mock
has all interactions verified,
but the following 2 interactions were not verified:
- [0] invoke method DoWork(1)
- [2] invoke method DoWork(3)
- invoke method DoWork(1)
- invoke method DoWork(3)
""");
}

Expand All @@ -83,7 +83,7 @@ public async Task WhenOneInvocationIsNotVerified_ShouldThrow()
sut.DoWork(1);
sut.DoWork(2);

sut.Mock.Verify.DoWork(It.Is(1)).AtLeastOnce();
await That(sut.Mock.Verify.DoWork(It.Is(1))).AtLeastOnce();

async Task Act()
{
Expand All @@ -95,7 +95,7 @@ await That(Act).Throws<XunitException>()
Expected that the aweXpect.Mockolate.Tests.ThatMockVerifyIs.IMyService mock
has all interactions verified,
but the following interaction was not verified:
- [1] invoke method DoWork(2)
- invoke method DoWork(2)
""");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ but never found it

Matching Interactions:
[
[0] invoke method MyMethod(1, True),
[1] invoke method MyMethod(2, True)
invoke method MyMethod(1, True),
invoke method MyMethod(2, True)
]
""");
}
Expand Down Expand Up @@ -253,7 +253,7 @@ but found it once

Matching Interactions:
[
[0] invoke method MyMethod(1, False)
invoke method MyMethod(1, False)
]
""");
}
Expand All @@ -280,8 +280,8 @@ but found it twice

Matching Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False)
]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ but found it only 3 times

Matching Interactions:
[
[0] invoke method MyMethod(1, True),
[1] invoke method MyMethod(2, True),
[2] invoke method MyMethod(3, True)
invoke method MyMethod(1, True),
invoke method MyMethod(2, True),
invoke method MyMethod(3, True)
]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ but found it only once

Matching Interactions:
[
[0] invoke method MyMethod(1, False)
invoke method MyMethod(1, False)
]

All Interactions:
[
[0] invoke method MyMethod(1, False)
invoke method MyMethod(1, False)
]
""");
}
Expand Down Expand Up @@ -226,9 +226,9 @@ but found it only once

Matching Interactions:
[
[0] invoke method MyMethod(1, True),
[1] invoke method MyMethod(2, True),
[2] invoke method MyMethod(3, True)
invoke method MyMethod(1, True),
invoke method MyMethod(2, True),
invoke method MyMethod(3, True)
]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ but found it 3 times

Matching Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False),
[2] invoke method MyMethod(1, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False),
invoke method MyMethod(1, False)
]

All Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False),
[2] invoke method MyMethod(1, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False),
invoke method MyMethod(1, False)
]
""");
}
Expand Down Expand Up @@ -93,15 +93,15 @@ but found it twice

Matching Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False)
]

All Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False),
[2] invoke method MyMethod(2, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False),
invoke method MyMethod(2, False)
]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ but found it 3 times

Matching Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False),
[2] invoke method MyMethod(1, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False),
invoke method MyMethod(1, False)
]

All Interactions:
[
[0] invoke method MyMethod(1, False),
[1] invoke method MyMethod(1, False),
[2] invoke method MyMethod(1, False),
[3] invoke method MyMethod(2, False)
invoke method MyMethod(1, False),
invoke method MyMethod(1, False),
invoke method MyMethod(1, False),
invoke method MyMethod(2, False)
]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ but found it only 3 times

Matching Interactions:
[
[0] invoke method MyMethod(1, True),
[1] invoke method MyMethod(2, True),
[2] invoke method MyMethod(3, True)
invoke method MyMethod(1, True),
invoke method MyMethod(2, True),
invoke method MyMethod(3, True)
]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ but found it 4 times

Matching Interactions:
[
[0] invoke method MyMethod(1, True),
[1] invoke method MyMethod(2, True),
[2] invoke method MyMethod(3, True),
[3] invoke method MyMethod(4, True)
invoke method MyMethod(1, True),
invoke method MyMethod(2, True),
invoke method MyMethod(3, True),
invoke method MyMethod(4, True)
]
""");
}
Expand Down
Loading
Loading