Esempio n. 1
0
        void FromDelegate()
        {
            IEqualityComparer comp = null;

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

            Test.If.Action.ThrowsException(() => comp = DynamicEqualityComparer.FromDelegate(null, (obj) => 42), out ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "equals");

            Test.If.Action.ThrowsException(() => comp = DynamicEqualityComparer.FromDelegate((x, y) => true, null), out ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "getHashCode");

            Test.IfNot.Action.ThrowsException(() => comp = DynamicEqualityComparer.FromDelegate((x, y) => true, (obj) => 42), out Exception ex2);
        }
Esempio n. 2
0
        void ComparisonInvokes()
        {
            IEqualityComparer comp   = null;
            Boolean           result = false;
            Int32             hash   = 0;

            comp = DynamicEqualityComparer.FromDelegate((x, y) => throw new NotImplementedException(), (obj) => throw new NotImplementedException());
            Test.If.Action.ThrowsException(() => result = comp.Equals(0, 1), out NotImplementedException ex1);
            Test.If.Action.ThrowsException(() => hash   = comp.GetHashCode(0), out ex1);

            comp = DynamicEqualityComparer.FromDelegate((x, y) => true, (obj) => 42);
            Test.IfNot.Action.ThrowsException(() => result = comp.Equals(0, 1), out Exception ex2);
            Test.If.Value.IsEqual(result, true);

            Test.IfNot.Action.ThrowsException(() => hash = comp.GetHashCode(0), out ex2);
            Test.If.Value.IsEqual(hash, 42);
        }
Esempio n. 3
0
        void FromDelegateT()
        {
            IEqualityComparer <Dummy> comp = null;
            Boolean result = false;
            Int32   hash   = 0;

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

            Test.If.Action.ThrowsException(() => comp = DynamicEqualityComparer.FromDelegate <Dummy>(null, (obj) => 42), out ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "equals");

            Test.If.Action.ThrowsException(() => comp = DynamicEqualityComparer.FromDelegate <Dummy>((x, y) => true, null), out ex1);
            Test.If.Value.IsEqual(ex1.ParamName, "getHashCode");

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

            result = comp.Equals(0, 1);
            Test.If.Value.IsEqual(result, true);

            hash = comp.GetHashCode(0);
            Test.If.Value.IsEqual(hash, 42);
        }