Esempio n. 1
0
    public void Can_get_and_set_model_annotations()
    {
        IMutableAnnotatable annotatable = new Annotatable();

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

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

        annotatable["Foo"] = "horse";

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

        annotatable["Foo"] = null;

        Assert.Null(annotatable["Foo"]);
        Assert.Empty(annotatable.GetAnnotations());

        Assert.Equal(
            CoreStrings.AnnotationNotFound("Foo", "Microsoft.EntityFrameworkCore.Infrastructure.Annotatable"),
            Assert.Throws <InvalidOperationException>(() => annotatable.GetAnnotation("Foo")).Message);
    }
        public void Can_get_and_set_model_annotations()
        {
            var annotatable = new Annotatable();
            var annotation  = annotatable.GetOrAddAnnotation("Foo", "Bar");

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

            annotatable["Foo"] = "horse";

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

            annotatable["Foo"] = null;

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

            Assert.Equal(
                Strings.AnnotationNotFound("Foo"),
                Assert.Throws <InvalidOperationException>(() => annotatable.GetAnnotation("Foo")).Message);
        }
        public void Can_get_and_set_model_annotations()
        {
            var annotatable = new Annotatable();
            var annotation = annotatable.GetOrAddAnnotation("Foo", "Bar");

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

            annotatable["Foo"] = "horse";

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

            annotatable["Foo"] = null;

            Assert.Null(annotatable["Foo"]);
            Assert.Empty(annotatable.GetAnnotations());

            Assert.Equal(
                CoreStrings.AnnotationNotFound("Foo"),
                Assert.Throws<InvalidOperationException>(() => annotatable.GetAnnotation("Foo")).Message);
        }