public void Should_throw_with_custom_placeholders_in_pattern_without_public_instance_property() { const string metricPattern = "Component/Memory/{NotInstanceProperty}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder(); Assert.Throws <Exception>(() => QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric")); }
public void Assert_custom_placeholders_with_null_values_are_replaced_with_null_text() { const string metricPattern = "Component/Memory/{ThePlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder {ThePlaceholder = null, TheMetric = 42,}; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/null/TheMetric"), "Substitution failed"); }
public void Assert_custom_placeholders_in_pattern_are_replaced() { const string metricPattern = "Component/Memory/{ThePlaceholder}/Machine/{AnotherPlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder {ThePlaceholder = "Tada", AnotherPlaceholder = "Flexible", TheMetric = 42,}; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/Tada/Machine/Flexible/TheMetric"), "Substitution failed"); }
public void Assert_custom_placeholders_have_whitespace_trimmed() { const string metricPattern = "Component/Memory/{ThePlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder {ThePlaceholder = " space then tab\t", TheMetric = 42,}; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/space_then_tab/TheMetric"), "Substitution failed"); }
public void Assert_custom_placeholders_have_non_alphanumerics_replaced_with_underbar() { const string metricPattern = "Component/Memory/{ThePlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder {ThePlaceholder = "I ->have.bad_45+stuff!", TheMetric = 42,}; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/I___have_bad_45_stuff_/TheMetric"), "Substitution failed"); }
public void Should_throw_with_custom_placeholders_in_pattern_without_matching_property() { const string metricPattern = "Component/Memory/{ThisMatchesNothing}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder { ThePlaceholder = "BooHiss" }; Assert.Throws <Exception>(() => QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric")); }
public void Assert_custom_placeholders_with_null_values_are_replaced_with_null_text() { const string metricPattern = "Component/Memory/{ThePlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder { ThePlaceholder = null, TheMetric = 42, }; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/null/TheMetric"), "Substitution failed"); }
public void Assert_custom_placeholders_in_pattern_are_replaced() { const string metricPattern = "Component/Memory/{ThePlaceholder}/Machine/{AnotherPlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder { ThePlaceholder = "Tada", AnotherPlaceholder = "Flexible", TheMetric = 42, }; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/Tada/Machine/Flexible/TheMetric"), "Substitution failed"); }
public void Assert_custom_placeholders_have_whitespace_trimmed() { const string metricPattern = "Component/Memory/{ThePlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder { ThePlaceholder = " space then tab\t", TheMetric = 42, }; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/space_then_tab/TheMetric"), "Substitution failed"); }
public void Assert_custom_placeholders_have_non_alphanumerics_replaced_with_underbar() { const string metricPattern = "Component/Memory/{ThePlaceholder}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder { ThePlaceholder = "I ->have.bad_45+stuff!", TheMetric = 42, }; var metricName = QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric"); Assert.That(metricName, Is.EqualTo("Component/Memory/I___have_bad_45_stuff_/TheMetric"), "Substitution failed"); }
public void Should_throw_when_placeholder_case_is_not_exact() { const string metricPattern = "Component/Memory/{CASEMATTERSPEOPLE}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder { CaseMattersPeople = "Why are you yelling?", }; var exception = Assert.Throws <Exception>(() => QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric")); Assert.That(exception.Message.ToLower(), Is.StringMatching("case-sensitive"), "Expected a helpful error message"); }
public void Should_throw_with_custom_placeholders_in_pattern_without_public_property() { const string metricPattern = "Component/Memory/{NotPublicProperty}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder {NotPublicProperty = "BooHiss",}; Assert.Throws<Exception>(() => QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric")); }
public void Should_throw_when_placeholder_case_is_not_exact() { const string metricPattern = "Component/Memory/{CASEMATTERSPEOPLE}/{MetricName}"; var queryResult = new FakeQueryWithCustomPlaceHolder {CaseMattersPeople = "Why are you yelling?",}; var exception = Assert.Throws<Exception>(() => QueryContext.FormatMetricKey(metricPattern, queryResult, "TheMetric")); Assert.That(exception.Message.ToLower(), Is.StringMatching("case-sensitive"), "Expected a helpful error message"); }