public void SingleAsync_With_Multiple_Must_Throw(int[] source) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); // Act Func <ValueTask> action = async() => _ = await AsyncValueEnumerable .SingleAsync <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped); // Assert _ = action.Must() .Throw <InvalidOperationException>() .EvaluateTrue(exception => exception.Message == "Sequence contains more than one element"); }
public async void SingleAsync_With_Multiple_Must_Return_None(int[] source) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); // Act var result = await AsyncValueEnumerable .SingleAsync <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped); // Assert _ = result.Must() .BeOfType <Option <int> >() .EvaluateTrue(option => option.IsNone); }
public async ValueTask SingleAsync_With_SingleAsync_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable.Single(source); // Act var result = await AsyncValueEnumerable .SingleAsync <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped); // Assert _ = result.Must() .BeEqualTo(expected); }
public async ValueTask SingleAsync_With_SingleAsync_Must_Return_Some(int[] source) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable.Single(source); // Act var result = await AsyncValueEnumerable .SingleAsync <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }