Example #1
0
        public async Task UndeclaredException_ShouldThrowRpcFailure(TestOperationType operationType)
        {
            var serviceRegistrator = new RpcServiceDefinitionsBuilder();

            serviceRegistrator
            .RegisterService <IDeclaredFaultsService>();


            var(host, connection) = this.CreateServerAndConnection(serviceRegistrator);
            var publishedInstanceScope = host.ServicePublisher.PublishInstance <IDeclaredFaultsService>(new FaultServiceImpl());

            var faultService = connection.GetServiceInstance <IFaultServiceClient>(publishedInstanceScope.Value);

            host.Start();
            try
            {
                switch (operationType)
                {
                case TestOperationType.AsyncAsyncVoid:
                    Assert.ThrowsAsync <RpcFailureException>(() => faultService.GenerateUndeclaredAsyncExceptionAsync(false).DefaultTimeout());
                    break;

                case TestOperationType.AsyncAsync:
                    Assert.ThrowsAsync <RpcFailureException>(() => faultService.GenerateUndeclaredAsyncExceptionWithReturnAsync(false).DefaultTimeout());
                    break;

                case TestOperationType.BlockingAsyncVoid:
                    Assert.Throws <RpcFailureException>(() => faultService.GenerateUndeclaredAsyncException(false));
                    break;

                case TestOperationType.BlockingAsync:
                    Assert.Throws <RpcFailureException>(() => faultService.GenerateUndeclaredAsyncExceptionWithReturn(false));
                    break;

                case TestOperationType.AsyncBlockingVoid:
                    Assert.ThrowsAsync <RpcFailureException>(() => faultService.GenerateUndeclaredExceptionAsync().DefaultTimeout());
                    break;

                case TestOperationType.AsyncBlocking:
                    Assert.ThrowsAsync <RpcFailureException>(() => faultService.GenerateUndeclaredExceptionWithReturnAsync().DefaultTimeout());
                    break;

                case TestOperationType.BlockingBlockingVoid:
                    Assert.Throws <RpcFailureException>(() => faultService.GenerateUndeclaredException());
                    break;

                case TestOperationType.BlockingBlocking:
                    Assert.Throws <RpcFailureException>(() => faultService.GenerateUndeclaredExceptionWithReturn());
                    break;
                }

                // TODO: Should this be allowed, or should the connection be closed on undeclared exceptions?
                int res = faultService.Add(5, 6);
                Assert.AreEqual(5 + 6, res);
            }
            finally
            {
                await host.ShutdownAsync();
            }
        }
