public void ExecuteCodeWithGuaranteedCleanup_CleanUpIsNull_Throws() { Assert.Throws <ArgumentNullException>(() => { RuntimeHelper.ExecuteCodeWithGuaranteedCleanup( () => { }, null); }); }
public void ExecuteCodeWithGuaranteedCleanup_CleanupThrows_ExceptionIsThrown() { // Arrange var expected = new ArgumentException("expected exception"); // Act var actual = Assert.Throws <ArgumentException>(() => { RuntimeHelper.ExecuteCodeWithGuaranteedCleanup( () => { }, () => throw expected); }); // Assert Assert.AreEqual(expected.Message, actual.Message); }
public void ExecuteCodeWithGuaranteedCleanup_ActionThrows_InvokesCleanup() { // Arrange var isCleanupCalled = false; void CleanUp() => isCleanupCalled = true; void Action() => throw new ArgumentException("expected exception"); // Act var swallowed = Assert.Throws <ArgumentException>(() => { RuntimeHelper.ExecuteCodeWithGuaranteedCleanup( Action, CleanUp); }); // Assert Assert.True(isCleanupCalled); }