public void AddOrUpdateConfigSection_when_using_NET4_EF_assembly_updates_EF_section_if_configSections_element_is_too_new()
        {
            var config = CreateConfigSectionDoc(_net45EntityFrameworkSectionName);

            var sectionModified = new ConfigFileManipulator().AddOrUpdateConfigSection(config, _net40EntityFrameworkVersion);

            Assert.True(sectionModified);
            Assert.Equal(_net40EntityFrameworkSectionName, GetEfSectionName(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 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 ConfigFileManipulator().AddConnectionFactoryToConfig(config, new ConnectionFactorySpecification(ConnectionFactorySpecification.SqlConnectionFactoryName, "SomeConnectionString"));

                    Assert.True(modified);

                    Assert.Equal(ConnectionFactorySpecification.SqlConnectionFactoryName, GetFactoryName(config));
                    Assert.Equal("SomeConnectionString", GetArgument(config));
                });

                Assert.Equal(1, configFilesFound.Count);
                Assert.Equal("App.config", configFilesFound.Single());
            });
        }
        public void AddOrUpdateConfigSection_adds_EF_section_if_configSections_element_has_no_entityFramework_entry()
        {
            var config = CreateConfigSectionDoc(assemblyName: null);

            var sectionModified = new ConfigFileManipulator().AddOrUpdateConfigSection(config, _net45EntityFrameworkVersion);

            Assert.True(sectionModified);
            Assert.Equal(_net45EntityFrameworkSectionName, GetEfSectionName(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 ConfigFileManipulator().AddOrUpdateConfigSection(config, _net40EntityFrameworkVersion);

            Assert.False(sectionModified);
            Assert.Equal(_net40EntityFrameworkSectionName, GetEfSectionName(config));
        }
        public void AddOrUpdateConfigSection_adds_EF_section_if_configuration_element_is_missing()
        {
            var config = new XDocument();

            var sectionModified = new ConfigFileManipulator().AddOrUpdateConfigSection(config, _net45EntityFrameworkVersion);

            Assert.True(sectionModified);
            Assert.Equal(_net45EntityFrameworkSectionName, GetEfSectionName(config));
        }
        public void AddOrUpdateConfigSection_adds_EF_section_if_configSections_element_contains_no_entries()
        {
            var config =
                new XDocument(new XElement(ConfigFileManipulator.ConfigurationElementName,
                                           new XElement(ConfigFileManipulator.ConfigSectionsElementName)));

            var sectionModified = new 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 ConfigFileManipulator().AddConnectionFactoryToConfig(config, new ConnectionFactorySpecification("NewConnectionFactory"));

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

            Assert.Null(config.Element(ConfigFileManipulator.ConfigurationElementName)
                            .Element(ConfigFileManipulator.EntityFrameworkElementName)
                            .Element(ConfigFileManipulator.DefaultConnectionFactoryElementName)
                            .Element(ConfigFileManipulator.ParametersElementName));
        }
        public void AddConnectionFactoryToConfig_adds_factory_with_many_parameters()
        {
            var config = new XDocument();

            var factoryAdded = new ConfigFileManipulator().AddConnectionFactoryToConfig(config, new 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 ConfigFileManipulator().AddConnectionFactoryToConfig(config, new 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 ConfigFileManipulator().AddConnectionFactoryToConfig(config, new 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 ConfigFileManipulator().AddConnectionFactoryToConfig(config, new 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(ConnectionFactorySpecification.SqlConnectionFactoryName, "Database=Bob");

            var factoryAdded = new ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                config,
                new ConnectionFactorySpecification(
                    ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                    ConnectionFactorySpecification.SqlCompactProviderName));

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

            var factoryAdded = new ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                config,
                new ConnectionFactorySpecification(
                    ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                    ConnectionFactorySpecification.SqlCompactProviderName));

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

            var factoryAdded = new ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                config,
                new ConnectionFactorySpecification(
                    ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                    ConnectionFactorySpecification.SqlCompactProviderName));

            Assert.True(factoryAdded);
            Assert.Equal(ConnectionFactorySpecification.SqlCeConnectionFactoryName, GetFactoryName(config));
            Assert.Equal(ConnectionFactorySpecification.SqlCompactProviderName, GetArgument(config));
        }
        public void AddSqlCompactConnectionFactoryToConfig_does_nothing_if_correct_SQL_Compact_entry_already_exists()
        {
            var config = CreateConnectionFactoryConfigDoc(ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                                                          ConnectionFactorySpecification.SqlCompactProviderName);

            var factoryAdded = new ConfigFileManipulator()
                .AddOrUpdateConnectionFactoryInConfig(
                config,
                new ConnectionFactorySpecification(
                    ConnectionFactorySpecification.SqlCeConnectionFactoryName,
                    ConnectionFactorySpecification.SqlCompactProviderName));

            Assert.False(factoryAdded);
            Assert.Equal(ConnectionFactorySpecification.SqlCeConnectionFactoryName, GetFactoryName(config));
            Assert.Equal(ConnectionFactorySpecification.SqlCompactProviderName, GetArgument(config));
        }