/// <summary> /// Gets a <see cref="IMoyaTestRunner"/> implementation for a subclass of <see cref="MoyaAttribute"/>. /// Throws a <see cref="MoyaException"/> if <paramref name="attribute"/> is not a subclass of <see cref="MoyaAttribute"/>. /// </summary> /// <param name="attribute">A <see cref="Type"/> which is a subclass of <see cref="MoyaAttribute"/>.</param> /// <returns>An implementation of <see cref="IMoyaTestRunner"/> for <paramref name="attribute"/>.</returns> public IMoyaTestRunner GetTestRunnerForAttribute(Type attribute) { Guard.IsMoyaAttribute(attribute, $"Unable to provide moya test runner for type {attribute}"); Type typeOfTestRunner = _attributeTestRunnerMapping[attribute]; IMoyaTestRunner instance = (IMoyaTestRunner)Activator.CreateInstance(typeOfTestRunner); return(instance); }
/// <summary> /// Runs a specific test runner on a method. The test runner is deduced from the specified /// argument <paramref name="attributeType"/> . The <see cref="Type"/> of <paramref name="attributeType"/> /// must be a subclass of <see cref="MoyaAttribute"/>. It must also have a mapping to a test runner /// which either explicitly or implicitly implement <see cref="IMoyaTestRunner"/>. /// </summary> /// <param name="methodInfo">A method we want to test.</param> /// <param name="attributeType">A </param> private void RunTest(MethodInfo methodInfo, Type attributeType) { if (!MethodHasAttribute(methodInfo, attributeType)) { return; } IMoyaTestRunner testRunner = _testRunnerFactory.GetTestRunnerForAttribute(attributeType); IMoyaTestRunner decoratedTestRunner = _testRunnerDecorator.DecorateTestRunner(testRunner); _testResults.Add(decoratedTestRunner.Execute(methodInfo)); }
/// <summary> /// Runs one or more user made test runners. /// </summary> /// <param name="testRunners">The test runner(s) to run.</param> /// <param name="methodInfo">The targeted <see cref="MethodInfo"/> which will be run by the test runners.</param> private void RunCustomTestRunners(IEnumerable <IMoyaTestRunner> testRunners, MethodInfo methodInfo) { foreach (var testRunner in testRunners) { var attributeType = _testRunnerFactory.GetAttributeForTestRunner(testRunner.GetType()); if (MethodHasAttribute(methodInfo, attributeType.GetType())) { IMoyaTestRunner decoratedTestRunner = _testRunnerDecorator.DecorateTestRunner(testRunner); _testResults.Add(decoratedTestRunner.Execute(methodInfo)); } } }
public TestResultTests() { IMoyaTestRunnerDecorator testRunnerDecorator = new MoyaTestRunnerDecorator(); _testRunner = testRunnerDecorator.DecorateTestRunner(new StressTestRunner()); }
/// <summary> /// Initializes a new instance of the <see cref="TimerDecorator"/> class. /// </summary> /// <param name="testRunner">An instance of a <see cref="IMoyaTestRunner"/> /// which will be measured.</param> public TimerDecorator(IMoyaTestRunner testRunner) { DecoratedTestRunner = testRunner; }
/// <summary> /// Initializes a new instance of the <see cref="MethodNameDecorator"/> class. /// </summary> /// <param name="testRunner"> An instance of <see cref="IMoyaTestRunner"/> whose results will /// be appended method name and namespace by this <see cref="IMethodNameDecorator"/></param>. public MethodNameDecorator(IMoyaTestRunner testRunner) { DecoratedTestRunner = testRunner; }
/// <summary> /// Decorates an instance of <see cref="IMoyaTestRunner"/> with the /// following <see cref="IMoyaTestRunner"/> decorators: /// - <see cref="TimerDecorator"/> /// - <see cref="MethodNameDecorator"/> /// - <see cref="ExceptionCatcherDecorator"/> /// </summary> /// <param name="testRunner">The <see cref="IMoyaTestRunner"/> to be decorated.</param> /// <returns>A decorated <see cref="IMoyaTestRunner"/>.</returns> public IMoyaTestRunner DecorateTestRunner(IMoyaTestRunner testRunner) { return(new TimerDecorator(new MethodNameDecorator(new ExceptionCatcherDecorator(testRunner)))); }
/// <summary> /// Initializes a new instance of the <see cref="TimerDecorator"/> class. /// </summary> /// <param name="testRunner">An instance of a <see cref="IMoyaTestRunner"/> /// which will be measured.</param> public TimerDecorator(IMoyaTestRunner testRunner) { DecoratedTestRunner = testRunner; }
public TestResultTests() { IMoyaTestRunnerDecorator testRunnerDecorator = new MoyaTestRunnerDecorator(); _testRunner = testRunnerDecorator.DecorateTestRunner(new StressTestRunner()); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionCatcherDecorator"/> class. /// </summary> /// <param name="testRunner">An instance of a <see cref="IMoyaTestRunner"/> /// which we will surpress exceptions from.</param> public ExceptionCatcherDecorator(IMoyaTestRunner testRunner) { DecoratedTestRunner = testRunner; }
/// <summary> /// Initializes a new instance of the <see cref="MethodNameDecorator"/> class. /// </summary> /// <param name="testRunner"> An instance of <see cref="IMoyaTestRunner"/> whose results will /// be appended method name and namespace by this <see cref="IMethodNameDecorator"/></param>. public MethodNameDecorator(IMoyaTestRunner testRunner) { DecoratedTestRunner = testRunner; }
public void DecoratingAddsMethodNameDecorator() { IMoyaTestRunner decoratedTestRunner = _moyaTestRunnerDecorator.DecorateTestRunner(_mockTestRunner.Object); Assert.Equal(typeof(MethodNameDecorator), ((ITimerDecorator)decoratedTestRunner).DecoratedTestRunner.GetType()); }
public void DecoratingAddsTimerDecorator() { IMoyaTestRunner decoratedTestRunner = _moyaTestRunnerDecorator.DecorateTestRunner(_mockTestRunner.Object); Assert.Equal(typeof(TimerDecorator), decoratedTestRunner.GetType()); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionCatcherDecorator"/> class. /// </summary> /// <param name="testRunner">An instance of a <see cref="IMoyaTestRunner"/> /// which we will surpress exceptions from.</param> public ExceptionCatcherDecorator(IMoyaTestRunner testRunner) { DecoratedTestRunner = testRunner; }
/// <summary> /// Decorates an instance of <see cref="IMoyaTestRunner"/> with the /// following <see cref="IMoyaTestRunner"/> decorators: /// - <see cref="TimerDecorator"/> /// - <see cref="MethodNameDecorator"/> /// - <see cref="ExceptionCatcherDecorator"/> /// </summary> /// <param name="testRunner">The <see cref="IMoyaTestRunner"/> to be decorated.</param> /// <returns>A decorated <see cref="IMoyaTestRunner"/>.</returns> public IMoyaTestRunner DecorateTestRunner(IMoyaTestRunner testRunner) { return new TimerDecorator(new MethodNameDecorator(new ExceptionCatcherDecorator(testRunner))); }