Object instance Assertions

			MyClass actual;
			...
			actual.Should().Be.EqualTo(expectedInstance);
			actual.Should().Be.Null();
			actual.Should().Be.SameInstanceAs(expectedInstance);
			actual.Should().Be.InstanceOf<SomeClass>();
			actual.Should().Be.OfType<SomeClass>();
			actual.Should().Be.AssignableFrom<SomeClass>();
			actual.Should().Be.AssignableTo<SomeClass>();
			actual.Should().Be.BinarySerializable();
			actual.Should().Be.XmlSerializable();

Examples with negation

			actual.Should().Not.Be.EqualTo(notExpectedInstance);
			actual.Should().Not.Be.Null();

Examples with chain

			actual.Should()
				.Be.EqualTo(notExpectedInstance)
				.And.Not.Be.SameInstanceAs(anotherInstance)
				.And.Be.BinarySerializable();

Example using ValueOf

			object instanceOfClass;
			...
			instanceOfClass.Should()
				.Be.AssignableTo<BaseClass>()
				.And.Be.OfType<InheritedClass>()
				.And.ValueOf.OneProperty
					.Should().Be.Null();
After the assertion Be.OfType<InheritedClass>() we know which is the concrete type of the variable instanceOfClass so we can begin a new assertion based on one of the properties of instanceOfClass (see .And.ValueOf.OneProperty.Should().Be.Null()).

Last edited Oct 29, 2009 at 2:11 PM by fabiomaulo, version 3

Comments

No comments yet.