public void Build_Builds_Object_From_Delegate_Supplied() { const int expected = 11; var builder = new DelegateBuilder<int>(() => expected); Assert.AreEqual(builder.Build(), expected); }
/// <summary> /// Builds this method into a delegate that invokes the method using the argument to the first /// parameter of the action as the target object and returns void. /// </summary> /// <remarks><b>Must be non-static method.</b> For static methods, see <see cref="BuildDelegateStatic{TDelegate}(MethodInfo, Type[])"/>.</remarks> /// <typeparam name="TDelegate">The type of <see cref="Delegate"/> to build the method into.</typeparam> /// <param name="method">The method to build into an action.</param> /// <exception cref="IncompatibleInstanceException">The method is static and no instance is given. /// -or-The method is non-static and an instance is given. /// -or-The method is not defined for the instance given.</exception> /// <exception cref="ArgumentCountMismatchException">The number of arguments given does not match the /// number of parameters on the given method.</exception> /// <exception cref="IncompatibleArgumentTypeException">An argument value given can't be cast to be compatible with the /// corresponding parameter in the method signature.</exception> /// <exception cref="IncompatibleParameterTypeException">An argument-mapped parameter type given can't be cast to be compatible with the /// corresponding parameter in the method signature.</exception> /// <exception cref="IncompatibleReturnTypeException">The return type of the method cannot be converted into the given return type.</exception> /// <exception cref="ArgumentNullException"><paramref name="method"/> is null.</exception> public static TDelegate CreateDelegate <TDelegate>(this MethodInfo method, Action <DelegateBuilder> builderSetup) where TDelegate : Delegate { var builder = new DelegateBuilder(method); builderSetup(builder); return(builder.Build <TDelegate>()); }
public void Build_BuildAnActionFromTypeAndMethodInfo_ReturnsActionThatDoesNotThrow() { var analyzer = new Analyzer(); PerformanceSet set = analyzer.GetPerformanceSets((typeof(Test).Assembly)).First(); PerformanceUnit performanceUnit = set.PerformanceUnits.First(); var builder = new DelegateBuilder(); Action action = builder.Build(set.Type, performanceUnit.MethodInfo); Assert.DoesNotThrow(action.Invoke); }
public void Run_RunsAMarkedMethodOneHundredTimes_ReturnsResultWithOneHundredResults() { var analyzer = new Analyzer(); IEnumerable<PerformanceSet> sets = analyzer.GetPerformanceSets((typeof (Test).Assembly)); PerformanceSet set = sets.First(); PerformanceUnit unit = set.PerformanceUnits.First(); MethodInfo methodInfo = unit.MethodInfo; var builder = new DelegateBuilder(); Action action = builder.Build(set.Type, methodInfo); var runner = new UnitRunner(); Result result = runner.Run(set.Name, methodInfo.Name, action, unit.Runs); Assert.IsTrue(result.Success); }
public void Run_RunsAMarkedMethodOneHundredTimes_ReturnsResultWithOneHundredResults() { var analyzer = new Analyzer(); IEnumerable <PerformanceSet> sets = analyzer.GetPerformanceSets((typeof(Test).Assembly)); PerformanceSet set = sets.First(); PerformanceUnit unit = set.PerformanceUnits.First(); MethodInfo methodInfo = unit.MethodInfo; var builder = new DelegateBuilder(); Action action = builder.Build(set.Type, methodInfo); var runner = new UnitRunner(); Result result = runner.Run(set.Name, methodInfo.Name, action, unit.Runs); Assert.IsTrue(result.Success); }