public void Select_With_NullSelector_Must_Throw() { // Arrange var collection = Wrap.AsValueReadOnlyCollection(new int[0]); var selector = (NullableSelector <int, string>)null; // Act Action action = () => _ = ValueReadOnlyCollectionExtensions.Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(collection, selector); // Assert _ = action.Must() .Throw <ArgumentNullException>() .EvaluateTrue(exception => exception.ParamName == "selector"); }
public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); // Act var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .First(); // Assert _ = result.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }
public void Select_With_ValidData_Must_Succeed(int[] source, Func <int, string> selector) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); var expected = System.Linq.Enumerable.Select(wrapped, selector); // Act var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector); // Assert _ = result.Must() .BeEnumerableOf <string>() .BeEqualTo(expected); }
public void First_Selector_With_ValidData_Must_Return_Some(int[] source, NullableSelector <int, string> selector) { // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = Enumerable .Select(source, selector.AsFunc()) .First(); // Act var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .First(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, NullableSelector <int, string> selector) { // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = System.Linq.Enumerable.ToArray( System.Linq.Enumerable.Select(source, selector.AsFunc())); // Act var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ToArray(); // Assert _ = result.Must() .BeArrayOf <string>() .BeEqualTo(expected); }
public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func <int, int, string> selector) { // Arrange var pool = MemoryPool <string> .Shared; var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = Enumerable .Select(source, selector) .ToArray(); // Act using var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ToArray(pool); // Assert _ = result.Memory .SequenceEqual(expected); }
public void ToList_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); var expected = Enumerable .Select(source, selector.AsFunc()) .ToList(); // Act var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ToList(); // Assert _ = result.Must() .BeOfType <List <string> >() .BeEnumerableOf <string>() .BeEqualTo(expected); }
public void ElementAt_Selector_With_ValidData_Must_Return_Some(int[] source, Func <int, string> selector) { // Arrange var wrapped = Wrap.AsValueReadOnlyCollection(source); var expected = Enumerable .Select(source, selector) .ToList(); for (var index = 0; index < source.Length; index++) { // Act var result = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(index); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected[index]), () => throw new Exception()); } }
public void ElementAt_Selector_With_OutOfRange_Must_Return_None(int[] source, Func <int, string> selector) { // Arrange var wrapped = Wrap .AsValueReadOnlyCollection(source); // Act var optionNegative = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(-1); var optionTooLarge = ValueReadOnlyCollectionExtensions .Select <Wrap.ValueReadOnlyCollectionWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(source.Length); // Assert _ = optionNegative.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); _ = optionTooLarge.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }