Example #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_add_and_remove_annotation()
        {
            var annotatable = new Annotatable();

            Assert.Null(annotatable.FindAnnotation("Foo"));
            Assert.Null(annotatable.RemoveAnnotation(new Annotation("Foo", "Bar")));

            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.Annotations.ToArray());

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

            Assert.Empty(annotatable.Annotations);
            Assert.Null(annotatable.RemoveAnnotation(annotation));
            Assert.Null(annotatable["Foo"]);
            Assert.Null(annotatable.FindAnnotation("Foo"));
        }
Example #3
0
 Dictionary <string, string> GetStorageParameters(Annotatable annotatable)
 => annotatable.GetAnnotations()
 .Where(a => a.Name.StartsWith(NpgsqlAnnotationNames.StorageParameterPrefix))
 .ToDictionary(
     a => a.Name.Substring(NpgsqlAnnotationNames.StorageParameterPrefix.Length),
     a => GenerateStorageParameterValue(a.Value)
     );
        public void Annotations_are_ordered_by_name()
        {
            var annotatable = new Annotatable();

            var annotation1 = annotatable.AddAnnotation("Z", "Foo");
            var annotation2 = annotatable.AddAnnotation("A", "Bar");

            Assert.True(new[] { annotation2, annotation1 }.SequenceEqual(annotatable.GetAnnotations()));
        }
        public void Annotations_are_ordered_by_name()
        {
            var annotatable = new Annotatable();

            var annotation1 = annotatable.AddAnnotation("Z", "Foo");
            var annotation2 = annotatable.AddAnnotation("A", "Bar");

            Assert.True(new[] { annotation2, annotation1 }.SequenceEqual(annotatable.Annotations));
        }
        public void Addind_duplicate_annotation_throws()
        {
            var annotatable = new Annotatable();

            annotatable.AddAnnotation("Foo", "Bar");

            Assert.Equal(
                Strings.DuplicateAnnotation("Foo"),
                Assert.Throws <InvalidOperationException>(() => annotatable.AddAnnotation("Foo", "Bar")).Message);
        }
        public void Addind_duplicate_annotation_throws()
        {
            var annotatable = new Annotatable();

            annotatable.AddAnnotation("Foo", "Bar");

            Assert.Equal(
                CoreStrings.DuplicateAnnotation("Foo"),
                Assert.Throws<InvalidOperationException>(() => annotatable.AddAnnotation("Foo", "Bar")).Message);
        }
Example #8
0
    public void Added_annotation_type_is_consistent()
    {
        var annotatable = new Annotatable();

        annotatable.AddAnnotations(new[] { new ConventionAnnotation("Foo", "Bar", ConfigurationSource.Convention) });

        Assert.Equal(typeof(Annotation), annotatable.FindAnnotation("Foo").GetType());

        var conventionAnnotatable = new Model();

        conventionAnnotatable.AddAnnotations(new[] { new Annotation("Foo", "Bar") });

        Assert.Equal(typeof(ConventionAnnotation), conventionAnnotatable.FindAnnotation("Foo").GetType());
    }
        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"));
        }
        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);
        }
Example #12
0
 protected InternalMetadataBuilder(Annotatable metadata)
     : base(metadata)
 {
 }
 private bool?IsMemoryOptimized(Annotatable annotatable)
 => annotatable[SqlServerAnnotationNames.MemoryOptimized] as bool?;
Example #14
0
 private bool?IsMemoryOptimized(Annotatable annotatable)
 => annotatable[SqlServerFullAnnotationNames.Instance.MemoryOptimized] as bool?;
Example #15
0
 private static bool IsMemoryOptimized(Annotatable annotatable)
 => annotatable[SqlServerAnnotationNames.MemoryOptimized] as bool? == true;
Example #16
0
 private bool IsMemoryOptimized(Annotatable annotatable, IModel model, string schema, string tableName)
 => annotatable[SqlServerAnnotationNames.MemoryOptimized] as bool?
 ?? FindEntityTypes(model, schema, tableName)?.Any(t => t.SqlServer().IsMemoryOptimized) == true;
 protected InternalMetadataBuilder([NotNull] Annotatable metadata)
 {
     Metadata = metadata;
 }
 protected virtual void CopyAnnotations(IEnumerable <IAnnotation> annotations, Annotatable annotatable)
 {
     foreach (var annotation in annotations)
     {
         annotatable.AddAnnotation(annotation.Name, annotation.Value);
     }
 }
 private static bool IsMemoryOptimized(Annotatable annotatable)
 => annotatable[OracleAnnotationNames.MemoryOptimized] as bool? == true;