public void Throws_ReturnsException_IfTargetThrowsASubclassOfExpectedExceptionType() { var exception = NrAssert.Throws <Exception>(() => { throw new NullReferenceException(); }); Assert.NotNull(exception); Assert.AreEqual(typeof(NullReferenceException), exception.GetType()); }
public void Throws_ReturnsException_IfTargetThrowsExpectedExceptionType() { var exception = NrAssert.Throws <NullReferenceException>(() => { throw new NullReferenceException("Test message"); }); Assert.NotNull(exception); Assert.AreEqual("Test message", exception.Message); }
public void when_serializing_sparse_properties_as_array() { var sparseObject = new SparseProperties(); var exception = NrAssert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(sparseObject)); Assert.NotNull(exception); }
public void ErrorThrownWhenDeserializingClassWithNoMembersWithIndexes() { var sparseFields = new TestClass_Bad_NoMembersWithAttribute(); var exception = NrAssert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(sparseFields)); Assert.NotNull(exception); }
public void Merge_Throws_IfGivenMetricsWithDifferentNames() { var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1))); var metric2 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name1", "scope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(5))); var metric3 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name2", "scope", MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(13), TimeSpan.FromSeconds(11))); NrAssert.Throws <Exception>(() => MetricWireModel.Merge(new[] { metric1, metric2, metric3 })); }
public void Throws_ThrowsTestFailureException_IfTargetDoesNotThrowAnException() { TestFailureException testException = null; try { NrAssert.Throws <NullReferenceException>(() => { }); } catch (TestFailureException ex) { testException = ex; } Assert.NotNull(testException); Assert.AreEqual("Expected exception of type 'System.NullReferenceException' was not thrown.", testException.Message); }
public void Throws_ThrowsTestFailureException_IfTargetThrowsIncompatibleExceptionType() { TestFailureException testFailureException = null; try { NrAssert.Throws <NullReferenceException>(() => { throw new InvalidOperationException(); }); } catch (TestFailureException ex) { testFailureException = ex; } Assert.NotNull(testFailureException); Assert.IsTrue(testFailureException.Message.StartsWith( "Expected exception of type 'System.NullReferenceException', but exception of type 'System.InvalidOperationException' was thrown instead", StringComparison.InvariantCultureIgnoreCase)); }
public void NormalizeUrl_Throws_IfIgnoreRuleMatchesInput(string input, bool shouldThrow) { Mock.Arrange(() => _configuration.UrlRegexRules).Returns(new List <RegexRule> { new RegexRule("/apple", "ThisWillNeverHappen/apple", false, 10, false, false, false), new RegexRule("/apple", null, true, 10, false, false, false) }); Action normalizeAction = () => _metricNameService.NormalizeUrl(input); if (shouldThrow) { NrAssert.Throws <IgnoreTransactionException>(normalizeAction); } else { normalizeAction(); } }
public void Merge_ThrowsIfEmptyListGiven() { NrAssert.Throws <Exception>(() => MetricWireModel.Merge(new MetricWireModel[] { })); }
public void Merge_ThrowsIfAllNullsGiven() { NrAssert.Throws <Exception>(() => MetricWireModel.Merge(new MetricWireModel[] { null, null })); }