/// <summary> /// OnAsyncMethodEnd callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TReturn">Type of the return value</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="returnValue">Return value</param> /// <param name="exception">Exception instance in case the original code threw an exception.</param> /// <param name="state">Calltarget state value</param> /// <returns>A response value, in an async scenario will be T of Task of T</returns> public static CallTargetReturn <TReturn> OnMethodEnd <TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state) where TTarget : ITestMethodRunner { if (returnValue is Array returnValueArray && returnValueArray.Length == 1) { object unitTestResultObject = returnValueArray.GetValue(0); if (unitTestResultObject != null && unitTestResultObject.TryDuckCast <UnitTestResultStruct>(out var unitTestResult)) { var outcome = unitTestResult.Outcome; if (outcome == UnitTestResultOutcome.Inconclusive || outcome == UnitTestResultOutcome.NotRunnable || outcome == UnitTestResultOutcome.Ignored) { // This instrumentation catches all tests being ignored if (state.State != null && state.State.TryDuckCast <ITestMethodRunner>(out var testMethodRunner)) { var scope = MsTestIntegration.OnMethodBegin(testMethodRunner.TestMethodInfo, testMethodRunner.GetType()); scope.Span.SetTag(TestTags.Status, TestTags.StatusSkip); scope.Span.SetTag(TestTags.SkipReason, unitTestResult.ErrorMessage); scope.Dispose(); } } } } return(new CallTargetReturn <TReturn>(returnValue)); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TTestMethod">Type of the ITestMethod</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="testMethod">Test method instance</param> /// <returns>Calltarget state value</returns> public static CallTargetState OnMethodBegin <TTarget, TTestMethod>(TTarget instance, TTestMethod testMethod) where TTestMethod : ITestMethod, IDuckType { if (!MsTestIntegration.IsEnabled) { return(CallTargetState.GetDefault()); } var scope = MsTestIntegration.OnMethodBegin(testMethod, testMethod.Type); return(new CallTargetState(scope)); }