private static async Task LockShouldBeReleasedWhenCallThrowsException <T>( ILockAssertions lockAssertions, T wrappingObject, T wrappedObjectMock, Func <T, Task> callToCheck) where T : class { try { wrappedObjectMock.When(callToCheck).Throw(_ => { lockAssertions.AssertLocked(); return(new LockNotReleasedWhenExceptionOccurs()); }); await callToCheck(wrappingObject); throw new Exception( // todo more specific exception "The specified method was probably not called by the proxy with exactly the same arguments it received"); } catch { lockAssertions.AssertUnlocked(); } finally { wrappedObjectMock.ClearReceivedCalls(); } }
private static void LockShouldBeReleasedAfterACall <T, TReturn>( T wrappingObject, T wrappedObjectMock, Func <T, TReturn> callToCheck, ILockAssertions lockAssertions) where T : class { try { Func <TReturn> instance = Root.Any.Instance <TReturn>; var cannedResult = instance(); callToCheck(wrappedObjectMock).Returns(ci => { lockAssertions.AssertLocked(); return(cannedResult); }); lockAssertions.AssertUnlocked(); var actualResult = callToCheck(wrappingObject); lockAssertions.AssertUnlocked(); actualResult.Should().Be( cannedResult, "{0}", "The specified method was probably not called by the proxy with exactly the same arguments it received or it did not return the value obtained from wrapped call"); } finally { wrappedObjectMock.ClearReceivedCalls(); } }
private static void LockShouldBeReleasedAfterACall <T>( T wrappingObject, T wrappedObjectMock, Action <T> callToCheck, ILockAssertions lockAssertions) where T : class { try { wrappedObjectMock.When(callToCheck).Do(_ => lockAssertions.AssertLocked()); lockAssertions.AssertUnlocked(); callToCheck(wrappingObject); lockAssertions.AssertUnlocked(); callToCheck(wrappedObjectMock.Received(1)); } finally { wrappedObjectMock.ClearReceivedCalls(); } }
private static async Task LockShouldBeReleasedAfterACall <T>( T wrappingObject, T wrappedObjectMock, Func <T, Task> callToCheck, ILockAssertions lockAssertions) where T : class { try { callToCheck(wrappedObjectMock).Returns(async ci => { lockAssertions.AssertLocked(); }); lockAssertions.AssertUnlocked(); await callToCheck(wrappingObject); lockAssertions.AssertUnlocked(); } finally { wrappedObjectMock.ClearReceivedCalls(); } }