Exemple #1
0
        void Foreach_ThrowsException()
        {
            IEnumerable <Int32> enumerable = Enumerable.Empty <Int32>();

            Test.If.Action.ThrowsException(() => IEnumerableTExtensions.Foreach <Int32>(null, null), out ArgumentNullException ex);
            Test.If.Value.IsEqual(ex.ParamName, "_this");

            Test.If.Action.ThrowsException(() => IEnumerableTExtensions.Foreach <Int32>(null, (value) => { }), out ex);
            Test.If.Value.IsEqual(ex.ParamName, "_this");

            Test.If.Action.ThrowsException(() => enumerable.Foreach(null), out ex);
            Test.If.Value.IsEqual(ex.ParamName, "action");
        }
Exemple #2
0
        void MinT_ThrowsException()
        {
            IEnumerable <DummyIComparableT> empty = Enumerable.Empty <DummyIComparableT>();
            IEnumerable <DummyIComparableT> nulls = new DummyIComparableT[] { null, null };

            Test.If.Action.ThrowsException(() => IEnumerableTExtensions.MinimumT <DummyIComparableT>(null), out ArgumentNullException ex);
            Test.If.Value.IsEqual(ex.ParamName, "_this");

            Test.If.Action.ThrowsException(() => empty.MinimumT(), 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.MinimumT(), out argEx);
            Test.If.Value.IsEqual(argEx.ParamName, "_this");
            Test.If.String.StartsWith(argEx.Message, "The enumeration only contains null values.");
        }
Exemple #3
0
        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.");
        }
Exemple #4
0
        void MinComparerT_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.Minimum <Dummy>(null, null), out ArgumentNullException ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "_this");

            Test.If.Action.ThrowsException(() => IEnumerableTExtensions.Minimum(null, Comparer <Dummy> .Default), out ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "_this");

            Test.If.Action.ThrowsException(() => notEmpty.Minimum(null), out ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "comparer");

            Test.If.Action.ThrowsException(() => empty.Minimum(Comparer <Dummy> .Default), 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.Minimum(Comparer <Dummy> .Default), out ex2);
            Test.If.Value.IsEqual(ex2.ParamName, "_this");
            Test.If.String.StartsWith(ex2.Message, "The enumeration only contains null values.");
        }