Mock an APM instance

Hi @spark,

we actually did not think that MockPayloadSender or MockConfigSnapshot would be something that our users would use.

I think when you do unit tests, you don't actually need to test the agent.

So, if you have a class where you for example use the public agent API, you can just pass an ITracer instance into your code - in production this would come from the real agent and in a unit test you can just pass null.

Like here:

public void MyMethod(ITracer tracer)
{
	// If ITracer is a real tracer, it'll start the transaction, if ITracer is null, nothing will happen here 
	var transaction = tracer?.StartTransaction("SampleTransaction", "SampleSpan");
	try
	{
		// your code with here
	}
	catch (Exception e)
	{
		transaction?.CaptureException(e);
		throw;
	}
	finally
	{
		transaction?.End();
	}
}

In prod. code you can pass Agent.Tracer into this method, in a unit test just leave it to null. The concept is the same if you unit test a class - you can e.g. dependency inject in the constructor.