コード例 #1
0
ファイル: BlockSlotsTest.cs プロジェクト: Cricle/Anf
        public async Task GivenDisposeableObject_Dispose_AllDisposed()
        {
            var slot = new NullBlockSlots(10);

            for (int i = 0; i < slot.Size; i++)
            {
                slot.Datas[i] = () => new DispoableObject();
            }
            for (int i = 0; i < slot.Size; i++)
            {
                await slot.GetAsync(i);
            }
            slot.Dispose();
            var objs = slot.GetCreatedValues().OfType <DispoableObject>().ToArray();

            for (int i = 0; i < objs.Length; i++)
            {
                var obj = objs[i];
                Assert.IsTrue(obj.IsDisposed);
            }
        }
コード例 #2
0
ファイル: BlockSlotsTest.cs プロジェクト: Cricle/Anf
        public async Task GivenSize_MulitAsyncResultWasEqual()
        {
            var slot = new NullBlockSlots(1);

            slot.Datas[0] = () => new object();
            var res   = new object[10];
            var tasks = Enumerable.Range(0, res.Length)
                        .Select(x => slot.GetAsync(0).ContinueWith(y => res[x] = y.Result))
                        .ToArray();
            await Task.WhenAll(tasks);

            var val = slot[0];

            Assert.IsNotNull(val);
            for (int i = 0; i < res.Length; i++)
            {
                if (val != res[i])
                {
                    Assert.Fail("{0} not equal {1} != {2}", i.ToString(), val, res[i]);
                }
            }
            slot.Dispose();
        }