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); }
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'); }
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>(); }
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>(); }
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]"); }
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]"); }
public void WeCanAlsoSeeTheDifferenceBetweenTwoDifferentInstancesOfTheSameTypeWhithIdenticalToString() { Person dad = new Person { Name = "John" }; Person uncle = new Person { Name = "John" }; Check.That(uncle).IsEqualTo(dad); }
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]"); }
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]."); }
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]"); }
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]"); }
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: \\[.*\\]"); }
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]"); }
public void IsNotEqualToWorksObject() { var heroe = new Person { Name = "Gandhi" }; var badGuy = new Person { Name = "Pol Pot" }; Check.That(heroe).IsNotEqualTo(badGuy); }
public void InheritsFromThrowsExceptionWhenFailing() { var father = new Person { Name = "Odysseus" }; Check.That(father).InheritsFrom<NFluent.Tests.Child>(); }
public void CanNegateIsEqualToWithObject() { var heroe = new Person { Name = "Gandhi" }; Check.That(heroe).Not.IsEqualTo(null); }
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); }
namespace NFluent.Tests