public void AddSqlCompactConnectionFactoryToConfig_does_nothing_if_correct_SQL_Compact_entry_already_exists()
        {
            var config = CreateConnectionFactoryConfigDoc(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName);

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName));

            Assert.False(factoryAdded);
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                GetFactoryName(config));
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName,
                GetArgument(config));
        }
        public void AddOrUpdateConfigSection_when_using_NET4_EF_assembly_does_nothing_if_EF_assembly_name_is_up_to_date()
        {
            var config = CreateConfigSectionDoc(_net40EntityFrameworkSectionName, addRequirePermission: true);

            var sectionModified =
                new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().AddOrUpdateConfigSection(
                    config, _net40EntityFrameworkVersion);

            Assert.False(sectionModified);
            Assert.Equal(_net40EntityFrameworkSectionName, GetEfSectionName(config));
        }
        public void AddOrUpdateConfigSection_when_using_NET4_EF_assembly_updates_EF_section_if_configSections_element_is_too_new()
        {
            var config = CreateConfigSectionDoc(_net45EntityFrameworkSectionName);

            var sectionModified =
                new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().AddOrUpdateConfigSection(
                    config, _net40EntityFrameworkVersion);

            Assert.True(sectionModified);
            Assert.Equal(_net40EntityFrameworkSectionName, GetEfSectionName(config));
        }
        public void AddOrUpdateConfigSection_adds_EF_section_if_configSections_element_contains_no_entries()
        {
            var config =
                new XDocument(
                    new XElement(
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.ConfigurationElementName,
                        new XElement(powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.ConfigSectionsElementName)));

            var sectionModified =
                new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().AddOrUpdateConfigSection(
                    config, _net45EntityFrameworkVersion);

            Assert.True(sectionModified);
            Assert.Equal(_net45EntityFrameworkSectionName, GetEfSectionName(config));
        }
        public void AddOrUpdateConfigSection_adds_EF_section_if_configSections_element_has_no_entityFramework_entry()
        {
            var config = CreateConfigSectionDoc(assemblyName: null);

            var sectionModified =
                new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().AddOrUpdateConfigSection(
                    config, _net45EntityFrameworkVersion);

            Assert.True(sectionModified);
            Assert.Equal(_net45EntityFrameworkSectionName, GetEfSectionName(config));
        }
        public void AddConnectionFactoryToConfig_adds_factory_with_no_parameters()
        {
            var config = new XDocument();

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().
                AddConnectionFactoryToConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification("NewConnectionFactory"));

            Assert.True(factoryAdded);
            Assert.Equal("NewConnectionFactory", GetFactoryName(config));

            Assert.Null(
                config.Element(powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.ConfigurationElementName)
                    .Element(powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.EntityFrameworkElementName)
                    .Element(
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.DefaultConnectionFactoryElementName)
                    .Element(powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.ParametersElementName));
        }
        public void AddConnectionFactoryToConfig_adds_factory_with_many_parameters()
        {
            var config = new XDocument();

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().
                AddConnectionFactoryToConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        "NewConnectionFactory", "1", "2", "3"));

            Assert.True(factoryAdded);
            Assert.Equal("NewConnectionFactory", GetFactoryName(config));
            Assert.Equal("1", GetArguments(config).First());
            Assert.Equal("2", GetArguments(config).Skip(1).First());
            Assert.Equal("3", GetArguments(config).Skip(2).First());
        }
        public void AddConnectionFactoryToConfig_adds_factory_if_no_factory_name_already_exists()
        {
            var config = CreateConnectionFactoryConfigDoc(null);

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().
                AddConnectionFactoryToConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        "NewConnectionFactory", "NewBaseConnectionString"));

            Assert.True(factoryAdded);
            Assert.Equal("NewConnectionFactory", GetFactoryName(config));
            Assert.Equal("NewBaseConnectionString", GetArgument(config));
        }
        public void AddConnectionFactoryToConfig_adds_factory_if_configuration_element_is_missing()
        {
            var config = new XDocument();

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().
                AddConnectionFactoryToConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        "NewConnectionFactory", "NewBaseConnectionString"));

            Assert.True(factoryAdded);
            Assert.Equal("NewConnectionFactory", GetFactoryName(config));
            Assert.Equal("NewBaseConnectionString", GetArgument(config));
        }
        public void AddConnectionFactoryToConfig_does_nothing_if_factory_name_already_exists()
        {
            var config = CreateConnectionFactoryConfigDoc("SomeConnectionFactory");

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator().
                AddConnectionFactoryToConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        "NewConnectionFactory", "NewBaseConnectionString"));

            Assert.False(factoryAdded);
            Assert.Equal("SomeConnectionFactory", GetFactoryName(config));
        }
        public void AddSqlCompactConnectionFactoryToConfig_sets_factory_to_SQL_Compact_even_if_entry_with_param_already_exists()
        {
            var config =
                CreateConnectionFactoryConfigDoc(
                    powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlConnectionFactoryName,
                    "Database=Bob");

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName));

            Assert.True(factoryAdded);
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                GetFactoryName(config));
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName,
                GetArgument(config));
        }
        public void AddSqlCompactConnectionFactoryToConfig_adds_factory_if_configuration_element_is_missing()
        {
            var config = new XDocument();

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName));

            Assert.True(factoryAdded);
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                GetFactoryName(config));
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName,
                GetArgument(config));
        }
        public void AddSqlCompactConnectionFactoryToConfig_adds_factory_if_no_factory_name_already_exists()
        {
            var config = CreateConnectionFactoryConfigDoc(null);

            var factoryAdded = new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                    config,
                    new powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification(
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                        powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName));

            Assert.True(factoryAdded);
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                GetFactoryName(config));
            Assert.Equal(
                powershell::System.Data.Entity.ConnectionFactoryConfig.ConnectionFactorySpecification.SqlCompactProviderName,
                GetArgument(config));
        }
        public void Default_connection_factory_is_added_to_real_Visual_Studio_project_and_config_file()
        {
            var configFilesFound = new List<string>();

            Run_Project_test_if_Visual_Studio_is_running(
                p =>
                    {
                        new powershell::System.Data.Entity.ConnectionFactoryConfig.ConfigFileFinder().FindConfigFiles(
                            p.ProjectItems, i =>
                                                {
                                                    configFilesFound.Add(i.Name);

                                                    var config = XDocument.Load(i.FileNames[0]);

                                                    // Checked in app.config for unit tests has no connection factory, so one should be added
                                                    var modified = new powershell::System.Data.Entity.ConnectionFactoryConfig.
                                                        ConfigFileManipulator().AddConnectionFactoryToConfig(
                                                            config,
                                                            new powershell::System.Data.Entity.ConnectionFactoryConfig.
                                                                ConnectionFactorySpecification(
                                                                powershell::System.Data.Entity.ConnectionFactoryConfig.
                                                                    ConnectionFactorySpecification.SqlConnectionFactoryName,
                                                                "SomeConnectionString"));

                                                    Assert.True(modified);

                                                    Assert.Equal(
                                                        powershell::System.Data.Entity.ConnectionFactoryConfig.
                                                            ConnectionFactorySpecification.SqlConnectionFactoryName, GetFactoryName(config));
                                                    Assert.Equal("SomeConnectionString", GetArgument(config));
                                                });

                        Assert.Equal(1, configFilesFound.Count);
                        Assert.Equal("App.config", configFilesFound.Single());
                    });
        }