public void InterceptViaCode() { Recorder.Records.Clear(); DependencyContainer container = new DependencyContainer(); container.InterceptVirtual <SpyVirtual>(typeof(SpyVirtual).GetMethod("InterceptedMethod"), new RecordingHandler()); SpyVirtual obj = container.Get <SpyVirtual>(); obj.InterceptedMethod(); obj.NonInterceptedMethod(); Assert.Equal(4, Recorder.Records.Count); Assert.Equal("Before Method", Recorder.Records[0]); Assert.Equal("In Method", Recorder.Records[1]); Assert.Equal("After Method", Recorder.Records[2]); Assert.Equal("In Non-Intercepted Method", Recorder.Records[3]); }
public void ExceptionsAreUnchanged() { Recorder.Records.Clear(); DependencyContainer container = new DependencyContainer(); container.InterceptVirtual <SpyVirtual>(typeof(SpyVirtual).GetMethod("ThrowsException"), new RecordingHandler()); SpyVirtual obj = container.Get <SpyVirtual>(); Assert.Throws <Exception>(delegate { obj.ThrowsException(); }); Assert.Equal(3, Recorder.Records.Count); Assert.Equal("Before Method", Recorder.Records[0]); Assert.Equal("In Method", Recorder.Records[1]); Assert.Equal("After Method", Recorder.Records[2]); }