Release() публичный Метод

Exits the SemaphoreLight once.
public Release ( ) : int
Результат int
Пример #1
0
        public void Release()
        {
            var initialCount = new Random().Next(1, 10);
            var target = new SemaphoreLight(initialCount);

            Assert.AreEqual(initialCount, target.Release());
            Assert.AreEqual(initialCount + 1, target.CurrentCount);

            Assert.AreEqual(initialCount + 1, target.Release());
            Assert.AreEqual(initialCount + 2, target.CurrentCount);
        }
Пример #2
0
        public void Release_ReleaseCount()
        {
            var initialCount = new Random().Next(1, 10);
            var target = new SemaphoreLight(initialCount);

            var releaseCount1 = new Random().Next(1, 10);
            Assert.AreEqual(initialCount, target.Release(releaseCount1));
            Assert.AreEqual(initialCount + releaseCount1, target.CurrentCount);

            var releaseCount2 = new Random().Next(1, 10);
            Assert.AreEqual(initialCount + releaseCount1, target.Release(releaseCount2));
            Assert.AreEqual(initialCount + releaseCount1 + releaseCount2, target.CurrentCount);
        }
Пример #3
0
        public void WaitTest()
        {
            const int sleepTime = 200; 
            const int initialCount = 2;
            var target = new SemaphoreLight(initialCount);

            var start = DateTime.Now;

            target.Wait();
            target.Wait();

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds < 50);

            var releaseThread = new Thread(
                () =>
                    {
                        Thread.Sleep(sleepTime);
                        target.Release();
                    });
            releaseThread.Start();

            target.Wait();

            var end = DateTime.Now;
            var elapsed = end - start;

            Assert.IsTrue(elapsed.TotalMilliseconds > 200);
            Assert.IsTrue(elapsed.TotalMilliseconds < 250);
        }
Пример #4
0
 public void ReleaseTest()
 {
     int initialCount = 0; // TODO: Initialize to an appropriate value
     SemaphoreLight target = new SemaphoreLight(initialCount); // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.Release();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }