async Task <HttpResponseMessage> IProxyRelayCallService.ProxyRelayCallAsync(string tenantId, string body, HttpMethod httpMethod, IHeaderDictionary httpHeaders, string url) { if (string.IsNullOrWhiteSpace(body)) { throw new ArgumentNullException(nameof(body)); } if (string.IsNullOrWhiteSpace(tenantId)) { throw new ArgumentNullException(nameof(tenantId)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } if (httpMethod is null) { throw new ArgumentNullException(nameof(httpMethod)); } HybridConnectionDto hybridConnectionDto = await _storageApiClient.GetRelayFromIdAsync(tenantId); if (hybridConnectionDto is null) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } var relayCallDto = new RelayCallDto(hybridConnectionDto, body, httpMethod, httpHeaders, url); return(await _relayApiClient.RelayCallAsync(relayCallDto)); }
public async Task ReturnHybridConnectionDtoWhenGetRelayIsCalledAsync() { // Arrange IStorageApiClient storageApiClient = A.Fake <IStorageApiClient>(); ICloudProviderHandlerApiClient cloudProviderHandlerApiClient = A.Fake <ICloudProviderHandlerApiClient>(); IRelayManagementService sut = new RelayManagementService(storageApiClient, cloudProviderHandlerApiClient); A.CallTo(() => storageApiClient.GetRelayFromIdAsync(TestHelper.TenantId.ToString())).Returns(TestHelper.GetHybridConnectionDto()); // Act HybridConnectionDto actual = await sut.GetRelayAsync(TestHelper.TenantId.ToString()); // Assert Assert.Equal(TestHelper.GetHybridConnectionDto().HybridConnectionUrl, actual.HybridConnectionUrl); }
public async Task ReturnStatusCodeNotFoundWhenNoHybridConnectionWasFoundAsync() { // Arrange IStorageApiClient storageApiClient = A.Fake <IStorageApiClient>(); IRelayApiClient relayApiClient = A.Fake <IRelayApiClient>(); IProxyRelayCallService sut = new ProxyRelayCallService(storageApiClient, relayApiClient); A.CallTo(() => relayApiClient.RelayCallAsync(new RelayCallDto(TestHelper.GetHybridConnectionDto(), "body", new HttpMethod(HttpMethods.Post), null, "test/endpoint"))) .Returns(new HttpResponseMessage(HttpStatusCode.OK)); A.CallTo(() => storageApiClient.GetRelayFromIdAsync(TestHelper.TenantId.ToString())).WithAnyArguments().Returns <HybridConnectionDto>(null); // Act HttpResponseMessage actual = await sut.ProxyRelayCallAsync(TestHelper.TenantId.ToString(), "body", new HttpMethod(HttpMethods.Post), null, "test/endpoint"); // Assert Assert.Equal(HttpStatusCode.NotFound, actual.StatusCode); }
async Task <HybridConnectionDto> IRelayManagementService.GetRelayAsync(string tenantId) { return(await _storageApiClient.GetRelayFromIdAsync(tenantId)); }