void Max_ThrowsException() { IEnumerable <DummyIComparable> empty = Enumerable.Empty <DummyIComparable>(); IEnumerable <DummyIComparable> nulls = new DummyIComparable[] { null, null }; Test.If.Action.ThrowsException(() => IEnumerableTExtensions.Maximum <DummyIComparable>(null), out ArgumentNullException ex); Test.If.Value.IsEqual(ex.ParamName, "_this"); Test.If.Action.ThrowsException(() => empty.Maximum(), out ArgumentException argEx); Test.If.Value.IsEqual(argEx.ParamName, "_this"); Test.If.String.StartsWith(argEx.Message, "The enumeration is empty."); Test.If.Action.ThrowsException(() => nulls.Maximum(), out argEx); Test.If.Value.IsEqual(argEx.ParamName, "_this"); Test.If.String.StartsWith(argEx.Message, "The enumeration only contains null values."); }
void MaxIComparerT_ThrowsException() { IEnumerable <Dummy> notEmpty = new Dummy[] { null, -1, -1, null, 0, 1, 1 }; IEnumerable <Dummy> empty = Enumerable.Empty <Dummy>(); IEnumerable <Dummy> nulls = new Dummy[] { null, null }; Test.If.Action.ThrowsException(() => IEnumerableTExtensions.Maximum(null, null as IComparer <Dummy>), out ArgumentNullException ex1); Test.If.Value.IsEqual(ex1.ParamName, "_this"); Test.If.Action.ThrowsException(() => IEnumerableTExtensions.Maximum(null, DynamicComparer.FromDelegate <Dummy>((x, y) => 0)), out ex1); Test.If.Value.IsEqual(ex1.ParamName, "_this"); Test.If.Action.ThrowsException(() => notEmpty.Maximum(null as IComparer <Dummy>), out ex1); Test.If.Value.IsEqual(ex1.ParamName, "comparer"); Test.If.Action.ThrowsException(() => empty.Maximum(DynamicComparer.FromDelegate <Dummy>((x, y) => 0)), out ArgumentException ex2); Test.If.Value.IsEqual(ex2.ParamName, "_this"); Test.If.String.StartsWith(ex2.Message, "The enumeration is empty."); Test.If.Action.ThrowsException(() => nulls.Maximum(DynamicComparer.FromDelegate <Dummy>((x, y) => 0)), out ex2); Test.If.Value.IsEqual(ex2.ParamName, "_this"); Test.If.String.StartsWith(ex2.Message, "The enumeration only contains null values."); }