Exemple #1
0
 public void ShouldTryAndUpdateUsingFunction()
 {
     var atomic = new Atomic<int>(0);
     const int expected = 100;
     bool success = atomic.TryUpdate(x => x + expected);
     Assert.True(success);
     Assert.AreEqual(expected, atomic.Value);
 }
Exemple #2
0
 public void ShouldTryAndUpdate()
 {
     var atomic = new Atomic<int>(100);
     const int expected = 110;
     bool success = atomic.TryUpdate(expected);
     Assert.True(success);
     Assert.AreEqual(expected, atomic.Value);
 }
Exemple #3
0
        public void ShouldTryAndUpdateUsingFunction()
        {
            var       atomic   = new Atomic <int>(0);
            const int expected = 100;
            bool      success  = atomic.TryUpdate(x => x + expected);

            Assert.True(success);
            Assert.AreEqual(expected, atomic.Value);
        }
Exemple #4
0
        public void ShouldTryAndUpdate()
        {
            var       atomic   = new Atomic <int>(100);
            const int expected = 110;
            bool      success  = atomic.TryUpdate(expected);

            Assert.True(success);
            Assert.AreEqual(expected, atomic.Value);
        }
Exemple #5
0
 public void ConcurrentUpdateShouldFail()
 {
     var atomic = new Atomic<int>();
     var result = false;
     atomic.Update(x =>
         {
             var thread = new Thread(() => result = atomic.TryUpdate(100));
             thread.Start();
             return x;
         });
     Assert.False(result);
 }
Exemple #6
0
        public void ConcurrentUpdateShouldFail()
        {
            var atomic = new Atomic <int>();
            var result = false;

            atomic.Update(x =>
            {
                var thread = new Thread(() => result = atomic.TryUpdate(100));
                thread.Start();
                return(x);
            });
            Assert.False(result);
        }