Skip to content

Commit a2a3e6e

Browse files
committed
Make IDiff assertion helpers work on IEnumerable<IDiff> instead of IReadOnlyList<IDiff>. Closes #87
1 parent d60adcf commit a2a3e6e

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/bunit.web/Asserting/DiffAssertExtensions.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
3+
using System.Linq;
44
using AngleSharp.Diffing.Core;
55

66
using Bunit.Asserting;
@@ -18,14 +18,14 @@ public static class DiffAssertExtensions
1818
/// </summary>
1919
/// <param name="diffs">The collection to be inspected</param>
2020
/// <returns>The expected single <see cref="IDiff"/> in the collection.</returns>
21-
public static IDiff ShouldHaveSingleChange(this IReadOnlyList<IDiff> diffs)
21+
public static IDiff ShouldHaveSingleChange(this IEnumerable<IDiff> diffs)
2222
{
2323
if (diffs is null)
2424
throw new ArgumentNullException(nameof(diffs));
25-
if (diffs.Count != 1)
26-
throw new ActualExpectedAssertException(diffs.Count.ToString(), "1", "Actual changes", "Expected changes", "There were more than one change");
25+
if (diffs.Count() != 1)
26+
throw new ActualExpectedAssertException(diffs.Count().ToString(), "1", "Actual changes", "Expected changes", "There were more than one change");
2727

28-
return diffs[0];
28+
return diffs.First();
2929
}
3030

3131
/// <summary>
@@ -35,19 +35,20 @@ public static IDiff ShouldHaveSingleChange(this IReadOnlyList<IDiff> diffs)
3535
/// <param name="diffs">The collection to be inspected</param>
3636
/// <param name="diffInspectors">The <see cref="IDiff"/> inspectors, which inspect each <see cref="IDiff"/> in turn.
3737
/// The total number of <see cref="IDiff"/> inspectors must exactly match the number of <see cref="IDiff"/>s in the collection</param>
38-
public static void ShouldHaveChanges(this IReadOnlyList<IDiff> diffs, params Action<IDiff>[] diffInspectors)
38+
public static void ShouldHaveChanges(this IEnumerable<IDiff> diffs, params Action<IDiff>[] diffInspectors)
3939
{
4040
if (diffs is null)
4141
throw new ArgumentNullException(nameof(diffs));
4242

43-
if (diffs.Count != diffInspectors.Length)
44-
throw new ActualExpectedAssertException(diffs.Count.ToString(), diffInspectors.Length.ToString(), "Actual changes", "Expected changes", "The actual number of changes does not match the expected.");
43+
if (diffs.Count() != diffInspectors.Length)
44+
throw new ActualExpectedAssertException(diffs.Count().ToString(), diffInspectors.Length.ToString(), "Actual changes", "Expected changes", "The actual number of changes does not match the expected.");
4545

46-
for (int i = 0; i < diffInspectors.Length; i++)
46+
int index = 0;
47+
foreach (var diff in diffs)
4748
{
48-
diffInspectors[i](diffs[i]);
49+
diffInspectors[index](diff);
50+
index++;
4951
}
5052
}
51-
5253
}
5354
}

src/bunit.web/Asserting/ShouldBeTextChangeAssertExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static class ShouldBeTextChangeAssertExtensions
2121
/// <param name="diffs">The list of diffs to verify against.</param>
2222
/// <param name="expectedChange">The expected text change.</param>
2323
/// <param name="userMessage">A custom error message to show if the verification fails.</param>
24-
public static void ShouldHaveSingleTextChange(this IReadOnlyList<IDiff> diffs, string expectedChange, string? userMessage = null)
24+
public static void ShouldHaveSingleTextChange(this IEnumerable<IDiff> diffs, string expectedChange, string? userMessage = null)
2525
{
2626
DiffAssertExtensions.ShouldHaveSingleChange(diffs).ShouldBeTextChange(expectedChange, userMessage);
2727
}

0 commit comments

Comments
 (0)