Exemple #1
0
        public void Can_add_and_remove_annotation()
        {
            var annotatable = new Annotatable();

            Assert.Null(annotatable.FindAnnotation("Foo"));
            Assert.Null(annotatable.RemoveAnnotation("Foo"));

            var annotation = annotatable.AddAnnotation("Foo", "Bar");

            Assert.NotNull(annotation);
            Assert.Equal("Bar", annotation.Value);
            Assert.Equal("Bar", annotatable["Foo"]);
            Assert.Same(annotation, annotatable.FindAnnotation("Foo"));

            Assert.Same(annotation, annotatable.GetOrAddAnnotation("Foo", "Baz"));

            Assert.Equal(new[] { annotation }, annotatable.GetAnnotations().ToArray());

            Assert.Same(annotation, annotatable.RemoveAnnotation(annotation.Name));

            Assert.Empty(annotatable.GetAnnotations());
            Assert.Null(annotatable.RemoveAnnotation(annotation.Name));
            Assert.Null(annotatable["Foo"]);
            Assert.Null(annotatable.FindAnnotation("Foo"));
        }