Exemplo n.º 1
0
        private static EntityNamingLogic DefaultNamer()
        {
            var result = new EntityNamingLogic();

            result.SetNameBuilder(() => "dynamic");
            return(result);
        }
Exemplo n.º 2
0
        public void NotIsFalseMayThrowExceptions()
        {
            const bool tddSucks = false;

            EntityNamingLogic.ClearDefaultNameCache();
            Check.ThatCode(() => Check.That(tddSucks).Not.IsFalse())
            .IsAFailingCheckWithMessage(Environment.NewLine + "The checked boolean is false whereas it must be true." + Environment.NewLine + "The checked boolean:" + Environment.NewLine + "\t[False]");
        }
Exemplo n.º 3
0
 /// <summary>
 /// Builds a new <see cref="FluentSut{T}"/> instance.
 /// </summary>
 /// <param name="value">Value to examine.</param>
 /// <param name="reporter">Error reporter to use</param>
 /// <param name="negated">true if the check logic must be negated.</param>
 public FluentSut(T value, IErrorReporter reporter, bool negated)
 {
     this.Reporter    = reporter;
     this.value       = value;
     this.Negated     = negated;
     this.namingLogic = new EntityNamingLogic {
         EntityType = typeof(T)
     };
 }
Exemplo n.º 4
0
        public void HowGivenValueWorks()
        {
            var namer   = new EntityNamingLogic("date time");
            var message = FluentMessage.BuildMessage("The {0} is before the {1} whereas it must not.")
                          .For(namer)
                          .On("portna")
                          .And.WithGivenValue("ouaq").ToString();

            Assert.AreEqual(NewLine + "The checked date time is before the given one whereas it must not." + NewLine + "The checked date time:" + NewLine + "\t[\"portna\"]" + NewLine + "The expected date time:" + NewLine + "\t[\"ouaq\"]", message);
        }
Exemplo n.º 5
0
 public void ShouldFailWithHashesWhenSimilar()
 {
     EntityNamingLogic.ClearDefaultNameCache();
     Check.ThatCode(() => { Check.That(new Basic(1, 2)).IsEqualTo(new Basic(1, 3)); })
     .IsAFailingCheckWithMessage("",
                                 "The checked struct is different from the expected one.",
                                 "The checked struct:",
                                 "\t[NFluent.Tests.EnumOrStructRelatedTests+Basic] with HashCode: [3]",
                                 "The expected struct:",
                                 "\t[NFluent.Tests.EnumOrStructRelatedTests+Basic] with HashCode: [4]");
 }
Exemplo n.º 6
0
 public void NotIsInstanceOfThrows()
 {
     EntityNamingLogic.ClearDefaultNameCache();
     Check.ThatCode(() => Check.That(FirstLetterLowerCase).Not.IsInstanceOf <char>())
     .IsAFailingCheckWithMessage("",
                                 "The checked char is an instance of [char] whereas it must not.",
                                 "The checked char:",
                                 "\t['a'] of type: [char]",
                                 "The expected value: different from",
                                 "\tan instance of [char]");
 }
Exemplo n.º 7
0
        public void BasicTest()
        {
            var message = FluentMessage.BuildMessage("The {0} is ok.").ToString();
            var namer   = new EntityNamingLogic("string");

            Assert.AreEqual(NewLine + "The checked value is ok.", message);

            // override entity
            message = FluentMessage.BuildMessage("The {0} is ok.").For(namer).ToString();
            Assert.AreEqual(NewLine + "The checked string is ok.", message);
        }
Exemplo n.º 8
0
        public void NotIsBeforeMayThrowException()
        {
            var christmas2013   = new DateTime(2013, 12, 25);
            var newYearsEve2014 = new DateTime(2013, 12, 31);

            EntityNamingLogic.ClearDefaultNameCache();
            Check.ThatCode(() =>
            {
                Check.That(christmas2013).Not.IsBefore(newYearsEve2014);
            })
            .IsAFailingCheckWithMessage("",
                                        "The checked date time is before the given one whereas it must not.",
                                        "The checked date time:", "\t[2013-12-25T00:00:00.0000000, Kind = Unspecified]",
                                        "The expected date time: after or equal", "\t[2013-12-31T00:00:00.0000000, Kind = Unspecified]");
        }
