public void SetsIsLockAquiredToTrue()
 {
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     context.Acquire();
     Assert.IsTrue(context.IsLockAcquired);
 }
 public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEnd()
 {
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     context.Execute(() => Assert.IsTrue(context.IsLockAcquired));
     Assert.IsFalse(context.IsLockAcquired);
 }
Exemplo n.º 3
0
            public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEnd()
            {
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                context.Execute(() => Assert.IsTrue(context.IsLockAcquired));
                Assert.IsFalse(context.IsLockAcquired);
            }
Exemplo n.º 4
0
            public void KeepsIsLockAquiredInFalse()
            {
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                context.Release();
                Assert.IsFalse(context.IsLockAcquired);
            }
Exemplo n.º 5
0
            public void SetsIsLockAquiredToTrue()
            {
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                context.Acquire();
                Assert.IsTrue(context.IsLockAcquired);
            }
            public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEnd()
            {
                var @event  = new AutoResetEvent(false);
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                context.Enqueue(() => Assert.IsTrue(context.IsLockAcquired), (sender, args) => @event.Set());
                @event.WaitOne();
                Assert.IsFalse(context.IsLockAcquired);
            }
 public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEndAndReturnAValue()
 {
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     int expected = new Random().Next(50, 100);
     int result = context.Execute(() =>
         {
             Assert.IsTrue(context.IsLockAcquired);
             return expected;
         });
     Assert.IsFalse(context.IsLockAcquired);
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 8
0
            public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEndAndReturnAValue()
            {
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                int expected = new Random().Next(50, 100);
                int result   = context.Execute(() =>
                {
                    Assert.IsTrue(context.IsLockAcquired);
                    return(expected);
                });

                Assert.IsFalse(context.IsLockAcquired);
                Assert.AreEqual(expected, result);
            }
            public void NestedExecuteCallAreAllowed()
            {
                var context = new SynchronizationContext();
                Assert.IsFalse(context.IsLockAcquired);
                int expected = new Random().Next(50, 100);
                int result = context.Execute(() =>
                    {
                        int nestedResult = context.Execute(() =>
                            {
                                Assert.IsTrue(context.IsLockAcquired);
                                return expected;
                            });
                        Assert.IsTrue(context.IsLockAcquired);
                        return nestedResult;
                    });

                Assert.IsFalse(context.IsLockAcquired);
                Assert.AreEqual(expected, result);
            }
Exemplo n.º 10
0
            public void NestedExecuteCallAreAllowed()
            {
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                int expected = new Random().Next(50, 100);
                int result   = context.Execute(() =>
                {
                    int nestedResult = context.Execute(() =>
                    {
                        Assert.IsTrue(context.IsLockAcquired);
                        return(expected);
                    });
                    Assert.IsTrue(context.IsLockAcquired);
                    return(nestedResult);
                });

                Assert.IsFalse(context.IsLockAcquired);
                Assert.AreEqual(expected, result);
            }
            public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEndAndReturnAValue()
            {
                var @event  = new AutoResetEvent(false);
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                int expected = new Random().Next(50, 100);
                int result   = 0;

                context.Enqueue(() =>
                {
                    Assert.IsTrue(context.IsLockAcquired);
                    return(expected);
                }, (sender, args) =>
                {
                    result = (int)args.Result;
                    @event.Set();
                });
                @event.WaitOne();
                Assert.IsFalse(context.IsLockAcquired);
                Assert.AreEqual(expected, result);
            }
 public void KeepsIsLockAquiredInFalse()
 {
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     context.Release();
     Assert.IsFalse(context.IsLockAcquired);
 }
Exemplo n.º 13
0
 public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEnd()
 {
     var @event = new AutoResetEvent(false);
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     context.Enqueue(() => Assert.IsTrue(context.IsLockAcquired), (sender, args) => @event.Set());
     @event.WaitOne();
     Assert.IsFalse(context.IsLockAcquired);
 }
Exemplo n.º 14
0
 public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEndAndReturnAValue()
 {
     var @event = new AutoResetEvent(false);
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     int expected = new Random().Next(50, 100);
     int result = 0;
     context.Enqueue(() =>
     {
         Assert.IsTrue(context.IsLockAcquired);
         return expected;
     }, (sender, args) =>
         {
             result = (int)args.Result;
             @event.Set();
         });
     @event.WaitOne();
     Assert.IsFalse(context.IsLockAcquired);
     Assert.AreEqual(expected, result);
 }