Verification Methods

A list of verification methods.

The basic verification methods.

  • Satisfy(Expression<Func<TObject, bool>> predicateExpression)
  • Satisfy(Func<TObject, bool> predicate, string message)
  • Equal(TObject expected)
  • Be(TObject expected)
  • BeNull()

Usage

var sut = new KeyValuePair<string, int>("a", 1).ToSutSubject();

sut.Should.Satisfy(x => x.Key == "a" && x.Value == 1);
sut.Should.Satisfy(x => x.Key == "a" && x.Value == 1, "have a:1");
var sut = "abc".ToSutSubject();

sut.Should.Be(42);
sut.Should.Not.BeNull();
  • Throw<TException>()
  • Not.Throw()

Usage

var sut = new SomeClass().ToSutSubject();

sut.Invoking(x => x.GetSomething(null))
    .Should.Throw<ArgumentNullException>();

sut.Invoking(x => x.GetSomething("wrong"))
    .Should.Throw<InvalidOperationException>()
        .ValueOf(x => x.Message).Should.Be("Some error message.");

sut.Invoking(x => x.GetSomething("ok"))
    .Should.Not.Throw();

Static Methods

Subject.Invoking(() => SomeStaticClass.GetSomething(null))
    .Should.Throw<ArgumentNullException>();

Subject.Invoking(() => SomeStaticClass.GetSomething("wrong"))
    .Should.Throw<InvalidOperationException>()
        .ValueOf(x => x.Message).Should.Be("Some error message.");

Subject.Invoking(() => SomeStaticClass.GetSomething("ok"))
    .Should.Not.Throw();
  • BeTrue()
  • BeFalse()

Usage

var sut = true.ToSutSubject();

sut.Should.BeTrue();
sut.Should.Not.BeFalse();
  • BeNullOrEmpty()
  • BeNullOrWhiteSpace()
  • HaveLength(int expected)
  • EqualIgnoringCase(string expected)
  • Contain(string expected)
  • ContainIgnoringCase(string expected)
  • StartWith(string expected)
  • StartWithIgnoringCase(string expected)
  • EndWith(string expected)
  • EndWithIgnoringCase(string expected)
  • Match(string pattern)
  • Match(string pattern, RegexOptions regexOptions)
  • MatchAny(TermMatch match, params string[] expected)
  • ContainAll(params string[] expected)
  • StartWithAny(params string[] expected)
  • StartWithAny(IEnumerable<string> expected)
  • EndWithAny(params string[] expected)
  • EndWithAny(IEnumerable<string> expected)

Usage

var sut = "Hello World".ToSutSubject();

sut.Should.Not.BeNullOrEmpty();
sut.Should.Not.BeNullOrWhiteSpace();
sut.Should.HaveLength(11);
sut.Should.Equal("Hello World");
sut.Should.EqualIgnoringCase("hello world");
sut.Should.Contain("ello");
sut.Should.ContainIgnoringCase("world");
sut.Should.StartWith("Hello");
sut.Should.StartWithIgnoringCase("hello");
sut.Should.EndWith("World");
sut.Should.EndWithIgnoringCase("world");
sut.Should.Match("^Hello");
sut.Should.Match("^hello", RegexOptions.IgnoreCase);
sut.Should.MatchAny(TermMatch.Contains, "Hi", "Hello");
sut.Should.ContainAll("World", "Hello");
sut.Should.StartWithAny("Hi", "Hello");
sut.Should.EndWithAny("World", "Planet");

The methods apply to IObjectVerificationProvider of an object implementing IComparable<T>, for example numeric or date/time types like int, decimal, double, DateTime, TimeSpan, etc. Also apply to Nullable<T> values, like int?.

  • BeGreater(TObject expected)
  • BeGreaterOrEqual(TObject expected)
  • BeLess(TObject expected)
  • BeLessOrEqual(TObject expected)
  • BeInRange(TObject from, TObject to)

Usage

var sut = 42.ToSutSubject();

sut.Should.Be(42);
sut.Should.BeGreater(40);
sut.Should.BeGreaterOrEqual(42);
sut.Should.BeLess(50);
sut.Should.BeLessOrEqual(42);
sut.Should.BeInRange(40, 50);

The methods apply to IObjectVerificationProvider of a Size object.

  • BeGreater(int expectedWidth, int expectedHeight)
  • BeGreater(Size expected)
  • BeGreaterOrEqual(int expectedWidth, int expectedHeight)
  • BeGreaterOrEqual(Size expected)
  • BeLess(int expectedWidth, int expectedHeight)
  • BeLess(Size expected)
  • BeLessOrEqual(int expectedWidth, int expectedHeight)
  • BeLessOrEqual(Size expected)
  • BeInRange(int fromWidth, int fromHeight, int toWidth, int toHeight)
  • BeInRange(Size from, Size to)

Usage

var sut = page.SomeControl.Size;

sut.Should.BeGreater(50, 50);
sut.Should.BeGreaterOrEqual(50, 50);
sut.Should.BeLess(100, 100);
sut.Should.BeLessOrEqual(100, 100);
sut.Should.BeInRange(50, 50, 100, 100);
  • EqualDate(DateTime expected)

Basic and comparable verification methods also apply to DateTime objects.

Usage

var sut = DateTime.Now.ToSutSubject();

sut.Should.EqualDate(DateTime.Now.Date);

