Objects API

up

Here are the examples of how you can use the should template with objects.

Summary

Examples

Be null

Success expectations

    Object o = null;

    o.should.beNull;
    (new Object).should.not.beNull;

    /// or using the Assert utility
    Assert.beNull(o);
    Assert.notNull(new Object);

Failing expectations

    Object o = null;

    o.should.not.beNull;
    (new Object).should.beNull;

Instance of

  class BaseClass { }
  class ExtendedClass : BaseClass { }
  class SomeClass { }
  class OtherClass { }

  auto someObject = new SomeClass;
  auto otherObject = new OtherClass;
  auto extendedObject = new ExtendedClass;

Success expectations

  someObject.should.be.instanceOf!SomeClass;
  extendedObject.should.be.instanceOf!BaseClass;

  someObject.should.not.be.instanceOf!OtherClass;
  someObject.should.not.be.instanceOf!BaseClass;

Failing expectations

  otherObject.should.be.instanceOf!SomeClass;
  otherObject.should.not.be.instanceOf!OtherClass;