public void DispatchSaveToExtensions_invokes_serializers_if_present()
        {
            var inputDocument = XDocument.Parse("<model />");
            var updatedDocument = XDocument.Parse("<model x=\"1\" />");

            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            var mockProjectItem = new Mock<ProjectItem>();
            mockProjectItem.SetupGet(i => i.ContainingProject).Returns(mockDte.Project);

            var mockSerializerExtension = new Mock<IModelTransformExtension>();
            mockSerializerExtension
                .Setup(e => e.OnBeforeModelSaved(It.IsAny<ModelTransformExtensionContext>()))
                .Callback<ModelTransformExtensionContext>(
                    context =>
                        {
                            Assert.Equal(new Version(3, 0, 0, 0), context.EntityFrameworkVersion);
                            Assert.True(XNode.DeepEquals(inputDocument, context.OriginalDocument));
                            context.CurrentDocument = updatedDocument;
                        });

            var docData = new MicrosoftDataEntityDesignDocData(mockDte.ServiceProvider, Guid.NewGuid());
            docData.RenameDocData(0, mockDte.Hierarchy, 3, "model.edmx");

            var result = docData.DispatchSaveToExtensions(
                mockDte.ServiceProvider, mockProjectItem.Object, inputDocument.ToString(),
                new Lazy<IModelConversionExtension, IEntityDesignerConversionData>[1],
                new[] { new Lazy<IModelTransformExtension>(() => mockSerializerExtension.Object) });

            Assert.True(XNode.DeepEquals(updatedDocument, XDocument.Parse(result)));

            mockSerializerExtension.Verify(
                e => e.OnAfterModelLoaded(It.IsAny<ModelTransformExtensionContext>()), Times.Never());
            mockSerializerExtension.Verify(
                e => e.OnBeforeModelSaved(It.IsAny<ModelTransformExtensionContext>()), Times.Once());
        }
        public void GetTextBoxConnectionStringValue_returns_entity_connection_string_for_EDMX_ModelFirst()
        {
            var guid = new Guid("42424242-4242-4242-4242-424242424242");

            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            mockDte.SetProjectProperties(new Dictionary<string, object> { { "FullPath", @"C:\Project" } });
            var mockParentProjectItem = new Mock<ProjectItem>();
            mockParentProjectItem.Setup(p => p.Collection).Returns(Mock.Of<ProjectItems>());
            mockParentProjectItem.Setup(p => p.Name).Returns("Folder");

            var mockModelProjectItem = new Mock<ProjectItem>();
            var mockCollection = new Mock<ProjectItems>();
            mockCollection.Setup(p => p.Parent).Returns(mockParentProjectItem.Object);
            mockModelProjectItem.Setup(p => p.Collection).Returns(mockCollection.Object);

            var wizardPageDbConfig =
                new WizardPageDbConfig(
                    ModelBuilderWizardFormHelper.CreateWizard(ModelGenerationOption.GenerateDatabaseScript, mockDte.Project, @"C:\Project\myModel.edmx"));

            Assert.Equal(
                "metadata=res://*/myModel.csdl|res://*/myModel.ssdl|res://*/myModel.msl;provider=System.Data.SqlClient;" +
                "provider connection string=\"integrated security=SSPI;MultipleActiveResultSets=True;App=EntityFramework\"",
                wizardPageDbConfig.GetTextBoxConnectionStringValue(
                    CreateDataProviderManager(guid),
                    guid,
                    "Integrated Security=SSPI"));
        }
        public void TargetNetFrameworkVersion_returns_null_for_non_NetFramework_project()
        {
            var mockMonikerHelper = new MockDTE("Xbox,Version=v4.0");

            Assert.Null(
                NetFrameworkVersioningHelper.TargetNetFrameworkVersion(
                    mockMonikerHelper.Project, mockMonikerHelper.ServiceProvider));
        }
        public void TargetNetFrameworkVersion_returns_null_for_invalid_target_framework_moniker()
        {
            var mockMonikerHelper = new MockDTE("abc");

            Assert.Null(
                NetFrameworkVersioningHelper.TargetNetFrameworkVersion(
                    mockMonikerHelper.Project, mockMonikerHelper.ServiceProvider));
        }
        public void TargetNetFrameworkVersion_returns_null_for_non_string_target_net_framework_moniker()
        {
            var mockMonikerHelper = new MockDTE(new object());

            Assert.Null(
                NetFrameworkVersioningHelper.TargetNetFrameworkVersion(
                    mockMonikerHelper.Project, mockMonikerHelper.ServiceProvider));
        }
        public void TargetNetFrameworkVersion_returns_targeted_version_from_valid_net_framework_moniker()
        {
            var mockMonikerHelper = new MockDTE(".NETFramework,Version=v4.0,Profile=Client");

            Assert.Equal(
                NetFrameworkVersioningHelper.NetFrameworkVersion4,
                NetFrameworkVersioningHelper.TargetNetFrameworkVersion(
                    mockMonikerHelper.Project, mockMonikerHelper.ServiceProvider));
        }
        public void TemplateSupported_returns_false_for_NetFramework3_5()
        {
            var mockMonikerHelper =
                new MockDTE(".NETFramework,Version=v3.5");

            Assert.False(
                DbContextCodeGenerator.TemplateSupported(
                    mockMonikerHelper.Project,
                    mockMonikerHelper.ServiceProvider));
        }
        public void TargetNetFrameworkVersion_returns_null_for_misc_project()
        {
            const string vsMiscFilesProjectUniqueName = "<MiscFiles>";

            var mockMonikerHelper = new MockDTE("abc", vsMiscFilesProjectUniqueName);

            Assert.Null(
                NetFrameworkVersioningHelper.TargetNetFrameworkVersion(
                    mockMonikerHelper.Project, mockMonikerHelper.ServiceProvider));
        }
        public void TemplateSupported_returns_false_for_Misc_project()
        {
            const string vsMiscFilesProjectUniqueName = "<MiscFiles>";

            var mockMonikerHelper =
                new MockDTE(".NETFramework,Version=v4.0", vsMiscFilesProjectUniqueName);

            Assert.False(
                DbContextCodeGenerator.TemplateSupported(
                    mockMonikerHelper.Project,
                    mockMonikerHelper.ServiceProvider));
        }
        public void RetargetFilesInProject_retargets_Edmx_files_in_project()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

            var projectItems =
                new[]
                    {
                        MockDTE.CreateProjectItem("C:\\model1.edmx"),
                        MockDTE.CreateProjectItem("D:\\model2.EDMX")
                    };

            var fileInfos =
                projectItems.Select(
                    i =>
                    new VSFileFinder.VSFileInfo
                        {
                            Hierarchy = mockDte.Hierarchy,
                            ItemId = mockDte.AddProjectItem(i),
                            Path = i.Object.get_FileNames(1)
                        }).ToArray();

            var mockRetargetingHandler =
                new Mock<RetargetingHandler>(mockDte.Hierarchy, mockDte.ServiceProvider)
                    {
                        CallBase = true
                    };

            mockRetargetingHandler
                .Protected()
                .Setup<IEnumerable<VSFileFinder.VSFileInfo>>("GetEdmxFileInfos")
                .Returns(fileInfos);

            mockRetargetingHandler
                .Protected().Setup<bool>("IsDataServicesEdmx", ItExpr.IsAny<string>()).Returns(false);

            mockRetargetingHandler
                .Protected()
                .Setup<XmlDocument>("RetargetFile", ItExpr.IsAny<string>(), ItExpr.IsAny<Version>()).Returns(new XmlDocument());

            mockRetargetingHandler
                .Protected()
                .Setup("WriteModifiedFiles", ItExpr.IsAny<Project>(), ItExpr.IsAny<Dictionary<string, object>>())
                .Callback(
                    (Project project, Dictionary<string, object> documentMap) =>
                    Assert.Equal(fileInfos.Select(f => f.Path), documentMap.Keys));

            mockRetargetingHandler.Object.RetargetFilesInProject();

            mockRetargetingHandler.Protected().Verify("IsDataServicesEdmx", Times.Exactly(2), ItExpr.IsAny<string>());
            mockRetargetingHandler.Protected().Verify("RetargetFile", Times.Exactly(2), ItExpr.IsAny<string>(), ItExpr.IsAny<Version>());
        }
        public void HasEntityFrameworkProvider_returns_false_when_no_legacy_provider_or_ef_reference()
        {
            var provider = new Mock<IVsDataProvider>();
            provider.Setup(p => p.GetProperty("InvariantName")).Returns("System.Data.OleDb");
            var providerGuid = Guid.NewGuid();
            var providers = new Dictionary<Guid, IVsDataProvider> { { providerGuid, provider.Object } };
            var dataProviderManager = new Mock<IVsDataProviderManager>();
            dataProviderManager.SetupGet(m => m.Providers).Returns(providers);
            var dte = new MockDTE(".NETFramework,Version=v4.5", references: Enumerable.Empty<Reference>());

            Assert.False(
                DataConnectionUtils.HasEntityFrameworkProvider(
                    dataProviderManager.Object,
                    providerGuid,
                    dte.Project,
                    dte.ServiceProvider));
        }
        public void HasEntityFrameworkProvider_returns_true_when_has_legacy_provider()
        {
            var provider = new Mock<IVsDataProvider>();
            provider.Setup(p => p.GetProperty("InvariantName")).Returns("System.Data.SqlClient");
            var providerGuid = Guid.NewGuid();
            var providers = new Dictionary<Guid, IVsDataProvider> { { providerGuid, provider.Object } };
            var dataProviderManager = new Mock<IVsDataProviderManager>();
            dataProviderManager.SetupGet(m => m.Providers).Returns(providers);
            var dte = new MockDTE(".NETFramework,Version=v4.5");

            Assert.True(
                DataConnectionUtils.HasEntityFrameworkProvider(
                    dataProviderManager.Object,
                    providerGuid,
                    dte.Project,
                    dte.ServiceProvider));
        }
        public void TemplateSupported_returns_true_when_targeting_NetFramework4_or_newer()
        {
            var targets =
                new[]
                    {
                        ".NETFramework,Version=v4.0",
                        ".NETFramework,Version=v4.5",
                        ".NETFramework,Version=v4.5.1"
                    };

            foreach (var target in targets)
            {
                var mockMonikerHelper = new MockDTE(target);

                Assert.True(
                    DbContextCodeGenerator.TemplateSupported(
                        mockMonikerHelper.Project,
                        mockMonikerHelper.ServiceProvider));
            }
        }
