Esempio n. 1
0
                private IEnumerable <CallThatShouldThrow> GetArgumentPermutationsThatShouldThrow()
                {
                    var result = new List <CallThatShouldThrow>();
                    int index  = 0;

                    foreach (var argument in this.ValidArguments)
                    {
                        if (argument.Value != null && IsNullableType(argument.ArgumentType))
                        {
                            var permutation = new CallThatShouldThrow
                            {
                                ArgumentName = argument.Name,
                                Arguments    = this.ArgumentValues.Take(index)
                                               .Concat(default(object))
                                               .Concat(this.ArgumentValues.Skip(index + 1))
                                               .ToArray()
                            };
                            result.Add(permutation);
                        }

                        index++;
                    }

                    return(result);
                }
            private static string GetFailingCallDescription(CallThatShouldThrow call)
            {
                var result = new StringBuilder();

                result.Append("(");
                AppendArgumentList(result, call.Arguments);
                result.Append(") ");

                AppendFailReason(result, call);

                return(result.ToString());
            }
 private static void AppendFailReason(StringBuilder description, CallThatShouldThrow call)
 {
     if (call.Thrown == null)
     {
         description.Append("did not throw any exception.");
     }
     else
     {
         var argumentNullException = call.Thrown as ArgumentNullException;
         if (argumentNullException != null)
         {
             description.Append("threw ArgumentNullException with wrong argument name, it should be \"{0}\".".FormatInvariant(call.ArgumentName));
         }
         else
         {
             description.Append("threw unexpected {0}.".FormatInvariant(call.Thrown.GetType().FullName));
         }
     }
 }
            private IEnumerable<CallThatShouldThrow> GetArgumentPermutationsThatShouldThrow()
            {
                var result = new List<CallThatShouldThrow>();
                int index = 0;

                foreach (var argument in this.ValidArguments)
                {
                    if (argument.Value != null && IsNullableType(argument.ArgumentType))
                    {
                        var permutation = new CallThatShouldThrow();
                        permutation.ArgumentName = argument.Name;
                        permutation.Arguments = this.ArgumentValues.Take(index).Concat(new object[] { null }).Concat(this.ArgumentValues.Skip(index + 1)).ToArray();
                        result.Add(permutation);
                    }

                    index++;
                }

                return result;
            }
            private static string GetFailingCallDescription(CallThatShouldThrow call)
            {
                var result = new StringBuilder();

                result.Append("(");
                AppendArgumentList(result, call.Arguments);
                result.Append(") ");

                AppendFailReason(result, call);

                return result.ToString();
            }
 private static void AppendFailReason(StringBuilder description, CallThatShouldThrow call)
 {
     if (call.Thrown == null)
     {
         description.Append("did not throw any exception.");
     }
     else
     {
         var argumentNullException = call.Thrown as ArgumentNullException;
         if (argumentNullException != null)
         {
             description.Append(CommonExtensions.FormatInvariant("threw ArgumentNullException with wrong argument name, it should be \"{0}\".", call.ArgumentName));
         }
         else
         {
             description.Append(CommonExtensions.FormatInvariant("threw unexpected {0}.", call.Thrown.GetType().FullName));
         }
     }
 }