public async Task ReportMetricAsync_MetricIdAndValueAreProvided_Succeeds() { // Arrange var pageId = _bogus.Name.FirstName(); var metricId = _bogus.Name.FirstName(); var metricValue = _bogus.Random.Double(); var fakeHttpMessageHandler = new HttpMessageHandlerStub(); var sinkConfiguration = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(pageId: pageId); var atlassianStatuspageClient = new AtlassianStatuspageClient(httpClient: new HttpClient(fakeHttpMessageHandler), sinkConfiguration, NullLogger <AtlassianStatuspageClient> .Instance); // Act await atlassianStatuspageClient.ReportMetricAsync(metricId, metricValue); // Assert var request = fakeHttpMessageHandler.LastRequest; Assert.NotNull(request); Assert.Equal(HttpMethod.Post, request.Method); Assert.Equal($"https://api.statuspage.io/v1/pages/{pageId}/metrics/{metricId}/data", request.RequestUri.ToString()); var requestBody = await request.Content.ReadAsStringAsync(); var requestToken = JToken.Parse(requestBody); Assert.Equal(metricValue.ToString(CultureInfo.InvariantCulture), requestToken["data"]?["value"]?.ToString()); }
public void Constructor_NoHttpClientIsProvided_ThrowsException() { // Arrange var sinkConfiguration = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(); // Act & Assert // ReSharper disable once ExpressionIsAlwaysNull Assert.Throws <ArgumentNullException>(() => new AtlassianStatuspageClient(httpClient: null, sinkConfiguration, NullLogger <AtlassianStatuspageClient> .Instance)); }
public void Constructor_NoLoggerIsProvided_ThrowsException() { // Arrange var httpClientMock = new Mock <HttpClient>(); var sinkConfiguration = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(); // Act & Assert // ReSharper disable once ExpressionIsAlwaysNull Assert.Throws <ArgumentNullException>(() => new AtlassianStatuspageClient(httpClientMock.Object, sinkConfiguration, logger: null)); }
public async Task ReportMetricAsync_NoMetricIdIsProvided_ThrowsException() { // Arrange var metricValue = _bogus.Random.Double(); var httpClientMock = new Mock <HttpClient>(); var sinkConfiguration = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(); var atlassianStatuspageClient = new AtlassianStatuspageClient(httpClient: httpClientMock.Object, sinkConfiguration, NullLogger <AtlassianStatuspageClient> .Instance); // Act & Assert await Assert.ThrowsAsync <ArgumentException>(() => atlassianStatuspageClient.ReportMetricAsync(id: null, metricValue)); }
public async Task ReportMetricAsync_InputDoesNotContainMeasuredMetric_ThrowsException() { // Arrange var metricName = BogusGenerator.Name.FirstName(); var metricDescription = BogusGenerator.Lorem.Sentence(); var systemMetricConfigOptions = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(); var atlassianStatuspageClientMock = new Mock <IAtlassianStatuspageClient>(); var metricSink = new AtlassianStatuspageMetricSink(atlassianStatuspageClientMock.Object, systemMetricConfigOptions, NullLogger <AtlassianStatuspageMetricSink> .Instance); // Act & Assert // ReSharper disable once ExpressionIsAlwaysNull await Assert.ThrowsAsync <ArgumentNullException>(() => metricSink.ReportMetricAsync(metricName, metricDescription, null)); }
public async Task ReportMetricAsync_InputDoesNotContainMetricName_ThrowsException(string metricName) { // Arrange var metricDescription = BogusGenerator.Lorem.Sentence(); var metricValue = BogusGenerator.Random.Double(); var scrapeResult = ScrapeResultGenerator.Generate(metricValue); var systemMetricConfigOptions = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(); var atlassianStatuspageClientMock = new Mock <IAtlassianStatuspageClient>(); var metricSink = new AtlassianStatuspageMetricSink(atlassianStatuspageClientMock.Object, systemMetricConfigOptions, NullLogger <AtlassianStatuspageMetricSink> .Instance); // Act & Assert // ReSharper disable once ExpressionIsAlwaysNull await Assert.ThrowsAsync <ArgumentException>(() => metricSink.ReportMetricAsync(metricName, metricDescription, scrapeResult)); }
public async Task ReportMetricAsync_InputDoesNotContainMetricDescription_Succeeds(string metricDescription) { // Arrange var metricName = BogusGenerator.Name.FirstName(); var metricValue = BogusGenerator.Random.Double(); var measuredMetric = MeasuredMetric.CreateWithoutDimension(metricValue); var scrapeResult = ScrapeResultGenerator.GenerateFromMetric(measuredMetric); var systemMetricConfigOptions = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(); var atlassianStatuspageClientMock = new Mock <IAtlassianStatuspageClient>(); var metricSink = new AtlassianStatuspageMetricSink(atlassianStatuspageClientMock.Object, systemMetricConfigOptions, NullLogger <AtlassianStatuspageMetricSink> .Instance); // Act & Assert // ReSharper disable once ExpressionIsAlwaysNull await metricSink.ReportMetricAsync(metricName, metricDescription, scrapeResult); }
public async Task ReportMetricAsync_GetsValidInputWithMetricValueAndPromitorToSystemMetricMapping_SuccessfullyWritesMetric() { // Arrange var promitorMetricName = BogusGenerator.Name.FirstName(); var systemMetricId = BogusGenerator.Name.FirstName(); var metricDescription = BogusGenerator.Lorem.Sentence(); var metricValue = BogusGenerator.Random.Double(); var measuredMetric = MeasuredMetric.CreateWithoutDimension(metricValue); var scrapeResult = ScrapeResultGenerator.GenerateFromMetric(measuredMetric); var systemMetricConfigOptions = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(systemMetricId: systemMetricId, promitorMetricName: promitorMetricName); var atlassianStatuspageClientMock = new Mock <IAtlassianStatuspageClient>(); var metricSink = new AtlassianStatuspageMetricSink(atlassianStatuspageClientMock.Object, systemMetricConfigOptions, NullLogger <AtlassianStatuspageMetricSink> .Instance); // Act await metricSink.ReportMetricAsync(promitorMetricName, metricDescription, scrapeResult); // Assert atlassianStatuspageClientMock.Verify(mock => mock.ReportMetricAsync(systemMetricId, metricValue), Times.Once()); }
public async Task ReportMetricAsync_GetsValidInputWithPromitorMetricThatIsNotMappedToSystemMetricId_DoesNotWriteMetric() { // Arrange const double expectedDefaultValue = 0; var promitorMetricName = BogusGenerator.Name.FirstName(); var systemMetricId = BogusGenerator.Name.FirstName(); var metricDescription = BogusGenerator.Lorem.Sentence(); double? metricValue = null; // ReSharper disable once ExpressionIsAlwaysNull var measuredMetric = MeasuredMetric.CreateWithoutDimension(metricValue); var scrapeResult = ScrapeResultGenerator.GenerateFromMetric(measuredMetric); var systemMetricConfigOptions = BogusAtlassianStatuspageMetricSinkConfigurationGenerator.GetSinkConfiguration(promitorMetricName: promitorMetricName); var atlassianStatuspageClientMock = new Mock <IAtlassianStatuspageClient>(); var metricSink = new AtlassianStatuspageMetricSink(atlassianStatuspageClientMock.Object, systemMetricConfigOptions, NullLogger <AtlassianStatuspageMetricSink> .Instance); // Act await metricSink.ReportMetricAsync(promitorMetricName, metricDescription, scrapeResult); // Assert atlassianStatuspageClientMock.Verify(mock => mock.ReportMetricAsync(systemMetricId, expectedDefaultValue), Times.Never); }