Ejemplo n.º 14
0
        public void GetMetadataFileNamesFromArtifactFileName_creates_metadata_file_names_for_non_null_edmx_ProjectItem()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            mockDte.SetProjectProperties(new Dictionary<string, object> { { "FullPath", @"D:\Projects\Project\Folder" } });
            var mockParentProjectItem = new Mock<ProjectItem>();
            mockParentProjectItem.Setup(p => p.Collection).Returns(Mock.Of<ProjectItems>());
            mockParentProjectItem.Setup(p => p.Name).Returns("Folder");

            var mockModelProjectItem = new Mock<ProjectItem>();
            var mockCollection = new Mock<ProjectItems>();
            mockCollection.Setup(p => p.Parent).Returns(mockParentProjectItem.Object);
            mockModelProjectItem.Setup(p => p.Collection).Returns(mockCollection.Object);

            var metadataFileNames =
                ConnectionManager.GetMetadataFileNamesFromArtifactFileName(
                mockDte.Project, @"c:\temp\myModel.edmx", mockDte.ServiceProvider, (_, __) => mockModelProjectItem.Object);

            Assert.Equal(@".\Folder\myModel.csdl", metadataFileNames[0]);
            Assert.Equal(@".\Folder\myModel.ssdl", metadataFileNames[1]);
            Assert.Equal(@".\Folder\myModel.msl", metadataFileNames[2]);
        }
        public void TryGetBufferViaExtensions_returns_false_when_converter_is_present_but_transformer_is_absent_for_non_edmx_file()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            var mockProjectItem = new Mock<ProjectItem>();
            mockProjectItem.SetupGet(i => i.ContainingProject).Returns(mockDte.Project);
            mockProjectItem.Setup(i => i.get_FileNames(It.IsAny<short>())).Returns("non-edmx-file.xmde");

            var mockConversionData = new Mock<IEntityDesignerConversionData>();
            mockConversionData.SetupGet(d => d.FileExtension).Returns("xmde");

            var mockConversionExtension = new Mock<IModelConversionExtension>();
            mockConversionExtension
                .Setup(e => e.OnAfterFileLoaded(It.IsAny<ModelConversionExtensionContext>()))
                .Callback<ModelConversionExtensionContext>(
                    ctx =>
                        {
                            Assert.Equal(ctx.EntityFrameworkVersion, new Version(3, 0, 0, 0));
                            Assert.Equal(ctx.FileInfo.Name, "non-edmx-file.xmde");
                            Assert.Same(ctx.ProjectItem, mockProjectItem.Object);
                            Assert.Same(ctx.Project, mockDte.Project);
                        });

            var converter =
                new Lazy<IModelConversionExtension, IEntityDesignerConversionData>(
                    () => mockConversionExtension.Object, mockConversionData.Object);

            string outputDocument;
            List<ExtensionError> errors;
            Assert.False(
                StandaloneXmlModelProvider.TryGetBufferViaExtensions(
                    mockDte.ServiceProvider, mockProjectItem.Object, string.Empty, new[] { converter },
                    new Lazy<IModelTransformExtension>[0], out outputDocument, out errors));

            Assert.Empty(outputDocument);
            Assert.Empty(errors);

            mockConversionExtension.Verify(e => e.OnAfterFileLoaded(It.IsAny<ModelConversionExtensionContext>()), Times.Once());
            mockConversionExtension.Verify(e => e.OnBeforeFileSaved(It.IsAny<ModelConversionExtensionContext>()), Times.Never());
            mockConversionData.Verify(e => e.FileExtension, Times.Once());
        }
        private static void Run_OnDeactivate_creates_and_verifies_model_path(
            ModelGenerationOption generationOption, LangEnum language, bool isWebSite, string expectedExtension)
        {
            var mockDte =
                new MockDTE(
                    ".NETFramework, Version=v4.5",
                    isWebSite
                        ? MockDTE.CreateWebSite(
                            properties: new Dictionary<string, object>
                            {
                                { "CurrentWebsiteLanguage", language == LangEnum.CSharp ? "C#" : "VB" }
                            }, 
                            assemblyReferences: new AssemblyReference[0])
                        : MockDTE.CreateProject(
                            kind: language == LangEnum.CSharp ? MockDTE.CSharpProjectKind : MockDTE.VBProjectKind, 
                            assemblyReferences: new Reference[0]));

            var modelBuilderSettings = new ModelBuilderSettings
            {
                NewItemFolder = @"C:\temp",
                ModelName = "myModel",
                Project = mockDte.Project,
                GenerationOption = generationOption
            };

            var mockWizardPageStart = 
                new Mock<WizardPageStart>(ModelBuilderWizardFormHelper.CreateWizard(modelBuilderSettings, mockDte.ServiceProvider), null) 
                { CallBase = true };

            mockWizardPageStart
                .Protected()
                .Setup<bool>("VerifyModelFilePath", ItExpr.IsAny<string>())
                .Returns(false);

            mockWizardPageStart.Object.OnDeactivate();

            mockWizardPageStart
                .Protected()
                .Verify("VerifyModelFilePath", Times.Once(), @"C:\temp\myModel" + expectedExtension);
        }
        public void TemplateSupported_returns_false_when_for_non_NetFramework_projects()
        {
            var targets =
                new[]
                    {
                        ".NETFramework,Version=v1.1",
                        "XBox,Version=v4.0",
                        "abc",
                        string.Empty,
                        null
                    };

            foreach (var target in targets)
            {
                var mockMonikerHelper = new MockDTE(target);

                Assert.False(
                    DbContextCodeGenerator.TemplateSupported(
                        mockMonikerHelper.Project,
                        mockMonikerHelper.ServiceProvider));
            }
        }
        public void DispatchSaveToExtensions_invokes_converter_for_non_edmx_files_if_present()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            var mockProjectItem = new Mock<ProjectItem>();
            mockProjectItem.SetupGet(i => i.ContainingProject).Returns(mockDte.Project);

            var mockConversionExtension = new Mock<IModelConversionExtension>();
            mockConversionExtension
                .Setup(c => c.OnBeforeFileSaved(It.IsAny<ModelConversionExtensionContext>()))
                .Callback<ModelConversionExtensionContext>(
                    context =>
                        {
                            Assert.Equal(new Version(3, 0, 0, 0), context.EntityFrameworkVersion);
                            context.OriginalDocument = "my model";
                        });

            var mockConversionData = new Mock<IEntityDesignerConversionData>();
            mockConversionData.Setup(d => d.FileExtension).Returns("xmde");

            var docData = new MicrosoftDataEntityDesignDocData(mockDte.ServiceProvider, Guid.NewGuid());
            docData.RenameDocData(0, mockDte.Hierarchy, 3, "model.xmde");

            Assert.Same(
                "my model",
                docData.DispatchSaveToExtensions(
                    mockDte.ServiceProvider, mockProjectItem.Object, "<model />",
                    new[]
                        {
                            new Lazy<IModelConversionExtension, IEntityDesignerConversionData>(
                                () => mockConversionExtension.Object, mockConversionData.Object),
                        },
                    new Lazy<IModelTransformExtension>[0]));

            mockConversionExtension.Verify(
                e => e.OnAfterFileLoaded(It.IsAny<ModelConversionExtensionContext>()), Times.Never());
            mockConversionExtension.Verify(
                e => e.OnBeforeFileSaved(It.IsAny<ModelConversionExtensionContext>()), Times.Once());
        }
        // note that this may not be the desired behavior see: https://entityframework.codeplex.com/workitem/1371
        public void TryGetBufferViaExtensions_throws_when_converter_is_absent_for_non_edmx_file()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            var mockProjectItem = new Mock<ProjectItem>();
            mockProjectItem.SetupGet(i => i.ContainingProject).Returns(mockDte.Project);
            mockProjectItem.Setup(i => i.get_FileNames(It.IsAny<short>())).Returns("non-edmx-file.xmde");

            // need to pass a transformer since there must be at least onve converter or transformer
            // and the test tests a case where converter does not exist
            var mockTransformExtension = new Mock<IModelTransformExtension>();
            var transformer = new Lazy<IModelTransformExtension>(() => mockTransformExtension.Object);

            string outputDocument;
            List<ExtensionError> errors;

            Assert.Equal(
                Resources.Extensibility_NoConverterForExtension,
                Assert.Throws<InvalidOperationException>(
                    () => StandaloneXmlModelProvider.TryGetBufferViaExtensions(
                        mockDte.ServiceProvider, mockProjectItem.Object, "<root/>",
                        new Lazy<IModelConversionExtension, IEntityDesignerConversionData>[0],
                        new[] { transformer }, out outputDocument, out errors)).Message);
        }
