private void DoTestGenericRetval <T>(T expectedRetval) { var handler = CreateClass("MyService", "GenericRetval")(new[] { typeof(T) }); var retvalCodec = codecContainer.GetManualCodecFor <T>(); var expectedData = new byte[retvalCodec.CalculateSize(expectedRetval)]; fixed(byte *pData = expectedData) { var p = pData; retvalCodec.Encode(ref p, expectedRetval); } service.GenericRetval <T>().ReturnsForAnyArgs(expectedRetval); var result = handler.Handle(service, null, 0).Result; var serviceCall = service.ReceivedCalls().Last(); Assert.That(serviceCall.GetMethodInfo(), Is.EqualTo(typeof(IGlobalService).GetMethod("GenericRetval").MakeGenericMethod(new[] { typeof(T) }))); Assert.That(result, Is.EquivalentTo(expectedData)); }