示例#1
0
        public static void FillEqualityErrorMessage(FluentMessage msg, object instance, object expected, bool negated,
                                                    bool usingOperator)
        {
            var operatorText = negated ? "different from" : string.Empty;

            if (negated)
            {
                msg.Expected(expected).Comparison(operatorText).WithType();
                return;
            }

            // shall we display the type as well?
            var withType = instance != null && expected != null && instance.GetType() != expected.GetType() ||
                           instance == null;

            // shall we display the hash too
            var withHash = instance != null && expected != null && instance.GetType() == expected.GetType() &&
                           instance.ToStringProperlyFormatted() == expected.ToStringProperlyFormatted();

            msg.On(instance)
            .WithType(withType)
            .WithHashCode(withHash)
            .And.Expected(expected)
            .WithType(withType)
            .Comparison(operatorText)
            .WithHashCode(withHash);
        }
示例#2
0
            public FluentMessage BuildMessage <T>(IChecker <T, ICheck <T> > checker, bool negated)
            {
                FluentMessage result = null;

                if (this.DoValuesMatches == negated)
                {
                    if (negated)
                    {
                        result =
                            checker.BuildShortMessage(
                                string.Format(
                                    "The {{0}}'s {0} has the same value in the comparand, whereas it must not.",
                                    this.Expected.FieldLabel.DoubleCurlyBraces()));
                        EqualityHelper.FillEqualityErrorMessage(result, this.actual.Value, this.expected.Value, true);
                    }
                    else
                    {
                        if (!this.ExpectedFieldFound)
                        {
                            result = checker.BuildShortMessage(
                                string.Format(
                                    "The {{0}}'s {0} is absent from the {{1}}.",
                                    this.Expected.FieldLabel.DoubleCurlyBraces()));
                            result.Expected(this.expected.Value);
                        }
                        else
                        {
                            result =
                                checker.BuildShortMessage(
                                    string.Format(
                                        "The {{0}}'s {0} does not have the expected value.",
                                        this.Expected.FieldLabel.DoubleCurlyBraces()));
                            EqualityHelper.FillEqualityErrorMessage(result, this.actual.Value, this.expected.Value, false);
                        }
                    }
                }

                return(result);
            }
示例#3
0
        public static void FillEqualityErrorMessage(FluentMessage msg, object instance, object expected, bool negated)
        {
            if (negated)
            {
                msg.Expected(expected).Comparison("different from").WithType();
                return;
            }

            // shall we display the type as well?
            var withType = (instance != null && expected != null && instance.GetType() != expected.GetType()) ||
                           (instance == null);

            // shall we display the hash too
            var withHash = instance != null && expected != null && instance.GetType() == expected.GetType() &&
                           instance.ToString() == expected.ToString();

            msg.On(instance)
            .WithType(withType)
            .WithHashCode(withHash)
            .And.Expected(expected)
            .WithType(withType)
            .WithHashCode(withHash);
            return;
        }