public async Task ProvisionDeferred() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz" }; var response = new ServiceInstanceAsyncOperation { Operation = "my operation", DashboardUrl = new Uri("http://example.com") }; var operation = new LastOperationResource { State = LastOperationResourceState.Succeeded, Description = "done" }; var syntheticResponse = new ServiceInstanceProvision { DashboardUrl = response.DashboardUrl }; SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123"), request), response); SetupMock(x => x.GetLastOperationAsync(new ServiceInstanceContext("123"), "abc", "xyz", "my operation"), operation); var result = await Client.ServiceInstancesPolling["123"].ProvisionAsync(request); result.Should().BeEquivalentTo(syntheticResponse); }
public async Task ProvisionAsyncError() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz", OrganizationGuid = "org", SpaceGuid = "space" }; var response = new ServiceInstanceAsyncOperation { Operation = "my operation" }; var operation = new LastOperationResource { State = LastOperationResourceState.Failed, Description = "custom message" }; Mock.Setup(x => x.ProvisionAsync(new("123"), request)) .ReturnsAsync(response); Mock.Setup(x => x.GetLastOperationAsync(new("123"), "abc", "xyz", "my operation")) .ReturnsAsync(operation); await Client.ServiceInstancesPolling["123"] .Awaiting(x => x.ProvisionAsync(request)) .Should().ThrowAsync <BrokerException>().WithMessage("custom message"); }
public async Task <ServiceInstanceProvision> ProvisionAsync(ServiceInstanceProvisionRequest request) { var response = await HandleAsync(() => HttpClient.PutAsync(Uri, request, Serializer)); var result = await FromContentAsync <ServiceInstanceProvision>(response); result.Unchanged = (response.StatusCode == HttpStatusCode.OK); return(result); }
public async Task<ServiceInstanceProvision> ProvisionAsync(ServiceInstanceProvisionRequest request) { var response = await _inner.ProvisionAsync(request); if (string.IsNullOrEmpty(response.Operation)) return response.Result; await LastOperationWaitAsync(request.ServiceId, request.PlanId, response.Operation); return new ServiceInstanceProvision {DashboardUrl = response.DashboardUrl}; }
public void ProvisionConflict() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz" }; SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123"), request), new ConflictException("custom message")); Client.ServiceInstancesDeferred["123"].Awaiting(x => x.ProvisionAsync(request)).Should().Throw <ConflictException>().WithMessage("custom message"); }
public async Task OriginatingIdentity() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz" }; var identity = new OriginatingIdentity("myplatform", new JObject { { "id", "test" } }); SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123", identity), request), new ServiceInstanceProvision()); Client.SetOriginatingIdentity(identity); await Client.ServiceInstancesBlocking["123"].ProvisionAsync(request); }
public async Task ProvisionConflict() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz", OrganizationGuid = "org", SpaceGuid = "space" }; Mock.Setup((x => x.ProvisionAsync(new("123"), request))) .Throws(new ConflictException("custom message")); await Client.ServiceInstancesDeferred["123"] .Awaiting(x => x.ProvisionAsync(request)) .Should().ThrowAsync <ConflictException>().WithMessage("custom message"); }
public Task <IActionResult> Provision( [FromRoute(Name = "instance_id"), Required] string instanceId, [FromBody, Required] ServiceInstanceProvisionRequest request, [FromQuery(Name = "accepts_incomplete")] bool acceptsIncomplete = false) { var context = Context(instanceId); return(Do(acceptsIncomplete, blocking: async x => SyncResult(context, await x.ProvisionAsync(context, request)), deferred: async x => { var result = await x.ProvisionAsync(context, request); return result.Completed ? SyncResult(context, result.Result) : AsyncResult(context, result, request); })); }
public async Task ProvisionCompleted() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz" }; var response = new ServiceInstanceAsyncOperation().Complete(new ServiceInstanceProvision { DashboardUrl = new Uri("http://example.com") }); SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123"), request), response); var result = await Client.ServiceInstancesDeferred["123"].ProvisionAsync(request); result.Should().BeEquivalentTo(response); }
public async Task ProvisionUnchanged() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz" }; var response = new ServiceInstanceProvision { DashboardUrl = new Uri("http://example.com"), Unchanged = true }; SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123"), request), response); var result = await Client.ServiceInstancesBlocking["123"].ProvisionAsync(request); result.Should().BeEquivalentTo(response); }
public async Task OriginatingIdentity() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz", OrganizationGuid = "org", SpaceGuid = "space" }; var identity = new OriginatingIdentity("myplatform", new JObject { { "id", "test" } }); ServiceInstanceProvision result = new(); Mock.Setup(x => x.ProvisionAsync(new("123", identity), request)) .ReturnsAsync(result); Client.SetOriginatingIdentity(identity); await Client.ServiceInstancesBlocking["123"].ProvisionAsync(request); }
public async Task ProvisionCompleted() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz", OrganizationGuid = "org", SpaceGuid = "space" }; var response = new ServiceInstanceAsyncOperation().Complete(new ServiceInstanceProvision { DashboardUrl = new Uri("http://example.com") }); Mock.Setup(x => x.ProvisionAsync(new("123"), request)) .ReturnsAsync(response); var result = await Client.ServiceInstancesDeferred["123"].ProvisionAsync(request); result.Should().BeEquivalentTo(response); }
public async Task ProvisionCompleted() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz", OrganizationGuid = "org", SpaceGuid = "space" }; var syntheticResponse = new ServiceInstanceProvision { DashboardUrl = new Uri("http://example.com") }; var response = new ServiceInstanceAsyncOperation().Complete(syntheticResponse); SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123"), request), response); var result = await Client.ServiceInstancesPolling["123"].ProvisionAsync(request); result.Should().BeEquivalentTo(syntheticResponse); }
public void ProvisionAsyncError() { var request = new ServiceInstanceProvisionRequest { ServiceId = "abc", PlanId = "xyz" }; var response = new ServiceInstanceAsyncOperation { Operation = "my operation" }; var operation = new LastOperationResource { State = LastOperationResourceState.Failed, Description = "custom message" }; SetupMock(x => x.ProvisionAsync(new ServiceInstanceContext("123"), request), response); SetupMock(x => x.GetLastOperationAsync(new ServiceInstanceContext("123"), "abc", "xyz", "my operation"), operation); Client.ServiceInstancesPolling["123"].Awaiting(x => x.ProvisionAsync(request)).Should().Throw <BrokerException>().WithMessage("custom message"); }
public async Task <ServiceInstanceAsyncOperation> ProvisionAsync(ServiceInstanceProvisionRequest request) { var response = await HandleAsync(() => HttpClient.PutAsync(Uri, request, Serializer)); return(await ParseDeferredResponseAsync <ServiceInstanceProvision, ServiceInstanceAsyncOperation>(response)); }