public async Task ThrowInvalidOperationExceptionWhenCloudProviderDidNotReturnHybridConnectionAsync() { // Arrange IStorageApiClient storageApiClient = A.Fake <IStorageApiClient>(); ICloudProviderHandlerApiClient cloudProviderHandlerApiClient = A.Fake <ICloudProviderHandlerApiClient>(); IRelayManagementService sut = new RelayManagementService(storageApiClient, cloudProviderHandlerApiClient); A.CallTo(() => cloudProviderHandlerApiClient.CreateRelayHybridConnection(TestHelper.TenantId.ToString())).WithAnyArguments().Returns <HybridConnectionDto>(null); // Act & Assert await Assert.ThrowsAsync <InvalidOperationException>(() => sut.StoreRelayAsync(TestHelper.GetCreateRelayStorageDto())); }
async Task <HybridConnectionDto> IRelayManagementService.StoreRelayAsync(CreateRelayStorageDto createRelayStorageDto) { HybridConnectionDto hybridConnectionDto = await _cloudProviderHandlerApiClient.CreateRelayHybridConnection(createRelayStorageDto.TenantId); if (hybridConnectionDto is null) { throw new InvalidOperationException(nameof(hybridConnectionDto)); } return(await _storageApiClient.StoreRelayAsync(createRelayStorageDto.TenantId, hybridConnectionDto)); }
public async Task ReturnHybridConnectionDtoWhenStoreRelayIsCalledAsync() { // Arrange IStorageApiClient storageApiClient = A.Fake <IStorageApiClient>(); ICloudProviderHandlerApiClient cloudProviderHandlerApiClient = A.Fake <ICloudProviderHandlerApiClient>(); IRelayManagementService sut = new RelayManagementService(storageApiClient, cloudProviderHandlerApiClient); A.CallTo(() => cloudProviderHandlerApiClient.CreateRelayHybridConnection(TestHelper.TenantId.ToString())).WithAnyArguments().Returns(TestHelper.GetHybridConnectionDto()); A.CallTo(() => storageApiClient.StoreRelayAsync(TestHelper.TenantId.ToString(), TestHelper.GetHybridConnectionDto())).WithAnyArguments().Returns(TestHelper.GetHybridConnectionDto()); // Act HybridConnectionDto actual = await sut.StoreRelayAsync(TestHelper.GetCreateRelayStorageDto()); // Assert Assert.Equal(TestHelper.GetHybridConnectionDto().HybridConnectionUrl, actual.HybridConnectionUrl); }