public void ReturnsValueType() { RecordingHandler handler = new RecordingHandler(); MethodBase method = typeof(SpyReturn).GetMethod("ReturnsValueType"); Dictionary <MethodBase, List <IInterceptionHandler> > dictionary = new Dictionary <MethodBase, List <IInterceptionHandler> >(); List <IInterceptionHandler> handlers = new List <IInterceptionHandler>(); handlers.Add(handler); dictionary.Add(method, handlers); SpyReturn result = WrapAndCreateType <SpyReturn>(dictionary, 42); int retValue = result.ReturnsValueType(); Assert.Equal(SpyReturn.ValueReturn, retValue); }
public void Exception() { RecordingHandler handler = new RecordingHandler(); MethodBase method = typeof(SpyReturn).GetMethod("Exception"); Dictionary <MethodBase, List <IInterceptionHandler> > dictionary = new Dictionary <MethodBase, List <IInterceptionHandler> >(); List <IInterceptionHandler> handlers = new List <IInterceptionHandler>(); handlers.Add(handler); dictionary.Add(method, handlers); SpyReturn result = WrapAndCreateType <SpyReturn>(dictionary, 42); Assert.Throws <ArgumentException>(delegate { result.Exception(); }); }
public void NoReturnValue() { Recorder.Records.Clear(); RecordingHandler handler = new RecordingHandler(); MethodBase method = typeof(SpyReturn).GetMethod("NoReturnValue"); Dictionary <MethodBase, List <IInterceptionHandler> > dictionary = new Dictionary <MethodBase, List <IInterceptionHandler> >(); List <IInterceptionHandler> handlers = new List <IInterceptionHandler>(); handlers.Add(handler); dictionary.Add(method, handlers); SpyReturn result = WrapAndCreateType <SpyReturn>(dictionary, 42); result.NoReturnValue(); Assert.Equal(42, result.ConstructorValue); 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]); }