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
18 changes: 9 additions & 9 deletions Source/aweXpect.Core/Options/CollectionMatchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public sealed class ExpectationItem<TItem>
{
private readonly CancellationToken _cancellationToken;
private readonly IEvaluationContext _context;
internal readonly ManualExpectationBuilder<TItem> _itemExpectationBuilder;
internal readonly ManualExpectationBuilder<TItem> ItemExpectationBuilder;

/// <inheritdoc cref="ExpectationItem{TItem}" />
public ExpectationItem(Action<IThat<TItem>> expectation,
Expand All @@ -374,8 +374,8 @@ public ExpectationItem(Action<IThat<TItem>> expectation,
{
_context = context;
_cancellationToken = cancellationToken;
_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(null, grammars);
expectation.Invoke(new ThatSubject<TItem>(_itemExpectationBuilder));
ItemExpectationBuilder = new ManualExpectationBuilder<TItem>(null, grammars);
expectation.Invoke(new ThatSubject<TItem>(ItemExpectationBuilder));
}

/// <summary>
Expand All @@ -387,21 +387,21 @@ public async ValueTask<bool> IsMetBy(TItem value)
public async Task<bool> IsMetBy(TItem value)
#endif
{
ConstraintResult result = await _itemExpectationBuilder.IsMetBy(value, _context, _cancellationToken);
ConstraintResult result = await ItemExpectationBuilder.IsMetBy(value, _context, _cancellationToken);
return result.Outcome == Outcome.Success;
}

/// <inheritdoc cref="object.Equals(object?)" />
public override bool Equals(object? obj) => obj is ExpectationItem<TItem> other && Equals(other);

private bool Equals(ExpectationItem<TItem> other)
=> _itemExpectationBuilder.Equals(other._itemExpectationBuilder);
=> ItemExpectationBuilder.Equals(other.ItemExpectationBuilder);

/// <inheritdoc cref="object.GetHashCode()" />
public override int GetHashCode() => _itemExpectationBuilder.GetHashCode();
public override int GetHashCode() => ItemExpectationBuilder.GetHashCode();

/// <inheritdoc cref="object.ToString()" />
public override string ToString() => _itemExpectationBuilder.ToString();
public override string ToString() => ItemExpectationBuilder.ToString();
}

internal sealed class ExpectationItemEqualityComparer<TItem> : IEqualityComparer<ExpectationItem<TItem>>
Expand All @@ -423,9 +423,9 @@ public bool Equals(ExpectationItem<TItem>? x, ExpectationItem<TItem>? y)
return false;
}

return x._itemExpectationBuilder.Equals(y._itemExpectationBuilder);
return x.ItemExpectationBuilder.Equals(y.ItemExpectationBuilder);
}

public int GetHashCode(ExpectationItem<TItem> obj) => obj._itemExpectationBuilder.GetHashCode();
public int GetHashCode(ExpectationItem<TItem> obj) => obj.ItemExpectationBuilder.GetHashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public HasItemThatConstraint(ExpectationBuilder expectationBuilder,
_it = it;
_options = options;

_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(_expectationBuilder, Grammars);
_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(null, Grammars);
expectations.Invoke(new ThatSubject<TItem>(_itemExpectationBuilder));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public HasItemThatConstraint(ExpectationBuilder expectationBuilder,
_it = it;
_options = options;

_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(_expectationBuilder, Grammars);
_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(null, Grammars);
expectations.Invoke(new ThatSubject<TItem>(_itemExpectationBuilder));
}

Expand Down Expand Up @@ -189,7 +189,7 @@ public HasItemThatForEnumerableConstraint(ExpectationBuilder expectationBuilder,
_it = it;
_options = options;

_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(_expectationBuilder, Grammars);
_itemExpectationBuilder = new ManualExpectationBuilder<TItem>(null, Grammars);
expectations.Invoke(new ThatSubject<TItem>(_itemExpectationBuilder));
}

Expand Down
20 changes: 10 additions & 10 deletions Source/aweXpect/That/Strings/ThatString.EndsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ public static partial class ThatString
/// <summary>
/// Verifies that the subject ends with the <paramref name="expected" /> <see langword="string" />.
/// </summary>
public static StringEqualityTypeResult<string?, IThat<string?>> EndsWith(
public static StringEqualityResult<string?, IThat<string?>> EndsWith(
this IThat<string?> source,
string expected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new EndsWithConstraint(it, grammars, expected, options)),
StringEqualityOptions options = new StringEqualityOptions().AsSuffix();
return new StringEqualityResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((expectationBuilder, it, grammars) =>
new IsEqualToConstraint(expectationBuilder, it, grammars, expected, options)),
source,
options);
}

