예제 #1
0
        public void FormatThrowsIfFormatterIsNull()
        {
            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(NonGenericClass), NonGenericClassEmptyMethodInfo,
                                                                 EmptyArray <KeyValuePair <ISlotInfo, object> > .Instance, Mocks.Stub <IConverter>());

            Assert.Throws <ArgumentNullException>(delegate { spec.Format("Foo", null); });
        }
예제 #2
0
        public void FormatStringIsJustTheEntityIfThereAreNoSlots()
        {
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(NonGenericClass), NonGenericClassEmptyMethodInfo, slotValues, NullConverter.Instance);

            Assert.AreEqual("Foo", spec.Format("Foo", RuntimeAccessor.ServiceLocator.Resolve <IFormatter>()));
        }
예제 #3
0
        public void FormatDescribesTheMethod()
        {
            ITypeInfo   type   = Reflector.Wrap(typeof(GenericClass <>));
            IMethodInfo method = type.GetMethod("StaticMethod", PublicStatic);
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            slotValues.Add((IGenericParameterInfo)method.GenericArguments[0], typeof(int));
            slotValues.Add(method.Parameters[0], 1);

            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(GenericClass <int>), method, slotValues, NullConverter.Instance);

            Assert.AreEqual("Foo<int>(1)", spec.Format("Foo", RuntimeAccessor.ServiceLocator.Resolve <IFormatter>()));
        }
        /// <summary>
        /// Applies semantic actions to a test to estalish its runtime behavior.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method is called after <see cref="InitializeTest" />.
        /// </para>
        /// <para>
        /// The default behavior for a <see cref="TestMethodPatternAttribute" />
        /// is to configure the test actions as follows:
        /// <list type="bullet">
        /// <item><see cref="PatternTestInstanceActions.BeforeTestInstanceChain" />: Set the
        /// test step name, <see cref="PatternTestInstanceState.TestMethod" /> and
        /// <see cref="PatternTestInstanceState.TestArguments" /> based on any values bound
        /// to the test method's generic parameter and method parameter slots.</item>
        /// <item><see cref="PatternTestInstanceActions.ExecuteTestInstanceChain" />: Invoke the method.</item>
        /// </list>
        /// </para>
        /// <para>
        /// You can override this method to change the semantics as required.
        /// </para>
        /// </remarks>
        /// <param name="testBuilder">The test builder.</param>
        /// <param name="method">The test method.</param>
        protected virtual void SetTestSemantics(ITestBuilder testBuilder, IMethodInfo method)
        {
            testBuilder.TestInstanceActions.BeforeTestInstanceChain.After(
                delegate(PatternTestInstanceState testInstanceState)
            {
                MethodInvocationSpec spec = testInstanceState.GetTestMethodInvocationSpec(method);

                testInstanceState.TestMethod    = spec.ResolvedMethod;
                testInstanceState.TestArguments = spec.ResolvedArguments;

                if (!testInstanceState.IsReusingPrimaryTestStep)
                {
                    testInstanceState.NameBase = spec.Format(testInstanceState.NameBase, testInstanceState.Formatter);
                }
            });

            testBuilder.TestInstanceActions.ExecuteTestInstanceChain.After(Execute);
        }