/// <summary> /// GRPC Call with Circuit breaker policy /// </summary> /// <returns></returns> private async Task <long> GetCurrentStoreItems() { const string url = "https://localhost:7001"; using GrpcChannel channel = GrpcChannel.ForAddress(url); var client = new InventoryServiceProviderClient(channel); var request = new ServiceRequest { StoreId = "S001" }; long totalItems = 0L; try { await circuitAsyncBreakerPolicy.ExecuteAsync(async() => { ServiceReplay replay = await client.CountTotalItemsAsync(request); totalItems = long.Parse(replay.ItemCount); }); } catch (RpcException rEx) { Debug.WriteLine($"Grpc Exception:{rEx.Message}"); await Task.Delay(1000); } return(totalItems); }
public async Task ShouldReturnTotalItemsCountWhenValidStoreId() { using GrpcChannel channel = GrpcChannel.ForAddress("https://localhost:7001"); var client = new InventoryServiceProviderClient(channel); var request = new ServiceRequest { StoreId = "S001" }; ServiceReplay replay = await client.CountTotalItemsAsync(request); replay.ItemCount.Should().Equals("999"); }