Ejemplo n.º 20
0
        public void DetermineIfArtifactIsVersionSafe_sets_IsVersionSafe_to_true_for_Misc_project()
        {
            var mockDte = new MockDTE(
                ".NETFramework, Version=v4.5.1",
                Constants.vsMiscFilesProjectUniqueName);

            var modelManager = new Mock<ModelManager>(null, null).Object;
            var modelProvider = new Mock<XmlModelProvider>().Object;
            var mockVsArtifact =
                new Mock<VSArtifact>(modelManager, new Uri("urn:dummy"), modelProvider) { CallBase = true };
            mockVsArtifact.Protected().Setup<IServiceProvider>("ServiceProvider").Returns(mockDte.ServiceProvider);
            mockVsArtifact.Protected().Setup<Project>("GetProject").Returns(mockDte.Project);
            mockVsArtifact.Setup(a => a.XDocument).Returns(
                new XDocument(
                    new XElement(
                        XName.Get(
                            "Edmx",
                            SchemaManager.GetEDMXNamespaceName(EntityFrameworkVersion.Version3)))));

            var artifact = mockVsArtifact.Object;
            artifact.DetermineIfArtifactIsVersionSafe();
            Assert.True(artifact.IsVersionSafe);
        }
Ejemplo n.º 21
0
            DetermineIfArtifactIsVersionSafe_sets_IsVersionSafe_to_true_if_schema_is_the_latest_version_supported_by_referenced_runtime()
        {
            var mockDte = new MockDTE(
                ".NETFramework, Version=v4.5.1",
                references: new[] { MockDTE.CreateReference("EntityFramework", "6.0.0.0") });

            var modelManager = new Mock<ModelManager>(null, null).Object;
            var modelProvider = new Mock<XmlModelProvider>().Object;
            var mockVsArtifact =
                new Mock<VSArtifact>(modelManager, new Uri("urn:dummy"), modelProvider) { CallBase = true };
            mockVsArtifact.Protected().Setup<IServiceProvider>("ServiceProvider").Returns(mockDte.ServiceProvider);
            mockVsArtifact.Protected().Setup<Project>("GetProject").Returns(mockDte.Project);
            mockVsArtifact.Setup(a => a.XDocument).Returns(
                new XDocument(
                    new XElement(
                        XName.Get(
                            "Edmx",
                            SchemaManager.GetEDMXNamespaceName(EntityFrameworkVersion.Version3)))));

            var artifact = mockVsArtifact.Object;

            artifact.DetermineIfArtifactIsVersionSafe();
            Assert.True(artifact.IsVersionSafe);
        }
