Dummy class for unit testing purpose.
        public void IsEqualToWorksWithObject()
        {
            var heroe = new Person { Name = "Gandhi" };
            var otherReference = heroe;

            Check.That(heroe).IsEqualTo(otherReference);
        }
        public void NotIsEqualToWithObjectThrowsExceptionWhenFailing()
        {
            var heroe = new Person { Name = "Gandhi" };
            var otherReference = heroe;

            Check.That(heroe).Not.IsEqualTo(otherReference);
        }
Example #3
0
        public void CodeSnippetForReadmeMarkdownFile()
        {
            var integers = new int[] { 1, 2, 3, 4, 5, 666 };
            Check.That(integers).Contains(3, 5, 666);

            integers = new int[] { 1, 2, 3 };
            Check.That(integers).IsOnlyMadeOf(3, 2, 1);

            var guitarHeroes = new[] { "Hendrix", "Paco de Lucia", "Django Reinhardt", "Baden Powell" };
            Check.That(guitarHeroes).ContainsExactly("Hendrix", "Paco de Lucia", "Django Reinhardt", "Baden Powell");

            var camus = new Person() { Name = "Camus" };
            var sartre = new Person() { Name = "Sartre" };
            Check.That(camus).IsNotEqualTo(sartre).And.IsInstanceOf<Person>();

            var heroes = "Batman and Robin";
            Check.That(heroes).Not.Contains("Joker").And.StartsWith("Bat").And.Contains("Robin");

            int? one = 1;
            Check.That(one).HasAValue().Which.IsPositive().And.IsEqualTo(1);

            const Nationality FrenchNationality = Nationality.French;
            Check.ThatEnum(FrenchNationality).IsNotEqualTo(Nationality.Korean);

            string motivationalSaying = "Failure is mother of success.";
            Check.That(motivationalSaying).IsNotInstanceOf<int>();

            Check.That('A').IsSameLetterAs('a');
        }
Example #4
0
        public void AndOperatorCanChainMultipleAssertionsForObject()
        {
            var camus = new Person() { Name = "Camus" };
            var sartre = new Person() { Name = "Sartre" };

            Check.That(camus).IsNotEqualTo(sartre).And.IsInstanceOf<Person>();
            Check.That(sartre).IsEqualTo(sartre).And.IsInstanceOf<Person>();
        }
Example #5
0
        public void PropertiesWorksWithArray()
        {
            Person[] persons = new Person[]
                                 {
                                     new Person { Name = "Thomas", Age = 38 },
                                     new Person { Name = "Achille", Age = 10, Nationality = Nationality.French },
                                     new Person { Name = "Anton", Age = 7, Nationality = Nationality.French },
                                     new Person { Name = "Arjun", Age = 7, Nationality = Nationality.Indian }
                                 };

            Check.That(persons.Properties("Name")).ContainsExactly("Thomas", "Achille", "Anton", "Arjun");
            Check.That(persons.Properties("Age")).ContainsExactly(38, 10, 7, 7);
            Check.That(persons.Properties("Nationality")).ContainsExactly(Nationality.Unknown, Nationality.French, Nationality.French, Nationality.Indian);
        }
 public void WeCanSeeTheDifferenceBewteenTwoDifferentObjectsThatHaveTheSameToString()
 {
     Person dad = new Person { Name = "John" };
     Person son = new Child { Name = "John" };
     Check.That(son).IsEqualTo(dad);
 }
        public void IsEqualToThrowsExceptionWhenFailingWithObject()
        {
            var heroe = new Person { Name = "Gandhi" };
            var bastard = new Person { Name = "PolPot" };

            Check.That(heroe).IsEqualTo(bastard);
        }
 public void NotInheritsFromWorks()
 {
     var hero = new Person { Name = "Arjuna" };
     Check.That(hero).Not.InheritsFrom<int>();
 }
 public void NotInheritsFromThrowsExceptionWhenFailing()
 {
     var father = new Person { Name = "Odysseus" };
     Check.That(father).Not.InheritsFrom<Person>();
 }
Example #10
0
        public void HasDifferentValueAsFailsWithCorrectMessage()
        {
            var mySelf = new Person() { Name = "dupdob" };
            var myClone = new PersonEx() { Name = "dupdob" };

            Check.ThatCode(() => {
                Check.That(myClone).HasDifferentValueThan(mySelf);
            })
                .ThrowsAny()
                .WithMessage(
                    Environment.NewLine+ "The checked value is equal to the expected one whereas it must not." + Environment.NewLine + "The expected value: different from (using operator!=)" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]");

        }
Example #11
0
 public void HasSameValueAsFailsWithCorrectMessage()
 {
     var mySelf = new Person() { Name = "dupdob" };
     var myClone = new PersonEx() { Name = "tpierrain" };
     Check.ThatCode(() => {
             Check.That(myClone).HasSameValueAs(mySelf);
         })
         .ThrowsAny()
         .WithMessage(
             Environment.NewLine+ "The checked value is different from the expected one." + Environment.NewLine + "The checked value:" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+PersonEx] of type: [NFluent.Tests.ObjectRelatedTest+PersonEx]" + Environment.NewLine + "The expected value: equals to (using operator==)" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]");
 }
Example #12
0
 public void WeCanAlsoSeeTheDifferenceBetweenTwoDifferentInstancesOfTheSameTypeWhithIdenticalToString()
 {
     Person dad = new Person { Name = "John" };
     Person uncle = new Person { Name = "John" };
     
     Check.That(uncle).IsEqualTo(dad);
 }
