Пример #1
0
        public void GetConnectionString_ShouldReplaceAllPlaceholders_WhenPlaceholdersExist()
        {
            // Arrange
            const string connectionName   = "DefaultConnection";
            const string expectedUsername = "******";
            const string expectedPassword = "******";

            var testConfigurationData = new Dictionary <string, string>
            {
                { "ConnectionStrings.DefaultConnection", "Data Source=some.server;Initial Catalog=MyDatabase;User ID={{DatabaseUsername}};Password={{DatabasePassword}};" },
                { "DatabaseUsername", expectedUsername },
                { "DatabasePassword", expectedPassword }
            };

            var testConfiguration = new TestConfiguration(testConfigurationData);

            var cut = new ConnectionStringByConfigurationProvider(testConfiguration);

            // Act
            string actual = cut.Get(connectionName);

            // Assert
            actual.ShouldNotContain("{{");
            actual.ShouldNotContain("}}");
        }
Пример #2
0
        public void GetConnectionString_ShouldNotThrowAnException_WhenNoPlaceholdersExist()
        {
            // Arrange
            const string connectionName   = "DefaultConnection";
            const string expectedUsername = "******";
            const string expectedPassword = "******";

            var testConfigurationData = new Dictionary <string, string>
            {
                { "ConnectionStrings.DefaultConnection", "Data Source=some.server;Initial Catalog=MyDatabase;User ID=NotAPlaceholder;Password=NotAPlaceholder;" },
                { "DatabaseUsername", expectedUsername },
                { "DatabasePassword", expectedPassword }
            };

            var testConfiguration = new TestConfiguration(testConfigurationData);

            var cut = new ConnectionStringByConfigurationProvider(testConfiguration);

            // Act
            cut.Get(connectionName);

            // Assert
            true.ShouldBe(true);
        }