Ejemplo n.º 22
0
        public void GetTypeFromProject_uses_dynamic_type_service()
        {
            var dte = new MockDTE(".NETFramework,Version=v4.5");

            var typeResolutionService = new Mock<ITypeResolutionService>();
            var dynamicTypeService = new Mock<DynamicTypeService>(MockBehavior.Strict);
            dynamicTypeService.Setup(s => s.GetTypeResolutionService(It.IsAny<IVsHierarchy>(), It.IsAny<uint>()))
                .Returns(typeResolutionService.Object);
            var serviceProvider = Mock.Get(dte.ServiceProvider);
            serviceProvider.Setup(p => p.GetService(typeof(DynamicTypeService))).Returns(dynamicTypeService.Object);

            VsUtils.GetTypeFromProject("Some.Type", dte.Project, dte.ServiceProvider);

            dynamicTypeService.Verify(s => s.GetTypeResolutionService(dte.Hierarchy, It.IsAny<uint>()));
            typeResolutionService.Verify(s => s.GetType("Some.Type"));
        }
Ejemplo n.º 23
0
        public void SchemaVersionSupportedInProject_returns_true_for_v3_and_EF6_otherwise_false()
        {
            var targetNetFrameworkVersions =
                new[] { ".NETFramework, Version=v4.0", ".NETFramework, Version=v4.5" };

            foreach (var targetNetFrameworkVersion in targetNetFrameworkVersions)
            {
                var mockDte =
                    new MockDTE(
                        targetNetFrameworkVersion,
                        references: new[] { MockDTE.CreateReference("EntityFramework", "6.0.0.0") });

                Assert.False(
                    VsUtils.SchemaVersionSupportedInProject(
                        mockDte.Project, EntityFrameworkVersion.Version1, mockDte.ServiceProvider));

                Assert.False(
                    VsUtils.SchemaVersionSupportedInProject(
                        mockDte.Project, EntityFrameworkVersion.Version2, mockDte.ServiceProvider));

                Assert.True(
                    VsUtils.SchemaVersionSupportedInProject(
                        mockDte.Project, EntityFrameworkVersion.Version3, mockDte.ServiceProvider));
            }
        }
