public void SelectIndex_With_NullSelector_Must_Throw() { // Arrange var enumerable = Wrap.AsValueEnumerable(new int[0]); var selector = (Selector <int, string>)null; // Act Action action = () => _ = ValueEnumerable.Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(enumerable, selector); // Assert _ = action.Must() .Throw <ArgumentNullException>() .EvaluateTrue(exception => exception.ParamName == "selector"); }
public void Contains_SelectorAt_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source, SelectorAt <int, string> selector) { // Arrange var value = "!"; var wrapped = Wrap.AsValueEnumerable(source); // Act var result = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .Contains(value, EqualityComparer <string> .Default); // Assert _ = result.Must() .BeFalse(); }
public void First_SelectorAt_With_Empty_Must_Return_None(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); // Act var result = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .First(); // Assert _ = result.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }
public void SelectIndex_With_ValidData_Must_Succeed(int[] source) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); var expected = System.Linq.Enumerable.Select(wrapped, (item, index) => (item + index).ToString()); // Act var result = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, (item, index) => (item + index).ToString()); // Assert _ = result.Must() .BeEnumerableOf <string>() .BeEqualTo(expected); }
public void Contains_SelectorAt_With_Comparer_And_Contains_Must_ReturnTrue(int[] source, SelectorAt <int, string> selector) { // Arrange var value = System.Linq.Enumerable.Last( System.Linq.Enumerable.Select(source, selector.AsFunc())); var wrapped = Wrap.AsValueEnumerable(source); // Act var result = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .Contains(value, EqualityComparer <string> .Default); // Assert _ = result.Must() .BeTrue(); }
public void First_SelectorAt_With_ValidData_Must_Return_Some(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); var expected = System.Linq.Enumerable.First( System.Linq.Enumerable.Select(source, selector.AsFunc())); // Act var result = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .First(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsValueEnumerable(source); var expected = System.Linq.Enumerable.ToArray( System.Linq.Enumerable.Select(source, selector.AsFunc())); // Act var result = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ToArray(); // Assert _ = result.Must() .BeArrayOf <string>() .BeEqualTo(expected); }
public void ForEach_Action_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); var result = new List <string>(); var expected = new List <string>(); System.Linq.EnumerableEx.ForEach( System.Linq.Enumerable.Select(source, selector.AsFunc()), item => expected.Add(item)); // Act ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ForEach(item => result.Add(item)); // Assert _ = result.Must() .BeEnumerableOf <string>() .BeEqualTo(expected); }
public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap.AsValueEnumerable(source); // Act var optionNegative = ValueEnumerable .Select <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector) .ElementAt(-1); var optionTooLarge = ValueEnumerable .Select <Wrap.ValueEnumerable <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); }