public void SetNextValueTest003()
        {
            List <int> l    = new List <int>();
            var        hack = 0;
            var        a    = InterlockedUtilty.SetNextValue(ref l, 42, (o, a) => {
                o.Add(a);
                if (hack == 0)
                {
                    l = new List <int>()
                    {
                        -1
                    }; hack++;
                }
                return(o);
            }, (o) => {
                l = new List <int>()
                {
                    -2
                }; hack++;
                Assert.Equal(42, o[0]);
            });

            Assert.NotNull(l);
            Assert.Equal(2, hack);
            Assert.Equal(new List <int>()
            {
                -2, 42
            }, l);
        }
        public void SetNextValueTest002()
        {
            List <int> l = null;
            var        a = InterlockedUtilty.SetNextValue(ref l, 1, (o, a) => { var r = o ?? new List <int>(); r.Add(a); return(r); }, (o) => Assert.Equal("Cannot", "be"));
            var        b = InterlockedUtilty.SetNextValue(ref l, 2, (o, a) => { var r = o ?? new List <int>(); r.Add(a); return(r); }, (o) => Assert.Equal("Cannot", "be"));

            Assert.NotNull(l);
            Assert.Same(l, a);
            Assert.Same(a, b);
            Assert.Equal(new List <int>()
            {
                1, 2
            }, l);
        }
        public void SetNextValueTest001()
        {
            List <int> l = new List <int>()
            {
                1
            };
            var o = InterlockedUtilty.SetNextValue(ref l, 2, (o, a) => { var r = o ?? new List <int>(); r.Add(a); return(r); }, (v) => Assert.Equal("Cannot", "be"));

            Assert.Same(o, l);
            Assert.Equal(new List <int>()
            {
                1, 2
            }, l);
        }