Exemple #1
0
 public void CreateAndValidateEdmItemCollection_throws_ArgumentNullException_for_null_targetFrameworkVersion()
 {
     Assert.Equal(
         "targetFrameworkVersion",
         Assert.Throws <ArgumentNullException>(
             () => EdmExtension.CreateAndValidateEdmItemCollection(string.Empty, null)).ParamName);
 }
Exemple #2
0
        public void CreateStorageMappingItemCollection_returns_errors_for_invalid_ssdl()
        {
            var v3 = new Version(3, 0, 0, 0);
            var edmItemCollection   = EdmExtension.CreateAndValidateEdmItemCollection(Csdl, v3);
            var storeItemCollection =
                EdmExtension.CreateAndValidateStoreItemCollection(
                    Ssdl,
                    v3,
                    resolver,
                    false);

            var invalidMsl = XDocument.Parse(Msl);

            invalidMsl
            .Descendants("{http://schemas.microsoft.com/ado/2009/11/mapping/cs}ScalarProperty")
            .First()
            .SetAttributeValue("Name", "Non-existing-property");

            IList <EdmSchemaError> edmErrors;
            var storageMappingItemCollection =
                EdmExtension.CreateStorageMappingItemCollection(
                    edmItemCollection,
                    storeItemCollection,
                    invalidMsl.ToString(),
                    out edmErrors);

            Assert.Null(storageMappingItemCollection);
            Assert.Equal(1, edmErrors.Count);
            Assert.Contains("'Non-existing-property'", edmErrors[0].Message);
        }
Exemple #3
0
 public void CreateAndValidateEdmItemCollection_throws_ArgumentNullException_for_null_csdl()
 {
     Assert.Equal(
         "csdl",
         Assert.Throws <ArgumentNullException>(
             () => EdmExtension.CreateAndValidateEdmItemCollection(null, new Version(1, 0, 0, 0))).ParamName);
 }
Exemple #4
0
        public void CreateAndValidateEdmItemCollection_creates_EdmItemCollection_for_valid_csdl_and_targetFrameworkVersion()
        {
            var edmItemCollection = EdmExtension.CreateAndValidateEdmItemCollection(Csdl, new Version(3, 0, 0, 0));

            Assert.NotNull(edmItemCollection);
            Assert.NotNull(edmItemCollection.GetItem <EntityType>("AdventureWorksModel.Entity"));
        }
Exemple #5
0
        public void CreateAndValidateEdmItemCollection_throws_ArgumentException_for_incorrect_targetFrameworkVersion()
        {
            var exception = Assert.Throws <ArgumentException>(
                () => EdmExtension.CreateAndValidateEdmItemCollection(string.Empty, new Version(0, 0)));

            Assert.Equal("targetFrameworkVersion", exception.ParamName);
            Assert.True(
                exception.Message.StartsWith(
                    string.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, "0.0")));
        }
Exemple #6
0
        public void CreateAndValidateEdmItemCollection_throws_for_valid_csdl_whose_version_is_newer_than_targetFrameworkVersion()
        {
            var exception = Assert.Throws <InvalidOperationException>(
                () => EdmExtension.CreateAndValidateEdmItemCollection(Csdl, new Version(2, 0, 0, 0)));

            Assert.Contains(
                exception.Message,
                string.Format(
                    CultureInfo.CurrentCulture,
                    Resources.TargetVersionSchemaVersionMismatch,
                    new Version(3, 0, 0, 0),
                    new Version(2, 0, 0, 0)));
        }
Exemple #7
0
        public void CreateStorageMappingItemCollection_creates_storage_mapping_item_collection_for_valid_artifacts()
        {
            var v3 = new Version(3, 0, 0, 0);
            var edmItemCollection   = EdmExtension.CreateAndValidateEdmItemCollection(Csdl, v3);
            var storeItemCollection =
                EdmExtension.CreateAndValidateStoreItemCollection(
                    Ssdl,
                    v3,
                    resolver,
                    false);

            IList <EdmSchemaError> edmErrors;
            var storageMappingItemCollection = EdmExtension.CreateStorageMappingItemCollection(
                edmItemCollection, storeItemCollection, Msl, out edmErrors);

            Assert.NotNull(storageMappingItemCollection);
            Assert.Equal(0, edmErrors.Count);
            Assert.NotNull(storageMappingItemCollection.GetItem <GlobalItem>("AdventureWorksEntities3"));
        }
Exemple #8
0
        public void CreateAndValidateEdmItemCollection_throws_original_erros_even_if_targetFrameworkVersion_is_older_than_csdl_version()
        {
            var invalidCsdl = XDocument.Parse(Csdl);

            invalidCsdl.Descendants("{http://schemas.microsoft.com/ado/2009/11/edm}PropertyRef").Remove();
            invalidCsdl
            .Descendants("{http://schemas.microsoft.com/ado/2009/11/edm}EntityType")
            .Single()
            .Add(new XElement("{http://schemas.microsoft.com/ado/2009/11/edm}InvalidElement"));

            var exception = Assert.Throws <InvalidOperationException>(
                () => EdmExtension.CreateAndValidateEdmItemCollection(invalidCsdl.ToString(), new Version(2, 0, 0, 0)));

            Assert.True(exception.Message.StartsWith(Resources.ErrorCsdlNotValid.Replace("{0}", string.Empty)));
            var errorMessages = exception.Message.Split('\n');

            Assert.Equal(3, errorMessages.Length);
            Assert.Contains("'PropertyRef'", errorMessages[0]);
            Assert.Contains("'InvalidElement'", errorMessages[1]);
            Assert.Contains("InvalidElement", errorMessages[2]);
        }