Esempio n. 1
0
        public void Should_return_true_if_type_to_verify_is_as_the_one_expected()
        {
            var type = new SqlServerConnectionstringArguments();

            var result = type.IsA<SqlServerConnectionstringArguments>();

            Assert.IsTrue(result);
        }
        public void Should_throw_an_exception_if_password_is_null_or_empty_and_username_is_not_null_or_empty()
        {
            var connectionstringArguments = new SqlServerConnectionstringArguments
            {
                DataSource   = "DataSource",
                DatabaseName = "DatabaseName",
                Password     = "",
                Provider     = "Provider",
                Username     = "******"
            };

            _connectionstringArgumentsValidator.Validate(connectionstringArguments);
        }
        public void Should_return_true_if_username_and_password_are_null_or_empty()
        {
            var connectionstringArguments = new SqlServerConnectionstringArguments
            {
                DataSource   = "DataSource",
                DatabaseName = "DatabaseName",
                Provider     = "Provider",
            };

            var isValid = _connectionstringArgumentsValidator.Validate(connectionstringArguments);

            Assert.IsTrue(isValid);
        }
        public void Should_be_able_to_build_a_sqlserver_connectionstring_whith_integrated_security()
        {
            var connectionstringArguments = new SqlServerConnectionstringArguments
            {
                DataSource   = "TestDatabase",
                DatabaseName = "Test",
                Provider     = "SQLOLEDB"
            };

            var connectionstring = _connectionstringBuilderStrategy.BuildConnectionstring(connectionstringArguments);

            Assert.AreEqual("Provider=SQLOLEDB;Data Source=TestDatabase;Initial Catalog=Test;Integrated Security=SSPI;OLE DB Services=-4;", connectionstring);
        }
        private static string BuildConnectionString(SqlServerConnectionstringArguments arguments)
        {
            string connectionString;

            if (string.IsNullOrEmpty(arguments.Username) && string.IsNullOrEmpty(arguments.Password))
            {
                connectionString = string.Format("Provider={0};Data Source={1};Initial Catalog={2};Integrated Security=SSPI;OLE DB Services=-4;", arguments.Provider, arguments.DataSource, arguments.DatabaseName);
            }
            else
            {
                connectionString = string.Format("Provider={0};Data Source={1};Initial Catalog={2};User ID={3};Password={4};OLE DB Services=-4;", arguments.Provider, arguments.DataSource, arguments.DatabaseName, arguments.Username, arguments.Password);
            }
            return connectionString;
        }
        public void Should_be_able_to_build_a_connection_string_for_sqlserver_databases()
        {
            var connectionstringArguments = new SqlServerConnectionstringArguments
            {
                Provider     = "SQLOLEDB",
                DataSource   = "localhost",
                DatabaseName = "TestDatabase",
                Password     = "******",
                Username     = "******"
            };

            var connectionstring = _connectionstringFactory.BuildConnection(connectionstringArguments);

            Assert.AreEqual("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=TestDatabase;User ID=username;Password=password;OLE DB Services=-4;", connectionstring);
        }
        public void Should_be_able_to_build_a_sqlserver_connectionstring_when_username_and_password_are_specified()
        {
            var connectionstringArguments = new SqlServerConnectionstringArguments
            {
                DataSource = "TestDatabase",
                DatabaseName = "Test",
                Provider = "SQLOLEDB",
                Username = "******",
                Password = "******"
            };

            var connectionstring = _connectionstringBuilderStrategy.BuildConnectionstring(connectionstringArguments);

            Assert.AreEqual("Provider=SQLOLEDB;Data Source=TestDatabase;Initial Catalog=Test;User ID=Username;Password=Password;OLE DB Services=-4;", connectionstring);
        }