Ejemplo n.º 24
0
        public void SchemaVersionSupportedInProject_returns_true_for_v3_and_EF5_on_NetFramework_4_5_otherwise_false()
        {
            var mockDte =
                new MockDTE(
                    ".NETFramework, Version=v4.5",
                    references: new[] { MockDTE.CreateReference("System.Data.Entity", "4.0.0.0") });

            Assert.False(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version1, mockDte.ServiceProvider));

            Assert.False(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version2, mockDte.ServiceProvider));

            Assert.True(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version3, mockDte.ServiceProvider));
        }
Ejemplo n.º 25
0
        public void SchemaVersionSupportedInProject_returns_true_for_v2_and_v3_if_EF4_and_EF6_present()
        {
            var mockDte =
                new MockDTE(
                    ".NETFramework, Version=v4.0",
                    references:
                        new[]
                            {
                                MockDTE.CreateReference("System.Data.Entity", "4.0.0.0"),
                                MockDTE.CreateReference("EntityFramework", "6.0.0.0")
                            });

            Assert.False(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version1, mockDte.ServiceProvider));

            Assert.True(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version2, mockDte.ServiceProvider));

            Assert.True(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version3, mockDte.ServiceProvider));
        }
Ejemplo n.º 26
0
            SchemaVersionSupportedInProject_returns_true_for_v3_and_NetFramework_4_5_if_EF_not_referenced_otherwise_false()
        {
            var mockDte =
                new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

            Assert.False(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version1, mockDte.ServiceProvider));

            Assert.False(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version2, mockDte.ServiceProvider));

            Assert.True(
                VsUtils.SchemaVersionSupportedInProject(
                    mockDte.Project, EntityFrameworkVersion.Version3, mockDte.ServiceProvider));
        }
