private void AssertHealtItem(MockServicePartition partition, string name, HealthReport report) { HealthReportEntry entry = report.Entries[name]; SfHealthInformation?info = partition.HealthInformation.SingleOrDefault(h => string.Equals(h.Property, name, StringComparison.OrdinalIgnoreCase)); Assert.IsNotNull(info, name); Assert.AreEqual(GetMachingState(entry.Status), info.HealthState, nameof(HealthReportEntry.Status)); if (entry.Status == HealthStatus.Healthy) { Assert.AreEqual(info.Description, entry.Description, nameof(HealthReportEntry.Description)); } else { StringAssert.Contains(info.Description, entry.Description, nameof(HealthReportEntry.Description)); StringAssert.Contains(info.Description, entry.Exception.ToString(), nameof(HealthReportEntry.Exception)); StringAssert.Contains(info.Description, entry.Duration.ToString(), nameof(HealthReportEntry.Duration)); int index = 0; foreach (string tag in entry.Tags) { StringAssert.Contains(info.Description, tag, nameof(HealthReportEntry.Tags) + index); index++; } } }
public void PublishAsync_ReportsToServiceFabric() { string healthyCheckName = "HealthyCheck"; string degradedCheckName = "DegradedCheck"; string unhealthyCheckName = "UnhealthyCheck"; MockServicePartition partition = new MockServicePartition(); HealthReport report = new HealthReport(new Dictionary <string, HealthReportEntry>() { { healthyCheckName, CreateEntry(HealthStatus.Healthy, "testDescription1") }, { degradedCheckName, CreateEntry(HealthStatus.Degraded, "testDescription2", new ArithmeticException()) }, { unhealthyCheckName, CreateEntry(HealthStatus.Unhealthy, "testDescription3", new ArgumentOutOfRangeException()) } }, default); Accessor <IServicePartition> accessor = new Accessor <IServicePartition>(); IHealthCheckPublisher publisher = new ServiceFabricHealthCheckPublisher(accessor, new NullLogger <ServiceFabricHealthCheckPublisher>()); publisher.PublishAsync(report, default); // publish not failing if IServicePartition not available (accessor as IAccessorSetter <IServicePartition>).SetValue(partition); publisher.PublishAsync(report, default); AssertHealtItem(partition, healthyCheckName, report); AssertHealtItem(partition, degradedCheckName, report); AssertHealtItem(partition, degradedCheckName, report); }