예제 #1
0
        void FromDelegate()
        {
            IComparer comp = null;

            Test.If.Action.ThrowsException(() => comp = DynamicComparer.FromDelegate(null), out ArgumentNullException ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "compare");

            Test.IfNot.Action.ThrowsException(() => comp = DynamicComparer.FromDelegate((x, y) => 21), out Exception ex2);
        }
        void ComparisonInvokes()
        {
            IComparer comp   = null;
            Int32     result = 0;

            comp = DynamicComparer.FromDelegate((x, y) => throw new NotImplementedException());
            Test.If.Action.ThrowsException(() => result = comp.Compare(0, 1), out NotImplementedException ex1);

            comp = DynamicComparer.FromDelegate((x, y) => 42);
            Test.IfNot.Action.ThrowsException(() => result = comp.Compare(0, 1), out Exception ex2);
            Test.If.Value.IsEqual(result, 42);
        }
예제 #3
0
        void FromDelegateT()
        {
            IComparer <Dummy> comp   = null;
            Int32             result = 0;

            Test.If.Action.ThrowsException(() => comp = DynamicComparer.FromDelegate <Dummy>(null), out ArgumentNullException ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "compare");

            Test.IfNot.Action.ThrowsException(() => comp = DynamicComparer.FromDelegate <Dummy>((x, y) => 42), out Exception ex2);

            result = comp.Compare(0, 1);
            Test.If.Value.IsEqual(result, 42);
        }
예제 #4
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.");
        }