Esempio n. 1
0
        public void GetEntityFrameworkVersion_returns_null_when_misc_files()
        {
            var project         = MockDTE.CreateMiscFilesProject();
            var serviceProvider = new Mock <IServiceProvider>();

            var schemaVersion = EdmUtils.GetEntityFrameworkVersion(project, serviceProvider.Object);

            Assert.Null(schemaVersion);
        }
Esempio n. 2
0
        public void GetEntityFrameworkVersion_returns_version_when_ef_installed()
        {
            var helper = new MockDTE(
                ".NETFramework,Version=v4.5", references: new[] { MockDTE.CreateReference("EntityFramework", "6.0.0.0") });

            var schemaVersion = EdmUtils.GetEntityFrameworkVersion(helper.Project, helper.ServiceProvider);

            Assert.Equal(EntityFrameworkVersion.Version3, schemaVersion);
        }
Esempio n. 3
0
        // <summary>
        //     Project retargeting event handler.
        //     1. Check the project type, return immediately if project is misc project or a project that does not support EF.
        //     2. Find all the EDMX files in the project. Skip Data Services edmx files and linked files.
        //     3. Sync all the namespaces based on the new target framework
        // </summary>
        public void RetargetFilesInProject()
        {
            var project = VSHelpers.GetProject(_hierarchy);

            if (project == null ||
                !VsUtils.EntityFrameworkSupportedInProject(project, _serviceProvider, allowMiscProject: false))
            {
                return;
            }

            var targetSchemaVersion = EdmUtils.GetEntityFrameworkVersion(project, _serviceProvider, useLatestIfNoEF: false);

            Debug.Assert(targetSchemaVersion != null, "schema version must not be null for projects that support EF");

            var documentMap = new Dictionary <string, object>();

            foreach (var vsFileInfo in GetEdmxFileInfos())
            {
                try
                {
                    var projectItem = VsUtils.GetProjectItem(_hierarchy, vsFileInfo.ItemId);

                    // skip the process for astoria edmx file or a linked edmx file
                    if (IsDataServicesEdmx(projectItem.get_FileNames(1)) ||
                        VsUtils.IsLinkProjectItem(projectItem))
                    {
                        continue;
                    }

                    var doc = RetargetFile(vsFileInfo.Path, targetSchemaVersion);
                    if (doc != null)
                    {
                        documentMap.Add(vsFileInfo.Path, doc);
                    }
                }
                catch (Exception ex)
                {
                    // TODO: When there is an exception; should we continue?
                    VsUtils.LogStandardError(
                        string.Format(CultureInfo.CurrentCulture, Resources.ErrorSynchingEdmxNamespaces, vsFileInfo.Path, ex.Message),
                        vsFileInfo.Path, 0, 0);
                    throw;
                }
            }

            WriteModifiedFiles(project, documentMap);
        }
Esempio n. 4
0
        public void GetEntityFrameworkVersion_returns_latest_version_when_EF_dll_in_the_project_and_useLatestIfNoEf_true()
        {
            var netFxToSchemaVersionMapping =
                new[]
            {
                new KeyValuePair <string, Version>(".NETFramework,Version=v4.5", new Version(3, 0, 0, 0)),
                new KeyValuePair <string, Version>(".NETFramework,Version=v4.0", new Version(3, 0, 0, 0)),
                new KeyValuePair <string, Version>(".NETFramework,Version=v3.5", new Version(1, 0, 0, 0))
            };

            foreach (var mapping in netFxToSchemaVersionMapping)
            {
                var helper        = new MockDTE(/* .NET Framework Moniker */ mapping.Key, references: new Reference[0]);
                var schemaVersion = EdmUtils.GetEntityFrameworkVersion(helper.Project, helper.ServiceProvider, useLatestIfNoEF: true);
                Assert.Equal(/*expected schema version */ mapping.Value, schemaVersion);
            }
        }