public void ShouldReleaseLockOnExceptionFromRetrieve() { // Arrange MockSemaphoreSlimBookEnd mockSemaphoreSlimBookEnd = new MockSemaphoreSlimBookEnd.Builder().WaitSync().Release().Build(); MockCacheSync <string> mockCache = new MockCacheSync <string> .Builder().Retrieve(() => throw new Exception()).Build(); BlockingClassCacheSync <string> subject = new BlockingClassCacheSync <string>(mockSemaphoreSlimBookEnd, mockCache); // Act Action action = () => subject.Retrieve(() => null); // Assert action.Should().Throw <Exception>(); mockSemaphoreSlimBookEnd.AssertWaitSyncInvoked(); mockSemaphoreSlimBookEnd.AssertReleaseInvoked(); }
public void ShouldClearAndLock() { // Arrange MockSemaphoreSlimBookEnd mockSemaphoreSlimBookEnd = new MockSemaphoreSlimBookEnd.Builder().WaitSync().Release().Build(); MockCacheSync <string> mockCache = new MockCacheSync <string> .Builder().Clear().Build(); BlockingClassCacheSync <string> subject = new BlockingClassCacheSync <string>(mockSemaphoreSlimBookEnd, mockCache); // Act subject.Clear(); // Assert mockCache.AssertClearInvoked(); mockSemaphoreSlimBookEnd.AssertWaitSyncInvoked(); mockSemaphoreSlimBookEnd.AssertReleaseInvoked(); }
public void ShouldRetrieveAndLock() { // Arrange MockSemaphoreSlimBookEnd mockSemaphoreSlimBookEnd = new MockSemaphoreSlimBookEnd.Builder().WaitSync().Release().Build(); MockCacheSync <string> mockCache = new MockCacheSync <string> .Builder().Retrieve("return-value").Build(); BlockingClassCacheSync <string> subject = new BlockingClassCacheSync <string>(mockSemaphoreSlimBookEnd, mockCache); // Act string actual = subject.Retrieve(() => null); // Assert actual.Should().Be("return-value"); mockSemaphoreSlimBookEnd.AssertWaitSyncInvoked(); mockSemaphoreSlimBookEnd.AssertReleaseInvoked(); }