public ConsulServiceSubscriberFixture() { Client = Substitute.For <IConsulClient>(); HealthEndpoint = Substitute.For <IHealthEndpoint>(); ServiceSubscriber = Substitute.For <IServiceSubscriber>(); }
public static async Task <ServiceEntry[]> AvaliableServices(string consulAgentUrl, string name, string tags = "") { bool flag = false; int j; string str; Func <string, string> func = null; List <ServiceEntry> serviceEntries = new List <ServiceEntry>(); ConsulClient consulClient = new ConsulClient((ConsulClientConfiguration config) => config.Address = new Uri(consulAgentUrl)); try { string str1 = tags; char[] chrArray = new char[] { ',' }; string[] strArrays = str1.Split(chrArray); for (int i = 0; i < (int)strArrays.Length; i++) { string str2 = strArrays[i]; IHealthEndpoint health = consulClient.Health; string str3 = name; if (!string.IsNullOrEmpty(str2)) { str = str2; } else { str = null; } CancellationToken cancellationToken = new CancellationToken(); ConfiguredTaskAwaitable <QueryResult <ServiceEntry[]> > configuredTaskAwaitable = health.Service(str3, str, true, cancellationToken).ConfigureAwait(false); ServiceEntry[] response = await configuredTaskAwaitable.Response; for (j = 0; j < (int)response.Length; j++) { ServiceEntry serviceEntry = response[j]; List <ServiceEntry> serviceEntries1 = serviceEntries; if (!serviceEntries1.Any <ServiceEntry>((ServiceEntry service) => (service.Service.Address != serviceEntry.Service.Address ? false : service.Service.Port == serviceEntry.Service.Port))) { serviceEntries.Add(serviceEntry); } } !flag; } !flag; string str4 = tags; chrArray = new char[] { ',' }; string[] strArrays1 = str4.Split(chrArray); for (j = 0; j < (int)strArrays1.Length; j++) { string str5 = strArrays1[j]; if (!string.IsNullOrEmpty(str5)) { List <ServiceEntry> serviceEntries2 = serviceEntries; List <ServiceEntry> list = serviceEntries2.Where <ServiceEntry>((ServiceEntry service) => { string[] strArrays2 = service.Service.Tags; if (func == null) { func = (string t) => t.Trim().ToLower(); } return(!strArrays2.Select <string, string>(func).Contains <string>(str5.ToLower())); }).ToList <ServiceEntry>(); foreach (ServiceEntry serviceEntry1 in list) { serviceEntries.Remove(serviceEntry1); } } } !flag; } finally { if (consulClient != null) { ((IDisposable)consulClient).Dispose(); } } return(serviceEntries.ToArray()); }