예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }