Ejemplo n.º 1
0
        public void AnnotableGetAnnotation_ReturnsWhatsBeenSet()
        {
            var model = new EdmModel();

            foreach (IEdmElement annotatable in this.GetEdmAnnotatables())
            {
                var qualifiedNames = this.GetInterestingQualifiedNames().ToArray();

                // set
                for (int i = 0; i < qualifiedNames.Count(); i++)
                {
                    MyQualifiedName q = qualifiedNames[i];
                    model.SetAnnotationValue(annotatable, q.NamespaceName, q.Name, q.MyFullName);

                    Assert.AreEqual(i + 1, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
                }

                // get
                object result = model.GetAnnotationValue(annotatable, "_Not_Exist_", "_Not_Exist_");
                Assert.IsNull(result, "GetAnnotation() on {0}.", annotatable);

                foreach (MyQualifiedName q in qualifiedNames)
                {
                    result = model.GetAnnotationValue(annotatable, q.NamespaceName, q.Name);
                    Assert.AreEqual(q.MyFullName, result, "GetAnnotation() on {0}.", annotatable);

                    IEdmDirectValueAnnotation annotation = model.DirectValueAnnotations(annotatable).FirstOrDefault(a => a.NamespaceUri == q.NamespaceName && a.Name == q.Name);
                    Assert.IsNotNull(annotation, "GetAnnotation() on {0}.", annotatable);
                    Assert.AreEqual(q.MyFullName, ((IEdmDirectValueAnnotation)annotation).Value, "GetAnnotation() on {0}.", annotatable);
                }
            }
        }
Ejemplo n.º 2
0
        public void ExtensionGetInternalAnnotation_ReturnsNull_IfDeleted()
        {
            var model = new EdmModel();

            foreach (IEdmElement annotatable in this.GetEdmAnnotatables())
            {
                // set
                model.SetAnnotationValue(annotatable, "foo");
                model.SetAnnotationValue(annotatable, new MyQualifiedName("foo", "bar"));
                model.SetAnnotationValue <IEdmType>(annotatable, new EdmComplexType("foo", "foo", null, false));

                Assert.AreEqual(3, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);

                // delete
                model.SetAnnotationValue <Object>(annotatable, null);
                model.SetAnnotationValue <MyQualifiedName>(annotatable, null);

                string result1 = model.GetAnnotationValue <string>(annotatable);
                Assert.AreEqual("foo", result1, "(Extension) GetAnnotation<T>() on {0}.", annotatable);

                MyQualifiedName result2 = model.GetAnnotationValue <MyQualifiedName>(annotatable);
                Assert.IsNull(result2, "(Extension) GetAnnotation<T>() on {0}.", annotatable);

                Assert.AreEqual(2, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
            }
        }
Ejemplo n.º 3
0
        public void ExtensionGetInternalAnnotation_ReturnsWhatsBeenSet()
        {
            var model = new EdmModel();

            foreach (IEdmElement annotatable in this.GetEdmAnnotatables())
            {
                // set
                model.SetAnnotationValue(annotatable, "foo");
                model.SetAnnotationValue(annotatable, new MyQualifiedName("foo", "bar"));
                model.SetAnnotationValue <IEdmType>(annotatable, new EdmComplexType("foo", "foo", null, false));

                Assert.AreEqual(3, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);

                // get
                string result1 = model.GetAnnotationValue <string>(annotatable);
                Assert.AreEqual("foo", result1, "(Extension) GetAnnotation<T>() on {0}.", annotatable);

                MyQualifiedName result2 = model.GetAnnotationValue <MyQualifiedName>(annotatable);
                Assert.AreEqual(new MyQualifiedName("foo", "bar"), result2, "(Extension) GetAnnotation<T>() on {0}.", annotatable);

                IEdmType result3 = model.GetAnnotationValue <IEdmType>(annotatable);
                Assert.IsTrue(result3 is EdmComplexType, "(Extension) GetAnnotation<T>() on {0}.", annotatable);
                Assert.AreEqual("foo.foo", (result3 as IEdmSchemaType).FullName(), "(Extension) GetAnnotation<T>() on {0}.", annotatable);

                Object result4 = model.GetAnnotationValue <Object>(annotatable);
                Assert.IsNull(result4, "(Extension) GetAnnotation<T>() on {0}.", annotatable);

                Assert.AreEqual(3, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
            }
        }
Ejemplo n.º 4
0
        public void AnnotableGetAnnotation_ReturnsUpdatedValue()
        {
            foreach (IEdmElement annotatable in this.GetEdmAnnotatables())
            {
                var qualifiedNames = this.GetInterestingQualifiedNames().ToArray();
                var model          = new EdmModel();

                // set
                for (int i = 0; i < qualifiedNames.Count(); i++)
                {
                    MyQualifiedName q = qualifiedNames[i];
                    model.SetAnnotationValue(annotatable, q.NamespaceName, q.Name, q.MyFullName);

                    Assert.AreEqual(i + 1, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
                }

                // update
                foreach (MyQualifiedName q in qualifiedNames)
                {
                    model.SetAnnotationValue(annotatable, q.NamespaceName, q.Name, q.MyFullName + q.MyFullName);
                    object result = model.GetAnnotationValue(annotatable, q.NamespaceName, q.Name);
                    Assert.AreEqual(q.MyFullName + q.MyFullName, result, "GetAnnotation() on {0}.", annotatable);
                }

                Assert.AreEqual(qualifiedNames.Count(), model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
            }
        }
Ejemplo n.º 5
0
        public void AnnotableGetAnnotation_ReturnsNull_IfDeleted()
        {
            foreach (IEdmElement annotatable in this.GetEdmAnnotatables())
            {
                var qualifiedNames = this.GetInterestingQualifiedNames().ToArray();
                var model          = new EdmModel();

                // set
                for (int i = 0; i < qualifiedNames.Count(); i++)
                {
                    MyQualifiedName q = qualifiedNames[i];
                    model.SetAnnotationValue(annotatable, q.NamespaceName, q.Name, q.MyFullName);

                    Assert.AreEqual(i + 1, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
                }

                // delete
                for (int i = 0; i < qualifiedNames.Length; i++)
                {
                    MyQualifiedName q = qualifiedNames[i];
                    model.SetAnnotationValue(annotatable, q.NamespaceName, q.Name, null);

                    Assert.AreEqual(qualifiedNames.Length - i - 1, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
                }

                model.SetAnnotationValue(annotatable, "_Not_Exist_", "_Not_Exist_", null);

                foreach (MyQualifiedName q in qualifiedNames)
                {
                    object result = model.GetAnnotationValue(annotatable, q.NamespaceName, q.Name);
                    Assert.IsNull(result, "GetAnnotation() on {0}.", annotatable);
                }

                Assert.AreEqual(0, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
            }
        }