private void ValidateFinishTracer(GetTracerParameters getTracerParameters, FinishTracerParameters finishTracerParameters, object expectedReturnValue, Exception expectedException) { // validate that finish tracer was called Assert.IsTrue(finishTracerParameters.finishTracerCalled, "NewRelic.Agent.Core.FinishTracer was not called."); // validate that FinishTracer received all the right parameters Assert.AreEqual(getTracerParameters.tracer, finishTracerParameters.tracerObject, "The tracer received by finish tracer doesn't match the one we returned from GetTracer."); Assert.AreEqual(expectedReturnValue, finishTracerParameters.returnValue, "FinishTracer did not receive the correct returnValue."); Assert.AreEqual(expectedException, finishTracerParameters.exceptionObject, "FinishTracer did not receive the expected exception."); }
protected FinishTracerParameters DefaultFinishTracerImplementation() { var finishTracerParameters = new FinishTracerParameters(); // setup the code to execute when NewRelic.Agent.Core.FinishTracer is called SetFinishTracerDelegate((Object tracerObject, Object returnValue, Object exceptionObject) => { // we can't assert in here so save off the variables and assert later finishTracerParameters.tracerObject = tracerObject; finishTracerParameters.returnValue = returnValue; finishTracerParameters.exceptionObject = exceptionObject; // set the flag indicating the tracer was called, we'll be asserting on that later finishTracerParameters.finishTracerCalled = true; }); return(finishTracerParameters); }
protected void ValidateTracers(GetTracerParameters getTracerParameters, FinishTracerParameters finishTracerParameters, String expectedMethodName, String expectedArgumentSignature, object expectedInvocationTarget, object[] expectedParameters, object expectedReturnValue, Exception expectedException, String expectedTypeName = "NewRelic.Agent.Tests.ProfiledMethods.ProfiledMethods") { ValidateGetTracer(getTracerParameters, expectedMethodName, expectedArgumentSignature, expectedInvocationTarget, expectedParameters, expectedTypeName); ValidateFinishTracer(getTracerParameters, finishTracerParameters, expectedReturnValue, expectedException); }
public void nested_overloads() { // setup the callbacks for GetTracer and FinishTracer var getOverloadObjectTracerParameters = new GetTracerParameters(); var getOverloadStringTracerParameters = new GetTracerParameters(); // setup the code to execute when NewRelic.Agent.Core.GetTracer is called SetGetTracerDelegate((String tracerFactoryName, UInt32 tracerArguments, String metricName, String assemblyName, Type type, String typeName, String methodName, String argumentSignature, Object invocationTarget, Object[] args, UInt64 functionId) => { if (argumentSignature == "System.Object") { // we can't assert in here so save off the variables and assert later getOverloadObjectTracerParameters.tracerFactoryName = tracerFactoryName; getOverloadObjectTracerParameters.tracerArguments = tracerArguments; getOverloadObjectTracerParameters.metricName = metricName; getOverloadObjectTracerParameters.assemblyName = assemblyName; getOverloadObjectTracerParameters.type = type; getOverloadObjectTracerParameters.typeName = typeName; getOverloadObjectTracerParameters.methodName = methodName; getOverloadObjectTracerParameters.argumentSignature = argumentSignature; getOverloadObjectTracerParameters.invocationTarget = invocationTarget; getOverloadObjectTracerParameters.args = args; // set the flag indicating the tracer was called, we'll be asserting on that later getOverloadObjectTracerParameters.getTracerCalled = true; // create a new GUID for this tracer and push it onto our stack of GUIDs getOverloadObjectTracerParameters.tracer = Guid.NewGuid(); // return the GUID as the tracer object, we'll validate that FinishTracer gets it return(getOverloadObjectTracerParameters.tracer); } else if (argumentSignature == "System.String") { // we can't assert in here so save off the variables and assert later getOverloadStringTracerParameters.tracerFactoryName = tracerFactoryName; getOverloadStringTracerParameters.tracerArguments = tracerArguments; getOverloadStringTracerParameters.metricName = metricName; getOverloadStringTracerParameters.assemblyName = assemblyName; getOverloadStringTracerParameters.type = type; getOverloadStringTracerParameters.typeName = typeName; getOverloadStringTracerParameters.methodName = methodName; getOverloadStringTracerParameters.argumentSignature = argumentSignature; getOverloadStringTracerParameters.invocationTarget = invocationTarget; getOverloadStringTracerParameters.args = args; // set the flag indicating the tracer was called, we'll be asserting on that later getOverloadStringTracerParameters.getTracerCalled = true; // create a new GUID for this tracer and push it onto our stack of GUIDs getOverloadStringTracerParameters.tracer = Guid.NewGuid(); // return the GUID as the tracer object, we'll validate that FinishTracer gets it return(getOverloadStringTracerParameters.tracer); } else { return(null); } }); var finishOverloadObjectTracerParameters = new FinishTracerParameters(); var finishOverloadStringTracerParameters = new FinishTracerParameters(); // setup the code to execute when NewRelic.Agent.Core.FinishTracer is called SetFinishTracerDelegate((Object tracerObject, Object returnValue, Object exceptionObject) => { if ((Guid)(tracerObject) == getOverloadObjectTracerParameters.tracer) { // we can't assert in here so save off the variables and assert later finishOverloadObjectTracerParameters.tracerObject = tracerObject; finishOverloadObjectTracerParameters.returnValue = returnValue; finishOverloadObjectTracerParameters.exceptionObject = exceptionObject; // set the flag indicating the tracer was called, we'll be asserting on that later finishOverloadObjectTracerParameters.finishTracerCalled = true; } else if ((Guid)(tracerObject) == getOverloadStringTracerParameters.tracer) { // we can't assert in here so save off the variables and assert later finishOverloadStringTracerParameters.tracerObject = tracerObject; finishOverloadStringTracerParameters.returnValue = returnValue; finishOverloadStringTracerParameters.exceptionObject = exceptionObject; // set the flag indicating the tracer was called, we'll be asserting on that later finishOverloadStringTracerParameters.finishTracerCalled = true; } }); // call the method that will be instrumented Object parameter = new Object(); Assert.DoesNotThrow(() => { Overloaded(parameter); }, "Exception should not have been thrown."); var expectedOverloadObjectParameters = new object[] { parameter }; var expectedOverloadStringParameters = new object[] { parameter.ToString() }; var expectedOverloadObjectArgumentSignature = "System.Object"; var expectedOverloadStringArgumentSignature = "System.String"; ValidateTracers(getOverloadObjectTracerParameters, finishOverloadObjectTracerParameters, "Overloaded", expectedOverloadObjectArgumentSignature, this, expectedOverloadObjectParameters, null, null); ValidateTracers(getOverloadStringTracerParameters, finishOverloadStringTracerParameters, "Overloaded", expectedOverloadStringArgumentSignature, this, expectedOverloadStringParameters, null, null); }