Ejemplo n.º 27
0
        public void EntityFrameworkSupportedInProject_returns_false_for_project_where_EF_cannot_be_used()
        {
            var targets =
                new[]
                    {
                        ".NETFramework,Version=v3.0",
                        ".NETFramework,Version=v2.0",
                        ".XBox,Version=v4.5",
                        string.Empty,
                        null
                    };

            foreach (var target in targets)
            {
                var monikerHelper = new MockDTE(target);

                Assert.False(
                    VsUtils.EntityFrameworkSupportedInProject(monikerHelper.Project, monikerHelper.ServiceProvider, allowMiscProject: true));
                Assert.False(
                    VsUtils.EntityFrameworkSupportedInProject(monikerHelper.Project, monikerHelper.ServiceProvider, allowMiscProject: false));
            }
        }
Ejemplo n.º 28
0
        public void EntityFrameworkSupportedInProject_returns_false_for_Misc_project_if_not_allowed()
        {
            const string vsMiscFilesProjectUniqueName = "<MiscFiles>";

            var monikerHelper = new MockDTE("anytarget", vsMiscFilesProjectUniqueName);

            Assert.False(
                VsUtils.EntityFrameworkSupportedInProject(monikerHelper.Project, monikerHelper.ServiceProvider, allowMiscProject: false));
        }