Example #13
0
        public void IsEqualToThrowsExceptionWhenFailingWithObject()
        {
            var heroe = new Person { Name = "Gandhi" };
            var bastard = new Person { Name = "PolPot" };

            Check.ThatCode(() =>
            {
                Check.That(heroe).IsEqualTo(bastard);
            })
            .Throws<FluentCheckException>()
            .WithMessage(Environment.NewLine+ "The checked value is different from the expected one." + Environment.NewLine + "The checked value:" + Environment.NewLine + "\t[Gandhi]" + Environment.NewLine + "The expected value:" + Environment.NewLine + "\t[PolPot]");
        }
Example #14
0
        public void NotInheritsFromThrowsExceptionWhenFailing()
        {
            var father = new Person { Name = "Odysseus" };

            Check.ThatCode(() =>
            {
                Check.That(father).Not.InheritsFrom<Person>();
            })
            .Throws<FluentCheckException>()
            .WithMessage(Environment.NewLine+ "The checked expression is part of the inheritance hierarchy or of the same type than the specified one." + Environment.NewLine + "Indeed, checked expression type:" + Environment.NewLine + "\t[NFluent.Tests.Person]" + Environment.NewLine + "is a derived type of" + Environment.NewLine + "\t[NFluent.Tests.Person].");
        }
Example #15
0
        public void InheritsFromThrowsExceptionWhenFailing()
        {
            var father = new Person { Name = "Odysseus" };

            Check.ThatCode(() =>
            {
                Check.That(father).InheritsFrom<Child>();
            })
            .Throws<FluentCheckException>()
            .WithMessage(Environment.NewLine+ "The checked expression type does not have the expected inheritance." + Environment.NewLine + "The checked expression type:" + Environment.NewLine + "\t[NFluent.Tests.Person]" + Environment.NewLine + "The expected expression type: inherits from" + Environment.NewLine + "\t[NFluent.Tests.Child]");
        }
Example #16
0
        public void NotIsEqualToWithObjectThrowsExceptionWhenFailing()
        {
            var heroe = new Person { Name = "Gandhi" };
            var otherReference = heroe;

            Check.ThatCode(() =>
            {
                Check.That(heroe).Not.IsEqualTo(otherReference);
            })
            .Throws<FluentCheckException>()
            .WithMessage(Environment.NewLine+ "The checked value is equal to the expected one whereas it must not." + Environment.NewLine + "The expected value: different from" + Environment.NewLine + "\t[Gandhi] of type: [NFluent.Tests.Person]");
        }
Example #17
0
        public void WeCanAlsoSeeTheDifferenceBetweenTwoDifferentInstancesOfTheSameTypeWhithIdenticalToString()
        {
            Person dad = new Person { Name = "John" };
            Person uncle = new Person { Name = "John" };

            Check.ThatCode(() =>
            {
                Check.That(uncle).IsEqualTo(dad);
            })
            .Throws<FluentCheckException>().AndWhichMessage().Matches(Environment.NewLine+ "The checked value is different from the expected one." + Environment.NewLine + "The checked value:" + Environment.NewLine + "\\t\\[John\\] with HashCode: \\[.*\\]" + Environment.NewLine + "The expected value:" + Environment.NewLine + "\\t\\[John\\] with HashCode: \\[.*\\]");
        }
Example #18
0
        public void WeCanSeeTheDifferenceBewteenTwoDifferentObjectsThatHaveTheSameToString()
        {
            Person dad = new Person { Name = "John" };
            Person son = new Child { Name = "John" };

            Check.ThatCode(() =>
            {
                Check.That(son).IsEqualTo(dad);
            })
            .Throws<FluentCheckException>()
            .WithMessage(Environment.NewLine+ "The checked value is different from the expected one." + Environment.NewLine + "The checked value:" + Environment.NewLine + "\t[John] of type: [NFluent.Tests.Child]" + Environment.NewLine + "The expected value:" + Environment.NewLine + "\t[John] of type: [NFluent.Tests.Person]");
        }
Example #19
0
        public void IsNotEqualToWorksObject()
        {
            var heroe = new Person { Name = "Gandhi" };
            var badGuy = new Person { Name = "Pol Pot" };

            Check.That(heroe).IsNotEqualTo(badGuy);
        }
Example #20
0
 public void InheritsFromThrowsExceptionWhenFailing()
 {
     var father = new Person { Name = "Odysseus" };
     Check.That(father).InheritsFrom<NFluent.Tests.Child>();
 }
Example #21
0
        public void CanNegateIsEqualToWithObject()
        {
            var heroe = new Person { Name = "Gandhi" };

            Check.That(heroe).Not.IsEqualTo(null);
        }
Example #22
0
 public void WeCanAlsoSeeTheDifferenceBetweenTwoDifferentInstancesOfTheSameTypeWhichHaveSameToString()
 {
     // e.g.: "\nExpecting:\n\t[John] of type: [NFluent.Tests.Person] with HashCode: [45523402]\n but was\n\t[John] of type: [NFluent.Tests.Person] with HashCode: [35287174]."
     Person dad = new Person() { Name = "John" };
     Person uncle = new Person() { Name = "John" };
     Check.That(uncle).IsEqualTo(dad);
 }
        public void FailsToUseOperator()
        {

            var mySelf = new Person() { Name = "SilNak" };
            var myClone = new PersonEx() { Name = "SilNak" };
            var mySon = new Son() { Name = "SilNak" };

            Check.That(myClone).HasSameValueAs(mySelf); 
            if (mySelf == myClone)
                Check.That(mySelf).HasSameValueAs(myClone);
            if (mySon == myClone)
                Check.That(myClone).HasSameValueAs(mySon);
            if (myClone == mySelf)
                Check.That(myClone).HasSameValueAs(mySelf);

            Check.That(myClone).HasSameValueAs(myClone);
            Check.That(mySelf).HasDifferentValueThan(4);
        }
Example #24
0
namespace NFluent.Tests