Esempio n. 1
0
        public void listViewModelContents_DoubleClick_calls_OnFinish_if_EmptyModelCodeFirst_selected_and_EF_not_referenced_or_EF6_referenced()
        {
            var mockDtes = new[]
            {
                new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]),
                new MockDTE(".NETFramework, Version=v4.5",
                            references: new[] { MockDTE.CreateReference("EntityFramework", "6.0.0.0") })
            };

            foreach (var mockDte in mockDtes)
            {
                var mockWizard =
                    Mock.Get(
                        ModelBuilderWizardFormHelper.CreateWizard(
                            ModelGenerationOption.EmptyModelCodeFirst,
                            mockDte.Project,
                            serviceProvider: mockDte.ServiceProvider));

                var mockWizardPageStart =
                    CreateMockWizardPageStart(mockWizard.Object, WizardPageStart.GenerateEmptyModelCodeFirstIndex);

                mockWizard.Setup(w => w.OnFinish());

                mockWizardPageStart.Object.listViewModelContents_DoubleClick(sender: null, e: null);

                mockWizard.Verify(w => w.OnFinish(), Times.Once());
            }
        }
Esempio n. 2
0
        public void OnDeactivate_does_not_update_settings_if_model_file_already_exists()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

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

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

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

            mockWizardPageStart.Object.OnDeactivate();

            Assert.Null(modelBuilderSettings.ModelPath);
            Assert.True(wizard.FileAlreadyExistsError);
        }
Esempio n. 3
0
        public void OnDeactivate_generates_model()
        {
            var mockModelBuilderEngine =
                new Mock <EdmxModelBuilderEngine>(Mock.Of <IInitialModelContentsFactory>());

            var mockSettings = new Mock <ModelBuilderSettings> {
                CallBase = true
            };

            mockSettings.Setup(s => s.DesignTimeConnectionString).Returns("fakeConnString");
            mockSettings.Object.ModelBuilderEngine = mockModelBuilderEngine.Object;
            mockSettings.Object.Project            = Mock.Of <Project>();

            var mockWizardPageBase = new Mock <WizardPageBase>(
                ModelBuilderWizardFormHelper.CreateWizard(mockSettings.Object))
            {
                CallBase = true
            };

            mockWizardPageBase.Setup(p => p.MovingNext).Returns(true);

            mockWizardPageBase.Object.OnDeactivate();

            mockModelBuilderEngine
            .Verify(m => m.GenerateModel(It.IsAny <ModelBuilderSettings>(),
                                         It.IsAny <IVsUtils>(), It.IsAny <ModelBuilderEngineHostContext>()), Times.Once());
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
        public void OnActivate_result_depends_on_FileAlreadyExistsError()
        {
            var wizard             = ModelBuilderWizardFormHelper.CreateWizard();
            var wizardPageDbConfig = new WizardPageDbConfig(wizard);

            wizard.FileAlreadyExistsError = true;
            Assert.False(wizardPageDbConfig.OnActivate());

            wizard.FileAlreadyExistsError = false;
            Assert.True(wizardPageDbConfig.OnActivate());
        }
Esempio n. 6
0
        public void GetTextBoxConnectionStringValue_returns_regular_connection_string_for_CodeFirst_from_Database()
        {
            var guid = new Guid("42424242-4242-4242-4242-424242424242");
            var wizardPageDbConfig = new WizardPageDbConfig(
                ModelBuilderWizardFormHelper.CreateWizard(ModelGenerationOption.CodeFirstFromDatabase));

            Assert.Equal(
                "integrated security=SSPI;MultipleActiveResultSets=True;App=EntityFramework",
                wizardPageDbConfig.GetTextBoxConnectionStringValue(
                    CreateDataProviderManager(guid),
                    guid,
                    "Integrated Security=SSPI"));
        }
Esempio n. 7
0
        public void OnActivate_result_depends_on_FileAlreadyExistsError()
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

            var wizard =
                ModelBuilderWizardFormHelper.CreateWizard(project: mockDte.Project, serviceProvider: mockDte.ServiceProvider);
            var wizardPageStart = new WizardPageStart(wizard);

            wizard.FileAlreadyExistsError = true;
            Assert.False(wizardPageStart.OnActivate());

            wizard.FileAlreadyExistsError = false;
            Assert.True(wizardPageStart.OnActivate());
        }
Esempio n. 8
0
        private static ModelBuilderWizardForm CreateModelBuilderWizardForm(ModelGenerationOption modelGenerationOption)
        {
            var mockDte = new MockDTE(".NETFramework, Version=v4.5", references: new Reference[0]);

            var modelBuilderSettings = new ModelBuilderSettings
            {
                NewItemFolder         = @"C:\temp",
                ModelName             = "myModel",
                ReplacementDictionary = new Dictionary <string, string>(),
                TargetSchemaVersion   = EntityFrameworkVersion.Version3,
                VsTemplatePath        = "fake.vstemplate",
                Project          = mockDte.Project,
                GenerationOption = modelGenerationOption
            };

            var wizard = ModelBuilderWizardFormHelper.CreateWizard(modelBuilderSettings, mockDte.ServiceProvider);

            return(wizard);
        }
Esempio n. 9
0
        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);
        }