public async Task BindAsyncError()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };
            var response = new ServiceBindingAsyncOperation
            {
                Operation = "my operation"
            };
            var operation = new LastOperationResource
            {
                State       = LastOperationResourceState.Failed,
                Description = "custom message"
            };

            Mock.Setup(x => x.BindAsync(new("123", "456"), request))
            .ReturnsAsync(response);
            Mock.Setup(x => x.GetLastOperationAsync(new("123", "456"), "abc", "xyz", "my operation"))
            .ReturnsAsync(operation);
            await Client.ServiceInstancesPolling["123"].ServiceBindings["456"]
            .Awaiting(x => x.BindAsync(request))
            .Should().ThrowAsync <BrokerException>().WithMessage("custom message");
        }
        public async Task <ServiceBinding> BindAsync(ServiceBindingRequest request)
        {
            var response = await HandleAsync(() => HttpClient.PutAsync(Uri, request, Serializer));

            var result = await FromContentAsync <ServiceBinding>(response);

            result.Unchanged = (response.StatusCode == HttpStatusCode.OK);
            return(result);
        }
        public void BindConflict()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };

            SetupMock(x => x.BindAsync(new ServiceBindingContext("123", "456"), request), new ConflictException());
            Client.ServiceInstancesBlocking["123"].ServiceBindings["456"].Awaiting(x => x.BindAsync(request)).Should().Throw <ConflictException>();
        }
        public async Task BindConflict()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };

            Mock.Setup(x => x.BindAsync(new("123", "456"), request))
            .Throws <ConflictException>();
            await Client.ServiceInstancesPolling["123"].ServiceBindings["456"]
            .Awaiting(x => x.BindAsync(request))
            .Should().ThrowAsync <ConflictException>();
        }
        public async Task BindUnchanged()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };
            var response = new ServiceBinding();

            SetupMock(x => x.BindAsync(new ServiceBindingContext("123", "456"), request), response);
            var result = await Client.ServiceInstancesBlocking["123"].ServiceBindings["456"].BindAsync(request);

            result.Should().BeEquivalentTo(response);
        }
        public async Task BindCompleted()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };
            var response = new ServiceBindingAsyncOperation().Complete(new ServiceBinding());

            SetupMock(x => x.BindAsync(new ServiceBindingContext("123", "456"), request), response);
            var result = await Client.ServiceInstancesDeferred["123"].ServiceBindings["456"].BindAsync(request);

            result.Should().BeEquivalentTo(response);
        }
        public Task <IActionResult> Bind(
            [FromRoute(Name = "instance_id"), Required] string instanceId,
            [FromRoute(Name = "binding_id"), Required] string bindingId,
            [FromBody, Required] ServiceBindingRequest request,
            [FromQuery(Name = "accepts_incomplete")] bool acceptsIncomplete = false)
        {
            var context = Context(instanceId, bindingId);

            return(Do(acceptsIncomplete,
                      blocking: async x => SyncResult(context, await x.BindAsync(context, request)),
                      deferred: async x =>
            {
                var result = await x.BindAsync(context, request);
                return result.Completed
                        ? SyncResult(context, result.Result)
                        : AsyncResult(context, result, request);
            }));
        }
        public async Task BindUnchanged()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };
            var response = new ServiceBindingAsyncOperation().Complete(new ServiceBinding
            {
                Unchanged = true
            });

            Mock.Setup(x => x.BindAsync(new("123", "456"), request))
            .ReturnsAsync(response);
            var result = await Client.ServiceInstancesDeferred["123"].ServiceBindings["456"].BindAsync(request);

            result.Should().BeEquivalentTo(response);
        }
        public async Task BindCompleted()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId = "abc",
                PlanId    = "xyz"
            };
            var syntheticResponse = new ServiceBinding
            {
                RouteServiceUrl = new Uri("http://example.com")
            };
            var response = new ServiceBindingAsyncOperation().Complete(syntheticResponse);

            SetupMock(x => x.BindAsync(new ServiceBindingContext("123", "456"), request), response);
            var result = await Client.ServiceInstancesPolling["123"].ServiceBindings["456"].BindAsync(request);

            result.Should().BeEquivalentTo(syntheticResponse);
        }
        public async Task BindDeferred()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId    = "abc",
                PlanId       = "xyz",
                BindResource = new ServiceBindingResourceObject
                {
                    AppGuid = "123-456"
                }
            };
            var response = new ServiceBindingAsyncOperation
            {
                Operation = "my operation"
            };

            SetupMock(x => x.BindAsync(new ServiceBindingContext("123", "456"), request), response);
            var result = await Client.ServiceInstancesDeferred["123"].ServiceBindings["456"].BindAsync(request);

            result.Should().BeEquivalentTo(response);
        }
Esempio n. 11
0
        public async Task <ServiceBinding> BindAsync(ServiceBindingRequest request)
        {
            var response = await _inner.BindAsync(request);

            if (string.IsNullOrEmpty(response.Operation))
            {
                return(response.Result);
            }

            await LastOperationWaitAsync(request.ServiceId, request.PlanId, response.Operation);

            var resource = await FetchAsync();

            var result = new ServiceBinding
            {
                Credentials     = resource.Credentials,
                RouteServiceUrl = resource.RouteServiceUrl,
                SyslogDrainUrl  = resource.SyslogDrainUrl
            };

            result.VolumeMounts.AddRange(resource.VolumeMounts);
            return(result);
        }
        public async Task BindDeferred()
        {
            var request = new ServiceBindingRequest
            {
                ServiceId    = "abc",
                PlanId       = "xyz",
                BindResource = new ServiceBindingResourceObject
                {
                    AppGuid = "123-456"
                }
            };
            var response = new ServiceBindingAsyncOperation
            {
                Operation = "my operation"
            };
            var operation = new LastOperationResource
            {
                State       = LastOperationResourceState.Succeeded,
                Description = "done"
            };
            var resource = new ServiceBindingResource
            {
                RouteServiceUrl = new Uri("http://example.com")
            };
            var syntheticResponse = new ServiceBinding
            {
                RouteServiceUrl = new Uri("http://example.com")
            };

            SetupMock(x => x.BindAsync(new ServiceBindingContext("123", "456"), request), response);
            SetupMock(x => x.GetLastOperationAsync(new ServiceBindingContext("123", "456"), "abc", "xyz", "my operation"), operation);
            SetupMock(x => x.FetchAsync("123", "456"), resource);
            var result = await Client.ServiceInstancesPolling["123"].ServiceBindings["456"].BindAsync(request);

            result.Should().BeEquivalentTo(syntheticResponse);
        }
        public async Task <ServiceBindingAsyncOperation> BindAsync(ServiceBindingRequest request)
        {
            var response = await HandleAsync(() => HttpClient.PutAsync(Uri, request, Serializer));

            return(await ParseDeferredResponseAsync <ServiceBinding, ServiceBindingAsyncOperation>(response));
        }