Esempio n. 1
0
        public void BlockForTimeout()
        {
            // SETUP
            TimeSpan waitTime = TimeSpan.FromMilliseconds(100);
            // Create a pretend handle, so we can pretend a timeout
            // occurred.
            var mockWaitHandle = Substitute.For <IResourceLock>();

            mockWaitHandle.WaitOne(waitTime).Returns(false);
            // Setup our fake factory to return our fake wait handle
            var factory = Substitute.For <IResourceLockFactory>();

            factory.Create().Returns(mockWaitHandle);
            // Finally we will need our resource lock manager to work with
            var mgr = new ResourceLockManager <int>(factory);

            // ACT
            var item = mgr.BlockFor(0, waitTime);

            // ASSERT
            // Should throw exception
        } /* End of Function - BlockForTimeout */
Esempio n. 2
0
        public void BlockFor()
        {
            // SETUP
            // Specify the time to wait
            var waitTime = TimeSpan.FromMilliseconds(0);
            // Create our fakes
            var lockObj = Substitute.For <IResourceLock>();

            lockObj.WaitOne(waitTime).Returns(true);
            var factory = Substitute.For <IResourceLockFactory>();

            factory.Create().Returns(lockObj);
            // Create the resource lock manager to work with
            var mgr = new ResourceLockManager <int>(factory);

            // ACT
            // Block for item 0, which should create a new one
            var item = mgr.BlockFor(0, waitTime);

            // ASSERT
            Assert.AreEqual(item, lockObj);
            factory.Received(1).Create();
        } /* End of Function - BlockFor */