Example #1
0
        public void BeginAnnotationAndEndAnnotation_PushAndPopAnnotationsOnStack()
        {
            var    document = new SplashDocument();
            var    key      = new Key <string>("href");
            string value;

            Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value));
            Assert.IsNull(value);

            document.BeginAnnotation(key, "a");
            Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
            Assert.AreEqual("a", value);

            document.EndAnnotation(key);
            Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value));
            Assert.IsNull(value);

            using (document.BeginAnnotation(key, "b"))
            {
                Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
                Assert.AreEqual("b", value);

                using (document.BeginAnnotation(key, "c"))
                {
                    Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
                    Assert.AreEqual("c", value);
                }

                Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
                Assert.AreEqual("b", value);
            }

            Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value));
            Assert.IsNull(value);
        }
        public void BeginAnnotationAndEndAnnotation_PushAndPopAnnotationsOnStack()
        {
            var document = new SplashDocument();
            var key = new Key<string>("href");
            string value;

            Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value));
            Assert.IsNull(value);

            document.BeginAnnotation(key, "a");
            Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
            Assert.AreEqual("a", value);

            document.EndAnnotation(key);
            Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value));
            Assert.IsNull(value);

            using (document.BeginAnnotation(key, "b"))
            {
                Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
                Assert.AreEqual("b", value);

                using (document.BeginAnnotation(key, "c"))
                {
                    Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
                    Assert.AreEqual("c", value);
                }

                Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value));
                Assert.AreEqual("b", value);
            }

            Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value));
            Assert.IsNull(value);
        }