Ejemplo n.º 29
0
        public void EntityFrameworkSupportedInProject_returns_true_for_applicable_projects()
        {
            var targets =
                new[]
                    {
                        ".NETFramework,Version=v4.0",
                        ".NETFramework,Version=v3.5",
                        ".NETFramework,Version=v4.5",
                    };

            foreach (var target in targets)
            {
                var monikerHelper = new MockDTE(target);

                Assert.True(
                    VsUtils.EntityFrameworkSupportedInProject(monikerHelper.Project, monikerHelper.ServiceProvider, allowMiscProject: true));
                Assert.True(
                    VsUtils.EntityFrameworkSupportedInProject(monikerHelper.Project, monikerHelper.ServiceProvider, allowMiscProject: false));
            }
        }
Ejemplo n.º 30
0
        public void GetMetadataFileNamesFromArtifactFileName_creates_metadata_file_names_for_null_edmx_ProjectItem()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);
            mockDte.SetProjectProperties(new Dictionary<string, object> { { "FullPath", @"C:\Projects\Project\Folder" } });
            
            var metadataFileNames =
                ConnectionManager.GetMetadataFileNamesFromArtifactFileName(
                mockDte.Project, @"c:\temp\myModel.edmx", mockDte.ServiceProvider, (_, __) => null);

            Assert.Equal(@".\..\..\..\temp\myModel.csdl", metadataFileNames[0]);
            Assert.Equal(@".\..\..\..\temp\myModel.ssdl", metadataFileNames[1]);
            Assert.Equal(@".\..\..\..\temp\myModel.msl", metadataFileNames[2]);
        }