public void ExecuteWhenPassingWrongTypeThenException() { var arguments = new object[] { 4 }; Action action = () => this.testee.Execute(arguments); action .ShouldThrow <ArgumentException>() .WithMessage(ExceptionMessages.CannotCastArgumentToGuardArgument(arguments[0], this.testee.Describe())); }
/// <summary> /// Executes the guard. /// </summary> /// <param name="arguments">The state machine event arguments.</param> /// <returns>Result of the guard execution.</returns> public bool Execute(object[] arguments) { Ensure.ArgumentNotNull(arguments, "arguments"); if (arguments.Length != 1) { throw new ArgumentException(ExceptionMessages.CannotPassMultipleArgumentsToSingleArgumentGuard(arguments, this.Describe())); } if (!typeof(T).IsAssignableFrom(arguments[0].GetType())) { throw new ArgumentException(ExceptionMessages.CannotCastArgumentToGuardArgument(arguments[0], this.Describe())); } return(this.guard((T)arguments[0])); }