/// <summary>
/// Verifies that the subject does not end with the <paramref name="unexpected" /> <see langword="string" />.
/// </summary>
public static StringEqualityTypeResult<string?, IThat<string?>> DoesNotEndWith(
public static StringEqualityResult<string?, IThat<string?>> DoesNotEndWith(
this IThat<string?> source,
string unexpected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new EndsWithConstraint(it, grammars, unexpected, options).Invert()),
StringEqualityOptions options = new StringEqualityOptions().AsSuffix();
return new StringEqualityResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((expectationBuilder, it, grammars) =>
new IsEqualToConstraint(expectationBuilder, it, grammars, unexpected, options).Invert()),
source,
options);
}
Expand Down
20 changes: 10 additions & 10 deletions Source/aweXpect/That/Strings/ThatString.StartsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ public static partial class ThatString
/// <summary>
/// Verifies that the subject starts with the <paramref name="expected" /> <see langword="string" />.
/// </summary>
public static StringEqualityTypeResult<string?, IThat<string?>> StartsWith(
public static StringEqualityResult<string?, IThat<string?>> StartsWith(
this IThat<string?> source,
string expected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new StartsWithConstraint(it, grammars, expected, options)),
StringEqualityOptions options = new StringEqualityOptions().AsPrefix();
return new StringEqualityResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((expectationBuilder, it, grammars) =>
new IsEqualToConstraint(expectationBuilder, it, grammars, expected, options)),
source,
options);
}

