public async void GetServiceListAsync_ServiceFabricFails_ResultIsCached()
        {
            var caller           = Create <CachedServiceFabricCaller>();
            var originalServices = new List <ServiceWrapper> {
                SFTestHelpers.FakeService(new Uri("http://localhost/app1/sv1"), "MyServiceType")
            };

            Mock <IQueryClientWrapper>()
            .SetupSequence(m => m.GetServiceListAsync(
                               new Uri("http://localhost/app1"),
                               It.IsAny <TimeSpan>(),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(originalServices.ToList())
            .ThrowsAsync(new Exception("the cake is a lie"))
            .ThrowsAsync(new Exception("the cake is still a lie"));

            await CallThreeTimesAndAssertAsync(() => caller.GetServiceListAsync(new Uri("http://localhost/app1"), CancellationToken.None));
        }
        private ServiceWrapper CreateService(string appName, string serviceName, int numPartitions, int numReplicasPerPartition, out List <ReplicaWrapper> replicas, ServiceKind serviceKind = ServiceKind.Stateless)
        {
            var svcName = new Uri($"fabric:/{appName}/{serviceName}");
            var service = SFTestHelpers.FakeService(svcName, $"{appName}_{serviceName}_Type", serviceKind: serviceKind);

            replicas = new List <ReplicaWrapper>();

            var partitions = new List <Guid>();

            for (var i = 0; i < numPartitions; i++)
            {
                var partitionReplicas = Enumerable.Range(i * numReplicasPerPartition, numReplicasPerPartition).Select(replicaId => SFTestHelpers.FakeReplica(svcName, replicaId)).ToList();
                replicas.AddRange(partitionReplicas);
                var partition = SFTestHelpers.FakePartition();
                partitions.Add(partition);
                Mock_ReplicasResponse(partition, partitionReplicas.ToArray());
            }
            Mock_PartitionsResponse(svcName, partitions.ToArray());
            return(service);
        }