Esempio n. 1
0
        public async Task Exception_ThrowWithDetails(string pipeName, string details)
        {
            _serviceMock.Setup(x => x.ThrowException())
            .Throws(new Exception(details));

            IIpcClient <ITestService> client = _factory
                                               .WithIpcHostConfiguration(hostBuilder =>
            {
                hostBuilder.AddNamedPipeEndpoint <ITestService>(options =>
                {
                    options.PipeName = pipeName;
                    options.IncludeFailureDetailsInResponse = true;
                });
            })
                                               .CreateClient((name, services) =>
            {
                services.AddNamedPipeIpcClient <ITestService>(name, (_, options) =>
                {
                    options.PipeName = pipeName;
                });
            });

            IpcFaultException actual = await Assert.ThrowsAsync <IpcFaultException>(async() =>
            {
                await client.InvokeAsync(x => x.ThrowException());
            });

            Assert.NotNull(actual.InnerException);
            Assert.NotNull(actual.InnerException.InnerException);
            Assert.Equal(details, actual.InnerException.InnerException.Message);
        }
        public async Task UnserializableOutput_ThrowFaultException(string pipeName)
        {
            _serviceMock
            .Setup(x => x.UnserializableOutput())
            .Returns(UnserializableObject.Create());

            IIpcClient <ITestService> client = _factory
                                               .WithIpcHostConfiguration(hostBuilder =>
            {
                hostBuilder.AddNamedPipeEndpoint <ITestService>(pipeName);
            })
                                               .CreateClient((name, services) =>
            {
                services.AddNamedPipeIpcClient <ITestService>(name, pipeName);
            });

#if !DISABLE_DYNAMIC_CODE_GENERATION
            IpcFaultException exception = await Assert.ThrowsAnyAsync <IpcFaultException>(async() =>
            {
                await client.InvokeAsync(x => x.UnserializableOutput());
            });

            Assert.Equal(IpcStatus.InternalServerError, exception.Status);
#endif

            IpcFaultException exception2 = await Assert.ThrowsAnyAsync <IpcFaultException>(async() =>
            {
                var request = TestHelpers.CreateIpcRequest("UnserializableOutput");
                await client.InvokeAsync(request);
            });

            Assert.Equal(IpcStatus.InternalServerError, exception2.Status);
        }
        public async Task Exception_ThrowWithoutDetails(string pipeName, string details)
        {
            _serviceMock.Setup(x => x.ThrowException())
            .Throws(new Exception(details));

            IIpcClient <ITestService> client = _factory
                                               .WithIpcHostConfiguration(hostBuilder =>
            {
                hostBuilder.AddNamedPipeEndpoint <ITestService>(options =>
                {
                    options.PipeName = pipeName;
                    options.IncludeFailureDetailsInResponse = false;
                });
            })
                                               .CreateClient((name, services) =>
            {
                services.AddNamedPipeIpcClient <ITestService>(name, (_, options) =>
                {
                    options.PipeName = pipeName;
                });
            });

#if !DISABLE_DYNAMIC_CODE_GENERATION
            IpcFaultException actual = await Assert.ThrowsAsync <IpcFaultException>(async() =>
            {
                await client.InvokeAsync(x => x.ThrowException());
            });

            Assert.Null(actual.InnerException);
#endif

            IpcFaultException actual2 = await Assert.ThrowsAsync <IpcFaultException>(async() =>
            {
                var request = TestHelpers.CreateIpcRequest("ThrowException");
                await client.InvokeAsync(request);
            });

            Assert.Null(actual2.InnerException);
        }
Esempio n. 4
0
        public async Task UnserializableOutput_ThrowFaultException(string pipeName)
        {
            _serviceMock
            .Setup(x => x.UnserializableOutput())
            .Returns(UnserializableObject.Create());

            IIpcClient <ITestService> client = _factory
                                               .WithIpcHostConfiguration(hostBuilder =>
            {
                hostBuilder.AddNamedPipeEndpoint <ITestService>(pipeName);
            })
                                               .CreateClient((name, services) =>
            {
                services.AddNamedPipeIpcClient <ITestService>(name, pipeName);
            });

            IpcFaultException exception = await Assert.ThrowsAnyAsync <IpcFaultException>(async() =>
            {
                await client.InvokeAsync(x => x.UnserializableOutput());
            });

            Assert.Equal(IpcStatus.InternalServerError, exception.Status);
        }