Static Assertions

Executing

The Executing is basically a short-cut to use lambdas instead explicit create a new Action.
Executing has only one method This which parameter is the Action:
			Executing.This(() => new AClass(null)).Should().Throw();

The syntax after the method This(Action action) is the same of Assertion Actions.

Examples using ExceptionExtensions and LINQ

		public class SillyClass
		{
			public SillyClass(object obj)
			{
				if (obj == null)
				{
					throw new ArgumentException("mess",
							new ArgumentNullException("mess null",
								new ArgumentOutOfRangeException("obj")));
				}
			}
		}

		[TestMethod]
		public void Example()
		{
			Executing.This(() => new SillyClass(null)).Should().Throw<ArgumentException>()
							.And.ValueOf
							.InnerExceptions()
							.OfType<ArgumentOutOfRangeException>().First()
									.ParamName.Should().Be.EqualTo("obj");

			Executing.This(() => new SillyClass(null)).Should().Throw<ArgumentException>()
							.And.ValueOf
							.InnerExceptions().Select(e => e.GetType())
									.Should().Contain(typeof(ArgumentOutOfRangeException));

			Executing.This(() => new SillyClass(null)).Should().Throw<ArgumentException>()
							.And.ValueOf
							.InnerException
							.Should().Be.OfType<ArgumentNullException>()
									.And.ValueOf.Message.Should().Be.EqualTo("mess null");
		}

Last edited Apr 13, 2010 at 10:33 PM by fabiomaulo, version 5

Comments

No comments yet.