The methods apply to IObjectVerificationProvider of an object implementing IEnumerable<T> or IEnumerable<IObjectProvider<T>>, for example List<int>, string[], ControlList<Text<TOwner>, TOwner>, etc.

  • Satisfy(Expression<Func<IEnumerable<TObject>, bool>> predicateExpression)
  • Satisfy(Func<IEnumerable<TObject>, bool> predicate, string message)
  • BeEmpty()
  • HaveCount(int expected)
  • BeEquivalent(params TObject[] expected)
  • BeEquivalent(IEnumerable<TObject> expected)
  • EqualSequence(params TObject[] expected)
  • EqualSequence(IEnumerable<TObject> expected)
  • ContainSingle()
  • ContainSingle(TObject expected)
  • ContainSingle(Expression<Func<TObject, bool>> predicateExpression)
  • ContainExactly(int expectedCount, TObject expectedValue)
  • Contain(params TObject[] expected)
  • Contain(IEnumerable<TObject> expected)
  • Contain(Expression<Func<TObject, bool>> predicateExpression)
  • Contain(TermMatch match, params string[] expected)
  • Contain(TermMatch match, IEnumerable<string> expected)
  • ContainAny(params TObject[] expected)
  • ContainAny(IEnumerable<TObject> expected)
  • StartWith(params TObject[] expected)
  • StartWith(IEnumerable<TObject> expected)
  • StartWithAny(params TObject[] expected)
  • StartWithAny(IEnumerable<TObject> expected)
  • EndWith(params TObject[] expected)
  • EndWith(IEnumerable<TObject> expected)
  • EndWithAny(params TObject[] expected)
  • EndWithAny(IEnumerable<TObject> expected)
  • BeInAscendingOrder()
  • BeInDescendingOrder()
  • ConsistOf(params Expression<Func<TObject, bool>>[] predicateExpressions)
  • ConsistOnlyOf(Expression<Func<TObject, bool>> predicateExpression)
  • ConsistOnlyOf(Func<TObject, bool> predicate, string message)
  • ConsistOnlyOf(TObject expected)
  • ConsistOfSingle(Expression<Func<TObject, bool>> predicateExpression)
  • ConsistSequentiallyOf(params Expression<Func<TObject, bool>>[] predicateExpressions)

Usage

var sut = new [] { 1, 2, 3, 4 }.ToSutSubject();

sut.Should.Satisfy(x => x.Contains(3) && x.Count() == 5);
sut.Should.Satisfy(x => x.Contains(3) && x.Count() == 5, "contain 5 items including 3");
sut.Should.Not.BeEmpty();
sut.Should.HaveCount(4);
sut.Should.BeEquivalent(2, 1, 4, 3);
sut.Should.EqualSequence(1, 2, 3, 4);
sut.Should.Not.ContainSingle();
sut.Should.ContainSingle(1);
sut.Should.ContainSingle(x => x == 1);
sut.Should.ContainExactly(1, 3);
sut.Should.Contain(3, 4);
sut.Should.Contain(x => x > 1);
sut.Should.ContainAny(3, 4, 5);
sut.Should.StartWith(1, 2);
sut.Should.StartWithAny(0, 1);
sut.Should.EndWith(3, 4);
sut.Should.EndWithAny(4, 5);
sut.Should.BeInAscendingOrder();
sut.Should.Not.BeInDescendingOrder();
sut.Should.ConsistOf(x => x > 0, x => x == 3, x => x == 1, x => x < 4);
sut.Should.ConsistOnlyOf(x => x > 0 && x < 10);
sut.Should.ConsistOnlyOf(x => x > 0, "are positive");
sut.Should.Not.ConsistOnlyOf(1);
sut.Should.Not.ConsistOfSingle(x => x == 1);
sut.Should.ConsistSequentiallyOf(x => x == 0 || x == 1, x => x == 2, x => x == 3, x => x >= 4);
var sut = new [] { "Hello" }.ToSutSubject();

sut.Should.ContainSingle();
sut.Should.ConsistOfSingle("Hello");
sut.Should.IgnoringCase.ConsistOfSingle("hello");
sut.Should.ConsistOfSingle(x => x == "Hi" || x == "Hello");
sut.Should.Contain(TermMatch.StartsWith, "He");
  • BePresent()
  • BeVisible()
  • BeVisibleInViewPort()
  • BeHidden()
  • BeEnabled()
  • BeDisabled()
  • BeFocused()
  • BeReadOnly()
  • HaveClass(params string[] classNames)
  • HaveClass(IEnumerable<string> classNames)
  • BeChecked() Applies to RadioButton<TOwner> and CheckBox<TOwner>.
  • BeUnchecked() Applies to RadioButton<TOwner> and CheckBox<TOwner>.
  • HaveChecked(TValue value) Applies to CheckBoxList<TValue, TOwner>.

Usage

var sut = page.SomeInput;

sut.Should.BePresent();
sut.Should.BeVisible();
sut.Should.BeVisibleInViewPort();
sut.Should.Not.BeHidden();
sut.Should.BeEnabled();
sut.Should.Not.BeDisabled();
sut.Should.BeFocused();
sut.Should.Not.BeReadOnly();
sut.Should.HaveClass("some-class");

The methods apply to IObjectVerificationProvider of a FileInfo object.

  • Exist()

Usage

var sut = AtataContext.Current.Artifacts;

sut.Files["some.txt"].Should.Exist();

The methods apply to IObjectVerificationProvider of a DirectoryInfo object.

  • Exist()
  • ContainFile(string fileName)
  • ContainFiles(params string[] fileNames)
  • ContainFiles(IEnumerable<string> fileNames)
  • ContainDirectory(string directoryName)
  • ContainDirectories(params string[] directoryNames)
  • ContainDirectories(IEnumerable<string> directoryNames)

Usage

var sut = AtataContext.Current.Artifacts;

sut.Directories["dir1"].Should.Exist();
sut.Should.ContainDirectory("dir1");
sut.Should.ContainDirectories("dir1", "dir2");
sut.Should.ContainFile("1.txt");
sut.Should.ContainFiles("1.txt", "2.txt");