Example #2
0
        public async Task DeclaredFault_ShouldThrowRpcFaultException(TestOperationType operationType)
        {
            var serviceRegistrator = new RpcServiceDefinitionsBuilder();

            serviceRegistrator
            .RegisterService <IDeclaredFaultsService>();

            var(host, connection) = this.CreateServerAndConnection(serviceRegistrator);
            try
            {
                host.Start();

                using (var publishedInstanceScope = host.ServicePublisher.PublishInstance <IDeclaredFaultsService>(new FaultServiceImpl()))
                {
                    var faultService = connection.GetServiceInstance <IFaultServiceClient>(publishedInstanceScope.Value);

                    // Invoke unknown service instance
                    switch (operationType)
                    {
                    case TestOperationType.BlockingBlocking:
                        Assert.Throws <RpcFaultException <DeclaredFault> >(() => faultService.GenerateDeclaredFault(12));
                        break;

                    case TestOperationType.AsyncBlocking:
                        Assert.ThrowsAsync <RpcFaultException <DeclaredFault> >(() => faultService.GenerateDeclaredFaultAsync(12));
                        break;

                    case TestOperationType.BlockingAsync:
                        Assert.Throws <RpcFaultException <DeclaredFault> >(() => faultService.GenerateAsyncDeclaredFault(true));
                        Assert.Throws <RpcFaultException <DeclaredFault> >(() => faultService.GenerateAsyncDeclaredFault(false));
                        break;

                    case TestOperationType.AsyncAsync:
                        Assert.ThrowsAsync <RpcFaultException <DeclaredFault> >(() => faultService.GenerateAsyncDeclaredFaultAsync(true));
                        Assert.ThrowsAsync <RpcFaultException <DeclaredFault> >(() => faultService.GenerateAsyncDeclaredFaultAsync(false));
                        break;

                    case TestOperationType.BlockingBlockingVoid:
                        Assert.Throws <RpcFaultException <AnotherDeclaredFault> >(() => faultService.GenerateAnotherDeclaredFault(12));
                        break;

                    case TestOperationType.AsyncBlockingVoid:
                        Assert.ThrowsAsync <RpcFaultException <AnotherDeclaredFault> >(() => faultService.GenerateAnotherDeclaredFaultAsync(12));
                        break;

                    case TestOperationType.BlockingAsyncVoid:
                        Assert.Throws <RpcFaultException <DeclaredFault> >(() => faultService.GenerateAsyncAnotherDeclaredFault(true));
                        Assert.Throws <RpcFaultException <AnotherDeclaredFault> >(() => faultService.GenerateAsyncAnotherDeclaredFault(false));
                        break;

                    case TestOperationType.AsyncAsyncVoid:
                        Assert.ThrowsAsync <RpcFaultException <DeclaredFault> >(() => faultService.GenerateAsyncAnotherDeclaredFaultAsync(true));
                        Assert.ThrowsAsync <RpcFaultException <AnotherDeclaredFault> >(() => faultService.GenerateAsyncAnotherDeclaredFaultAsync(false));
                        break;

                    default:
                        throw new NotImplementedException(operationType.ToString());
                    }

                    // Make sure that the connection is still usable after exception
                    Assert.AreEqual(12 + 13, faultService.Add(12, 13));
                }
            }
            finally
            {
                await host.ShutdownAsync();
            }
        }
Example #3
0
        public async Task UnavailableService_ShouldThrowRpcServiceUnavailableException(TestOperationType operationType)
        {
            var serviceRegistrator = new RpcServiceDefinitionsBuilder();

            serviceRegistrator
            .RegisterService <IBlockingService>()
            .RegisterService <ISimpleService>();

            var(host, connection) = this.CreateServerAndConnection(serviceRegistrator);
            using (var publishedInstanceScope = host.ServicePublisher.PublishInstance <IBlockingService>(new TestBlockingServiceImpl()))
            {
                var objectId = RpcObjectId.NewId();
                var blockingClientService = connection.GetServiceInstance <IBlockingServiceClient>(objectId);
                var simpleService         = connection.GetServiceInstance <ISimpleService>(objectId);
                host.Start();

                try
                {
                    // Invoke unknown service instance
                    switch (operationType)
                    {
                    case TestOperationType.BlockingBlocking:
                        Assert.Throws <RpcServiceUnavailableException>(() => blockingClientService.Add(12, 13));
                        break;

                    case TestOperationType.AsyncBlocking:
                        // Async/blocking (client/host)
                        Assert.ThrowsAsync <RpcServiceUnavailableException>(() => blockingClientService.AddAsync(12, 13));
                        break;

                    case TestOperationType.BlockingBlockingVoid:
                        Assert.Throws <RpcServiceUnavailableException>(() => blockingClientService.Value = 23);
                        break;

                    case TestOperationType.AsyncBlockingVoid:
                        // Async/blocking void (client/host)
                        Assert.ThrowsAsync <RpcServiceUnavailableException>(() => blockingClientService.SetValueAsync(13));
                        break;

                    case TestOperationType.AsyncAsync:
                        // Async/async (client/host)
                        Assert.ThrowsAsync <RpcServiceUnavailableException>(() => simpleService.AddAsync(12, 13));
                        break;

                    case TestOperationType.AsyncAsyncVoid:
                        // Async/async void (client/host)
                        Assert.ThrowsAsync <RpcServiceUnavailableException>(() => simpleService.SetValueAsync(12));
                        break;
                    }

                    var exisingService = connection.GetServiceInstance <IBlockingServiceClient>(publishedInstanceScope.Value);
                    // Make sure that the connection is still usable after exception
                    Assert.AreEqual(12 + 13, exisingService.Add(12, 13));
                }
                finally
                {
                    await host.ShutdownAsync();
                }
            }
        }