/// <summary>
/// Verifies that the subject does not start with the <paramref name="unexpected" /> <see langword="string" />.
/// </summary>
public static StringEqualityTypeResult<string?, IThat<string?>> DoesNotStartWith(
public static StringEqualityResult<string?, IThat<string?>> DoesNotStartWith(
this IThat<string?> source,
string unexpected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new StartsWithConstraint(it, grammars, unexpected, options).Invert()),
StringEqualityOptions options = new StringEqualityOptions().AsPrefix();
return new StringEqualityResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((expectationBuilder, it, grammars) =>
new IsEqualToConstraint(expectationBuilder, it, grammars, unexpected, options).Invert()),
source,
options);
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1146,9 +1146,9 @@ namespace aweXpect
{
public static aweXpect.Results.StringEqualityTypeCountResult<string?, aweXpect.Core.IThat<string?>> Contains(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.StringEqualityTypeCountResult<string?, aweXpect.Core.IThat<string?>> DoesNotContain(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> DoesNotEndWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> DoesNotStartWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> EndsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> DoesNotEndWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> DoesNotStartWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> EndsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.PropertyResult.Int<string?> HasLength(this aweXpect.Core.IThat<string?> source) { }
public static aweXpect.Results.AndOrResult<string?, aweXpect.Core.IThat<string?>> IsEmpty(this aweXpect.Core.IThat<string?> source) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> IsEqualTo(this aweXpect.Core.IThat<string?> source, string? expected) { }
Expand All @@ -1172,7 +1172,7 @@ namespace aweXpect
public static aweXpect.Results.IsParsableResult<TType> IsParsableInto<TType>(this aweXpect.Core.IThat<string?> source, System.IFormatProvider? formatProvider = null)
where TType : System.IParsable<TType> { }
public static aweXpect.Results.AndOrResult<string?, aweXpect.Core.IThat<string?>> IsUpperCased(this aweXpect.Core.IThat<string?> source) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> StartsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> StartsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
}
public static class ThatTimeOnly
{
Expand Down
8 changes: 4 additions & 4 deletions Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1121,9 +1121,9 @@ namespace aweXpect
{
public static aweXpect.Results.StringEqualityTypeCountResult<string?, aweXpect.Core.IThat<string?>> Contains(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.StringEqualityTypeCountResult<string?, aweXpect.Core.IThat<string?>> DoesNotContain(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> DoesNotEndWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> DoesNotStartWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> EndsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> DoesNotEndWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> DoesNotStartWith(this aweXpect.Core.IThat<string?> source, string unexpected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> EndsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.PropertyResult.Int<string?> HasLength(this aweXpect.Core.IThat<string?> source) { }
public static aweXpect.Results.AndOrResult<string?, aweXpect.Core.IThat<string?>> IsEmpty(this aweXpect.Core.IThat<string?> source) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> IsEqualTo(this aweXpect.Core.IThat<string?> source, string? expected) { }
Expand All @@ -1143,7 +1143,7 @@ namespace aweXpect
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> IsOneOf(this aweXpect.Core.IThat<string?> source, System.Collections.Generic.IEnumerable<string?> expected) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> IsOneOf(this aweXpect.Core.IThat<string?> source, params string?[] expected) { }
public static aweXpect.Results.AndOrResult<string?, aweXpect.Core.IThat<string?>> IsUpperCased(this aweXpect.Core.IThat<string?> source) { }
public static aweXpect.Results.StringEqualityTypeResult<string?, aweXpect.Core.IThat<string?>> StartsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
public static aweXpect.Results.StringEqualityResult<string?, aweXpect.Core.IThat<string?>> StartsWith(this aweXpect.Core.IThat<string?> source, string expected) { }
}
public static class ThatTimeSpan
{
Expand Down
30 changes: 16 additions & 14 deletions Tests/aweXpect.Tests/Strings/ThatString.DoesNotEndWith.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not end with "TEXT" ignoring case,
but it was "some text"

Actual:
some text
""");
}

Expand Down Expand Up @@ -51,6 +54,9 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not end with "tExt" using IgnoreCaseForVocalsComparer,
but it was "some arbitrary text"

Actual:
some arbitrary text
""");
}

Expand All @@ -69,20 +75,15 @@ async Task Act()
}

[Fact]
public async Task WhenExpectedIsNull_ShouldFail()
public async Task WhenExpectedIsNull_ShouldSucceed()
{
string subject = "text";
string? expected = null;

async Task Act()
=> await That(subject).DoesNotEndWith(expected!);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not end with <null>,
but "text" cannot be validated against <null>
""");
await That(Act).DoesNotThrow();
}

[Fact]
Expand All @@ -99,6 +100,9 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not end with "text",
but it was "some text"

Actual:
some text
""");
}

Expand Down Expand Up @@ -128,24 +132,22 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not end with "some text",
but it was "some text"

Actual:
some text
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
public async Task WhenSubjectIsNull_ShouldSucceed()
{
string? subject = null;
string expected = "text";

async Task Act()
=> await That(subject).DoesNotEndWith(expected);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not end with "text",
but it was <null>
""");
await That(Act).DoesNotThrow();
}
}
}
Expand Down
30 changes: 16 additions & 14 deletions Tests/aweXpect.Tests/Strings/ThatString.DoesNotStartWith.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not start with "some",
but it was "some text"

Actual:
some text
""");
}

Expand Down Expand Up @@ -65,24 +68,22 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not start with "sOmE" using IgnoreCaseForVocalsComparer,
but it was "some arbitrary text"

Actual:
some arbitrary text
""");
}

[Fact]
public async Task WhenExpectedIsNull_ShouldFail()
public async Task WhenExpectedIsNull_ShouldSucceed()
{
string subject = "text";
string? expected = null;

async Task Act()
=> await That(subject).DoesNotStartWith(expected!);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not start with <null>,
but "text" cannot be validated against <null>
""");
await That(Act).DoesNotThrow();
}

[Fact]
Expand Down Expand Up @@ -111,6 +112,9 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not start with "SOME" ignoring case,
but it was "some text"

Actual:
some text
""");
}

Expand All @@ -128,24 +132,22 @@ await That(Act).Throws<XunitException>()
Expected that subject
does not start with "some text",
but it was "some text"

Actual:
some text
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
public async Task WhenSubjectIsNull_ShouldSucceed()
{
string? subject = null;
string expected = "text";

async Task Act()
=> await That(subject).DoesNotStartWith(expected);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not start with "text",
but it was <null>
""");
await That(Act).DoesNotThrow();
}
}
}
Expand Down
Loading
Loading