Exemplo n.º 9
0
        public static ICheckLink <ICheck <Nationality> > IsEuropean(this ICheck <Nationality> check)
        {
            var structChecker = ExtensibilityHelper.ExtractChecker(check);
            var namer         = new EntityNamingLogic("Nationality");

            return(structChecker.ExecuteCheck(
                       () =>
            {
                if (!structChecker.Value.Equals(Nationality.English) && !structChecker.Value.Equals(Nationality.German) && !structChecker.Value.Equals(Nationality.Serbian) && !structChecker.Value.Equals(Nationality.French))
                {
                    var message = FluentMessage.BuildMessage("The {0} is not part of Europe.").For(namer).On(structChecker.Value).ToString();
                    throw new FluentCheckException(message);
                }
            },
                       FluentMessage.BuildMessage("The {0} is part of Europe whereas it must not.").For(namer).On(structChecker.Value).ToString()));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FluentMessage"/> class.
        /// </summary>
        /// <param name="message">
        /// The main message.
        /// </param>
        /// <remarks>
        /// You can use {x} as place holders for standard wordings:
        /// - {0}.
        /// </remarks>
        private FluentMessage(string message)
        {
            var format = message;

            format                  = format.Replace("{checked}", "{0}");
            format                  = format.Replace("{expected}", "{1}");
            format                  = format.Replace("{given}", "{1}");
            this.message            = format;
            this.dontRepeatExpected = NormalOrder.IsMatch(format);
            this.dontRepeatChecked  = ReverseOrder.IsMatch(format);

            this.checkedNamingLogic  = new EntityNamingLogic();
            this.expectedNamingLogic = new EntityNamingLogic();
            this.checkedLabel        = GenericLabelBlock.BuildCheckedBlock(this.checkedNamingLogic);
            this.expectedLabel       = GenericLabelBlock.BuildExpectedBlock(this.expectedNamingLogic);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Builds a new <see cref="FluentSut{T}"/> instance.
 /// </summary>
 /// <param name="other">Value to examine.</param>
 /// <param name="negated">true if the check logic must be negated.</param>
 public FluentSut(FluentSut <T> other, bool negated) : this(other.Value, other.Reporter, negated)
 {
     this.namingLogic = other.namingLogic.Clone();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Specifies the attribute to use to describe entities.
 /// </summary>
 /// <param name="newEntityDescription">The new description for the Entity.</param>
 /// <returns>The same fluent message.</returns>
 public FluentMessage For(EntityNamingLogic newEntityDescription)
 {
     this.checkedNamingLogic.Merge(newEntityDescription);
     this.expectedNamingLogic.Merge(newEntityDescription);
     return(this);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Builds a chainable check with a sub item.
        /// </summary>
        /// <param name="check">original check to link to</param>
        /// <param name="item">sub item that can be check with which</param>
        /// <param name="label">label for the sub item</param>
        /// <typeparam name="TU">type of the sut</typeparam>
        /// <typeparam name="T">type of the sub item</typeparam>
        /// <returns>A chainable link supporting Which</returns>
        public static ICheckLinkWhich <ICheck <TU>, ICheck <T> > BuildCheckLinkWhich <TU, T>(ICheck <TU> check, T item, EntityNamingLogic label)
        {
            var chk = new FluentCheck <T>(item);

            chk.SutName.Merge(label);
            return(new CheckLinkWhich <ICheck <TU>, ICheck <T> >(check, chk));
        }
Exemplo n.º 14
0
 public static GenericLabelBlock BuildGivenBlock(EntityNamingLogic namer)
 {
     return(new GenericLabelBlock("expected", "given", namer));
 }
Exemplo n.º 15
0
 public static GenericLabelBlock BuildCheckedBlock(EntityNamingLogic namer)
 {
     return(new GenericLabelBlock("checked", "checked", namer));
 }
Exemplo n.º 16
0
 internal GenericLabelBlock(string adjective, string adjectiveMessage, EntityNamingLogic namer)
 {
     this.adjective            = adjective;
     this.adjectiveForMessages = adjectiveMessage;
     this.EntityLogic          = namer;
 }