예제 #1
0
        public TheoryCommand(IMethodInfo testMethod, object[] parameters, Type[] genericTypes)
            : base(testMethod, MethodUtility.GetDisplayName(testMethod), MethodUtility.GetTimeoutParameter(testMethod))
        {
            int idx;

            Parameters = parameters ?? new object[0];

            if (genericTypes != null && genericTypes.Length > 0)
            {
                string[] typeNames = new string[genericTypes.Length];
                for (idx = 0; idx < genericTypes.Length; idx++)
                {
                    typeNames[idx] = ConvertToSimpleTypeName(genericTypes[idx]);
                }

                DisplayName = String.Format("{0}<{1}>", DisplayName, string.Join(", ", typeNames));
            }

            ParameterInfo[] parameterInfos = testMethod.MethodInfo.GetParameters();
            string[]        displayValues  = new string[Math.Max(Parameters.Length, parameterInfos.Length)];

            for (idx = 0; idx < Parameters.Length; idx++)
            {
                displayValues[idx] = ParameterToDisplayValue(GetParameterName(parameterInfos, idx), Parameters[idx]);
            }

            for (; idx < parameterInfos.Length; idx++)  // Fill-in any missing parameters with "???"
            {
                displayValues[idx] = parameterInfos[idx].Name + ": ???";
            }

            DisplayName = String.Format("{0}({1})", DisplayName, string.Join(", ", displayValues));
        }
예제 #2
0
            public IEnumerable <ITestCommand> AssertCommands(string name, IMethodInfo method)
            {
                foreach (var assertion in _asserts)
                {
                    // do not capture the iteration variable because
                    // all tests would point to the same assertion
                    var    capturableAssertion = assertion;
                    Action test =
                        () =>
                    {
                        using (SpecificationPrimitiveExecutor.Execute(_context))
                        {
                            if (_do != null)
                            {
                                SpecificationPrimitiveExecutor.Execute(_do);
                            }

                            SpecificationPrimitiveExecutor.Execute(capturableAssertion);
                        }
                    };

                    string testDescription = String.Format("{0}, {1}", name, assertion.Message);

                    yield return(new ActionTestCommand(method, testDescription, MethodUtility.GetTimeoutParameter(method), test));
                }
            }
예제 #3
0
            public void TimeoutParameter()
            {
                Type       testClassType = typeof(TimeoutTestClass);
                MethodInfo methodInfo    = testClassType.GetMethod("TestAttributeWithTimeoutParameter");

                long timeout = MethodUtility.GetTimeoutParameter(Reflector.Wrap(methodInfo));

                Assert.Equal <long>(1000, timeout);
            }
예제 #4
0
 public FeatureTestCommand(IMethodInfo method, ILibrary adapter)
     : base(method, adapter.Name, MethodUtility.GetTimeoutParameter(method))
 {
     this.adapter = adapter;
 }
예제 #5
0
        public Command(MethodCall methodCall)
            : base(methodCall == null ? null : methodCall.Method, null, methodCall == null ? 0 : MethodUtility.GetTimeoutParameter(methodCall.Method))
        {
            Guard.AgainstNullArgument("methodCall", methodCall);

            this.methodCall  = methodCall;
            this.arguments   = methodCall.Arguments.ToArray();
            this.DisplayName = GetString(methodCall.Method, this.arguments, methodCall.TypeArguments.ToArray());
        }
예제 #6
0
 public SpecCommand(IMethodInfo method, bool liveOnly)
     : base(method, MethodUtility.GetDisplayName(method), MethodUtility.GetTimeoutParameter(method))
 {
     this.LiveOnly = liveOnly;
 }
 public ReleaseCommand(TheoryCommand theory, IMethodInfo method)
     : base(method, MethodUtility.GetDisplayName(method), MethodUtility.GetTimeoutParameter(method))
 {
     this.theory = theory;
 }
예제 #8
0
        public static IEnumerable <ITestCommand> ToTestCommands(IMethodInfo method)
        {
            try
            {
                if (exception == null && asserts.Count == 0)
                {
                    try
                    {
                        throw new InvalidOperationException("Must have at least one Assert in each specification");
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (exception == null && !context.HasValue)
                {
                    try
                    {
                        throw new InvalidOperationException("Must have a Context in each specification");
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (exception != null)
                {
                    yield return(new ExceptionTestCommand(method, exception));

                    yield break;
                }

                string name = context.Value.Key;

                if (@do.HasValue)
                {
                    name += " " + @do.Value.Key;
                }

                foreach (KeyValuePair <string, Action> kvp in asserts)
                {
                    List <Action> actions = new List <Action>();

                    actions.Add(context.Value.Value);
                    if (@do.HasValue)
                    {
                        actions.Add(@do.Value.Value);
                    }
                    actions.Add(kvp.Value);

                    yield return(new ActionTestCommand(method, name + ", " + kvp.Key, MethodUtility.GetTimeoutParameter(method), actions));
                }
            }
            finally
            {
                Reset();
            }
        }
예제 #9
0
 /// <param name="innerCommand">The <see cref="ITestCommand"/> to wrap</param>
 /// <param name="method">The method being used as a test</param>
 public IocLifetimeCommand(ITestCommand innerCommand, IMethodInfo method)
     : base(method, MethodUtility.GetDisplayName(method), MethodUtility.GetTimeoutParameter(method))
 {
     _innerCommand = innerCommand;
 }
예제 #10
0
 public FeatureTestCommand(IMethodInfo method, IFrameworkAdapter adapter)
     : base(method, adapter.FrameworkName, MethodUtility.GetTimeoutParameter(method))
 {
     this.adapter = adapter;
 }