Extensions useful in tests

Exception Extensions


Sharp Tests Ex offers two useful extensions to tests exceptions tree (especially useful with integration-tests).

InnerExceptions()

IEnumerable<Exception> InnerExceptions(this Exception source)
Returns a sequence of all Inner Exceptions.

Exceptions()

IEnumerable<Exception> Exceptions(this Exception source)
Returns a sequence of {Exception} including the root exception and all Inner Exceptions.

Examples of usage are available here and here

Object Extensions

FieldValue<T>

Allow access to a private field where a public property is not available.
		public class Configuration
		{
			private int oneField;

			public void Configure()
			{
				oneField = 5;
			}
		}

		[TestMethod]
		public void Example()
		{
			var configuration = new Configuration();
			configuration.Configure();

			configuration.FieldValue<int>("oneField").Should().Be.EqualTo(5);
		}

Last edited Oct 29, 2009 at 1:15 PM by fabiomaulo, version 3

Comments

No comments yet.