コード例 #1
0
        private static AreEqual GetOverriddenBridgeEquals(AreEqual bridgeEquals)
        {
            return((x, y) =>
            {
                // There are some difficult cases to consider here - in the simplest interesting case, both objects are of the same [ObjectLiteral] type and that type has an Equals method and
                // we call it against the first object, passing a reference to the second. The next simplest interesting case is when one of the objects is null and the other is an [ObjectLiteral]
                // with an Equals method. But things start to get more complicated if the first object is a non-null [ObjectLiteral] and the second is a non-null non-[ObjectLiteral] - for example,
                // if x is a NonBlankTrimmedString ([ObjectLiteral]) and y is an Optional<NonBlankTrimmedString> (non-[ObjectLiteral]) then the NonBlankTrimmedString Equals will say that they don't
                // match (because their types are not the same) but the Optional<NonBlankTrimmedString> Equals method would say that they DO - and that should be allowed a chance to do so.
                var customObjectLiteralMethodForFirstArgumentIfAny = TryToCustomObjectLiteralEqualsMethod(x);
                if (customObjectLiteralMethodForFirstArgumentIfAny != null)
                {
                    if (Script.Write <bool>("{0}.apply({1}, [{2}])", customObjectLiteralMethodForFirstArgumentIfAny, x, y))
                    {
                        return true;
                    }
                }
                var customObjectLiteralMethodForSecondArgumentIfAny = TryToCustomObjectLiteralEqualsMethod(y);
                if (customObjectLiteralMethodForSecondArgumentIfAny != null)
                {
                    if (Script.Write <bool>("{0}.apply({1}, [{2}])", customObjectLiteralMethodForSecondArgumentIfAny, y, x))
                    {
                        return true;
                    }
                }

                // Pass the full arguments array to bridgeEquals in case the Bridge internals include any additional metadata arguments, other than just the x and y values
                return Script.Write <bool>("{0}.apply(this, arguments)", bridgeEquals);
            });
        }
コード例 #2
0
ファイル: PublicTest.cs プロジェクト: LosManos/CompulsoryCow
        public void Public_FullCopy_ReturnTrue()
        {
            //	#	Arrange.
            var source      = Dto.CreateRandomised(_pr);
            var destination = source.FullCopy();

            //	#	Act.
            var res = AreEqual.Public(source, destination);

            //	# Assert.
            Assert.IsTrue(res);
        }
コード例 #3
0
        public void AreEqualIsTrue()
        {
            object   target           = 1;
            object   comparisonObject = 1;
            AreEqual rule             = new AreEqual("AreEqual", "AreEqualIsTrue", target, comparisonObject);
            Result   result           = rule.Execute();

            Assert.IsTrue(result.IsValid);
            Assert.IsNotNullOrEmpty(result.Message);
            Assert.IsNotNull(result.RulePolicy);
            Assert.AreEqual(result.RulePolicy.Severity, Severity.Exception);
        }
コード例 #4
0
        public void TestEqual()
        {
            AreEqual toNumber = new AreEqual();

            toNumber.Parameters = new List <Token>()
            {
                "-12".toToken(CefType.NumberLiteral), "-12".toToken(CefType.NumberLiteral)
            };
            var res = toNumber.Exec(null);

            res.Wait();

            Assert.AreEqual((int)res.Result.Value, 1);
        }
コード例 #5
0
ファイル: PublicTest.cs プロジェクト: LosManos/CompulsoryCow
        public void Public_NotFullCopyOfPublic_ReturnFalse()
        {
            //	#	Arrange.
            var source = Dto.CreateRandomised(_pr);

            var destination = source.FullCopy()
                              .With(d => d.MyPublicInt = _pr.Int());

            Assert.AreNotEqual(source.MyPublicInt, destination.MyPublicInt, "Sobriety check that what should be randomised to differ really does differ.");

            //	#	Act.
            var res = AreEqual.Public(source, destination);

            //	# Assert.
            Assert.IsFalse(res);
        }
コード例 #6
0
        public void PublicDepth_InfiniteDepth_StopForNothing()
        {
            //  #   Arrange.
            var equal = Dto.CreatePair(
                _pr,
                CreateInfiniteEqualsList(Dto.Pair.Equal));
            var notEqual = Dto.CreatePair(
                _pr,
                CreateInfiniteEqualsList(Dto.Pair.Differs));

            //  #   Act.
            var res1 = AreEqual.Public(AreEqual.Depth.Infinite, equal.Item1, equal.Item2);
            var res2 = AreEqual.Public(AreEqual.Depth.Infinite, notEqual.Item1, notEqual.Item2);

            //  #   Assert.
            Assert.IsTrue(res1);
            Assert.IsFalse(res2);
        }
コード例 #7
0
        public void PublicDepth_SetDepth_OnlyCompareToThatDepth()
        {
            //  #   Arrange.
            var equal = Dto.CreatePair(
                _pr,
                new[] { Dto.Pair.Equal, Dto.Pair.Equal, Dto.Pair.Differs });
            var notEqual = Dto.CreatePair(
                _pr,
                new[] { Dto.Pair.Equal, Dto.Pair.Differs, Dto.Pair.Equal });

            //  #   Act.
            var res1 = AreEqual.Public((AreEqual.Depth) 2, equal.Item1, equal.Item2);
            var res2 = AreEqual.Public((AreEqual.Depth) 2, notEqual.Item1, notEqual.Item2);

            //  #   Assert.
            Assert.IsTrue(res1);
            Assert.IsFalse(res2);
        }
コード例 #8
0
        public void PublicDepth_NoDepth_OnlyCompareImmediateObject()
        {
            //  #   Arrange.
            var equal = Dto.CreatePair(
                _pr,
                new[] { Dto.Pair.Equal, Dto.Pair.Differs });
            var notEqual = Dto.CreatePair(
                _pr,
                new[] { Dto.Pair.Differs, Dto.Pair.Equal });

            //  #   Act.
            var res1 = AreEqual.Public(AreEqual.Depth.None, equal.Item1, equal.Item2);
            var res2 = AreEqual.Public(AreEqual.Depth.None, notEqual.Item1, notEqual.Item2);

            //  #   Assert.
            Assert.IsTrue(res1);
            Assert.IsFalse(res2);
        }
コード例 #9
0
 /// <summary>
 ///   Creates the rule.
 /// </summary>
 /// <param name="target"> </param>
 /// <returns> </returns>
 public override RulePolicy CreateRule(object target)
 {
     Rule = new AreEqual(RuleName, FailMessage, target, comparisonTarget);
     return(Rule);
 }