예제 #1
0
        public void Can_add_and_remove_annotation()
        {
            var metadataBase = new ConcreteMetadata();

            Assert.Null(metadataBase.TryGetAnnotation("Foo"));
            Assert.Null(metadataBase.RemoveAnnotation(new Annotation("Foo", "Bar")));

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

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

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

            Assert.Equal(new[] { annotation }, metadataBase.Annotations.ToArray());

            Assert.Same(annotation, metadataBase.RemoveAnnotation(annotation));

            Assert.Empty(metadataBase.Annotations);
            Assert.Null(metadataBase.RemoveAnnotation(annotation));
            Assert.Null(metadataBase["Foo"]);
            Assert.Null(metadataBase.TryGetAnnotation("Foo"));
        }
예제 #2
0
        public void Can_get_and_set_model_annotations()
        {
            var metadataBase = new ConcreteMetadata();
            var annotation   = metadataBase.GetOrAddAnnotation("Foo", "Bar");

            Assert.NotNull(annotation);
            Assert.Same(annotation, metadataBase.TryGetAnnotation("Foo"));
            Assert.Same(annotation, metadataBase.GetAnnotation("Foo"));
            Assert.Null(metadataBase["foo"]);
            Assert.Null(metadataBase.TryGetAnnotation("foo"));

            metadataBase["Foo"] = "horse";

            Assert.Equal("horse", metadataBase["Foo"]);

            metadataBase["Foo"] = null;

            Assert.Null(metadataBase["Foo"]);
            Assert.Empty(metadataBase.Annotations);

            Assert.Equal(
                Strings.FormatAnnotationNotFound("Foo"),
                Assert.Throws <ModelItemNotFoundException>(() => metadataBase.GetAnnotation("Foo")).Message);
        }