public static async ValueTask ActionWhereNoneFail() { var items = new[] { 1, 1, 1, 1, 1, 1 }; var ex = await Record.ExceptionAsync(() => Assert.AllAsync(items, async x => { await Task.Yield(); Assert.Equal(1, x); })); Assert.Null(ex); }
public static async ValueTask ActionCanReceiveIndex() { var items = new[] { 1, 1, 2, 2, 1, 1 }; var indices = new List <int>(); await Assert.AllAsync(items, async (x, idx) => { await Task.Yield(); indices.Add(idx); }); Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, indices); }
public static async ValueTask ActionWhereAllFail() { var items = new[] { 1, 1, 2, 2, 1, 1 }; var ex = await Assert.ThrowsAsync <AllException>(() => Assert.AllAsync(items, async x => { await Task.Yield(); Assert.Equal(0, x); })); Assert.Equal(6, ex.Failures.Count); Assert.All(ex.Failures, x => Assert.IsType <EqualException>(x)); }
public static async ValueTask CollectionWithNullThrowsAllException() { var collection = new object?[] { new object(), null }; var ex = await Assert.ThrowsAsync <AllException>(() => Assert.AllAsync(collection, async x => { await Task.Yield(); Assert.NotNull(x); })); Assert.Contains("[1]: Item: ", ex.Message); }
public static async ValueTask NullActionThrows() { await Assert.ThrowsAsync <ArgumentNullException>(() => Assert.AllAsync(new object[0], (Func <object, ValueTask>)null !)); await Assert.ThrowsAsync <ArgumentNullException>(() => Assert.AllAsync(new object[0], (Func <object, int, ValueTask>)null !)); }