public void TestInterceptorRetrievesReturnValue() { _methodInfoMock .Setup(mock => mock.GetCustomAttributes(It.IsAny <Type>(), It.IsAny <bool>())) .Returns(new object[] { new LegacyDllMethodAttribute() }); WrapperClientInterceptor interceptor = new WrapperClientInterceptor(MockInterfaceType, _wrapperClientMock.Object, _libraryNameProviderMock.Object); interceptor.Intercept(_invocationMock.Object); _invocationMock.VerifySet(mock => mock.ReturnValue = ReturnedCallResult, Times.Once); }
/// <summary> /// Creates a new instance of TFunctions. /// All calls will be proxied over a named pipe to the wrapper executable. /// </summary> /// <param name="targetArchitecture">Architecture of the library to load (X86 / AMD64). Defaults to X86.</param> /// <exception cref="ArgumentException">An ArgumentException is thrown if the supplied generic type parameter is not an interface.</exception> /// <returns>Returns a new instance of TFunctions.</returns> public static TFunctions CreateWrapperClient(TargetArchitecture targetArchitecture = TargetArchitecture.X86) { if (!typeof(TFunctions).IsInterface) { throw new ArgumentException("Generic parameter type <TFunctions> must be an interface.", nameof(TFunctions)); } IProxyGenerator generator = new ProxyGenerator(new PersistentProxyBuilder()); IInterceptor interceptor = new WrapperClientInterceptor(typeof(TFunctions), targetArchitecture); return(generator.CreateInterfaceProxyWithoutTarget <TFunctions>(interceptor)); }
public void TestInterceptorCallsDispose() { Mock <MethodInfo> methodInfoMock = new Mock <MethodInfo>(); methodInfoMock .SetupGet(mock => mock.Name) .Returns(nameof(WrapperClient.Dispose)); _invocationMock .SetupGet(mock => mock.Method) .Returns(methodInfoMock.Object); WrapperClientInterceptor interceptor = new WrapperClientInterceptor(MockInterfaceType, _wrapperClientMock.Object, _libraryNameProviderMock.Object); interceptor.Intercept(_invocationMock.Object); // Should throw ObjectDisposedException now interceptor.Intercept(_invocationMock.Object); }
public void TestThrowsOnMissingInterfaceAttribute() { WrapperClientInterceptor interceptor = new WrapperClientInterceptor(MockInterfaceTypeWithoutAttribute, _wrapperClientMock.Object, _libraryNameProviderMock.Object); interceptor.Intercept(_invocationMock.Object); }