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
4 changes: 3 additions & 1 deletion Source/aweXpect/That/Collections/ThatDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ namespace aweXpect;
public static partial class ThatDictionary
{
internal static bool ContainsValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TValue value)
=> dictionary.Any(x => value?.Equals(x.Value) == true);
=> value is null
? dictionary.Any(x => x.Value is null)
: dictionary.Any(x => value.Equals(x.Value));
}
4 changes: 3 additions & 1 deletion Source/aweXpect/That/Collections/ThatReadOnlyDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ namespace aweXpect;
public static partial class ThatReadOnlyDictionary
{
internal static bool ContainsValue<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TValue value)
=> dictionary.Any(x => value?.Equals(x.Value) == true);
=> value is null
? dictionary.Any(x => x.Value is null)
: dictionary.Any(x => value.Equals(x.Value));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@ public sealed class ContainsValue
{
public sealed class Tests
{
[Fact]
public async Task WhenNullValueDoesNotExist_ShouldFail()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).ContainsValue(null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains value <null>,
but it contained only [
41,
42,
43
]

Dictionary:
{[1] = 41, [2] = 42, [3] = 43}
""");
}

[Fact]
public async Task WhenNullValueExists_ShouldSucceed()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, null, 43,]);

async Task Act()
=> await That(subject).ContainsValue(null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ async Task Act()
await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAllValuesExists_WithNull_ShouldSucceed()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [null, 42, 43,]);

async Task Act()
=> await That(subject).ContainsValues(42, null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenOneValueIsMissing_ShouldFail()
{
Expand All @@ -44,6 +55,31 @@ ] in [
""");
}

[Fact]
public async Task WhenOneValueIsMissing_WithNull_ShouldFail()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).ContainsValues(42, null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains values [42, <null>],
but it did not contain [
<null>
] in [
41,
42,
43
]

Dictionary:
{[1] = 41, [2] = 42, [3] = 43}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ public sealed class DoesNotContainValue
{
public sealed class Tests
{
[Fact]
public async Task WhenNullValueDoesNotExist_ShouldSucceed()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValue(null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNullValueExists_ShouldFail()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, null, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValue(null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not contain value <null>,
but it did

Dictionary:
{[1] = 41, [2] = <null>, [3] = 43}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ async Task Act()
await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAllValuesDoNotExist_WithNull_ShouldSucceed()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValues(2, null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAtLeastOneValueExists_ShouldFail()
{
Expand All @@ -40,6 +51,27 @@ but it did contain [
""");
}

[Fact]
public async Task WhenAtLeastOneValueExists_WithNull_ShouldFail()
{
IDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [null, 42, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValues(2, null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not contain values [2, <null>],
but it did contain [
<null>
]

Dictionary:
{[1] = <null>, [2] = 42, [3] = 43}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ public sealed class ContainsValue
{
public sealed class Tests
{
[Fact]
public async Task WhenNullValueDoesNotExist_ShouldFail()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).ContainsValue(null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains value <null>,
but it contained only [
41,
42,
43
]

Dictionary:
{[1] = 41, [2] = 42, [3] = 43}
""");
}

[Fact]
public async Task WhenNullValueExists_ShouldSucceed()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, null, 43,]);

async Task Act()
=> await That(subject).ContainsValue(null);

await That(Act).DoesNotThrow();
}
[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ async Task Act()
await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAllValuesExists_WithNull_ShouldSucceed()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [null, 42, 43,]);

async Task Act()
=> await That(subject).ContainsValues(42, null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenOneValueIsMissing_ShouldFail()
{
Expand All @@ -45,6 +56,31 @@ ] in [
""");
}

[Fact]
public async Task WhenOneValueIsMissing_WithNull_ShouldFail()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).ContainsValues(42, null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains values [42, <null>],
but it did not contain [
<null>
] in [
41,
42,
43
]

Dictionary:
{[1] = 41, [2] = 42, [3] = 43}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@ public sealed class DoesNotContainValue
{
public sealed class Tests
{
[Fact]
public async Task WhenNullValueDoesNotExist_ShouldSucceed()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValue(null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNullValueExists_ShouldFail()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, null, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValue(null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not contain value <null>,
but it did

Dictionary:
{[1] = 41, [2] = <null>, [3] = 43}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ async Task Act()
await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAllValuesDoNotExist_WithNull_ShouldSucceed()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [41, 42, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValues(2, null);

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAtLeastOneValueExists_ShouldFail()
{
Expand All @@ -41,6 +52,27 @@ but it did contain [
""");
}

[Fact]
public async Task WhenAtLeastOneValueExists_WithNull_ShouldFail()
{
IReadOnlyDictionary<int, int?> subject = ToDictionary<int, int?>([1, 2, 3,], [null, 42, 43,]);

async Task Act()
=> await That(subject).DoesNotContainValues(2, null);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not contain values [2, <null>],
but it did contain [
<null>
]

Dictionary:
{[1] = <null>, [2] = 42, [3] = 43}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
Expand Down
Loading