示例#1
0
        public void Test004()
        {
            var ac = new AssertionContext();

            ac.Set("abc", "def");

            IDisposable s1;

            using (s1 = ac.Push())
            {
                ac.Set("ghi", "jkl");

                var values = ac.GetData();
                assert.AreEqual(2, () => values.Count());
                assert.EveryUnsorted((new[] {
                    new
                    {
                        Key = "abc",
                        Value = "def",
                        Depth = 0
                    }, new {
                        Key = "ghi",
                        Value = "jkl",
                        Depth = 1,
                    }
                }).AsEnumerable(), () => values.Select(kvp => new
                {
                    Key   = kvp.Key,
                    Value = kvp.Value,
                    Depth = kvp.Depth
                }).AsEnumerable(), (t, a, b) => t.AreEqual(a, b));
            }

            // intentionally dispose s1 ag ain here, this shouldn't cause any problems
            s1.Dispose();

            var values2 = ac.GetData();

            assert.AreEqual(1, () => values2.Count());
            assert.EveryUnsorted((new[] {
                new
                {
                    Key = "abc",
                    Value = "def",
                    Depth = 0
                }
            }).AsEnumerable(), () => values2.Select(kvp => new
            {
                Key   = kvp.Key,
                Value = kvp.Value,
                Depth = kvp.Depth
            }).AsEnumerable(), (t, a, b) => t.AreEqual(a, b));
        }