public void Create_ConnectionParamsIsNull_ReturnThrow(SqlConnectionStringBuilder parameter)
        {
            var    client = new SqlServerClient();
            Action action = () => client.Create(parameter).Should().BeFalse();

            action.Should()
            .Throw <Exception>()
            .WithMessage("Connection failed: Object reference not set to an instance of an object.");
        }
        public void ConnectToDB_SqlServer(string connectionName, SqlConnectionStringBuilder sqlConnectionString)
        {
            databaseController.Connections.Should().NotContainKey(connectionName, $"Connection \"{connectionName}\" already exists");
            var connection = new SqlServerClient();

            connection.Create(sqlConnectionString).Should().BeTrue();
            connection.IsConnectAlive().Should().BeTrue();
            databaseController.Connections.TryAdd(connectionName, (connection, TypeOfAccess.Local, sqlConnectionString.ConnectTimeout));
        }
Beispiel #3
0
        public void Create_CorrectConnectionParams_ReturnTrue()
        {
            var mockSqlProvider = new Mock <ISqlProvider>();

            var client = new SqlServerClient();

            mockSqlProvider.Setup(c => c.Create(It.IsAny <string>())).Returns(true);

            client._provider = mockSqlProvider.Object;
            client.Create(dbConnectionParams).Should().BeTrue();
        }
Beispiel #4
0
        public void ConnectToDB_SqlServer(string connectionName, DbConnectionParams connectionParams)
        {
            var(isValid, results) = Validate.ValidateModel(connectionParams);
            isValid.Should().BeTrue(Message.CreateMessage(results));

            databaseController.Connections.Should().NotContainKey(connectionName, $"Connection \"{connectionName}\" already exists");
            var connection = new SqlServerClient();

            connection.Create(connectionParams).Should().BeTrue();
            connection.IsConnectAlive().Should().BeTrue();
            databaseController.Connections.TryAdd(connectionName, (connection, connectionParams.Timeout));
        }
Beispiel #5
0
        public void Create_IncorrectConnectionParams_ReturnThrow()
        {
            var client = new SqlServerClient();

            Action action = () => client.Create(dbConnectionParams).Should().BeFalse();

            action.Should()
            .Throw <ConnectSqlException>()
            .Which.Message.Contains($"Connection failed. Connection with parameters: {Database.Helpers.Message.CreateMessage(dbConnectionParams)}");
            action.Should()
            .Throw <ConnectSqlException>()
            .WithMessage("*A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.*");
        }
Beispiel #6
0
        public void Create_IncorrectConnectionParams_ReturnThrow()
        {
            var mockSqlProvider = new Mock <ISqlProvider>();

            var client = new SqlServerClient();

            mockSqlProvider.Setup(c => c.Create(It.IsAny <string>())).Throws(new ConnectSqlException("test"));
            client._provider = mockSqlProvider.Object;

            Action action = () => client.Create(dbConnectionParams);

            action.Should()
            .Throw <ConnectSqlException>()
            .WithMessage("Connection failed. test");
        }
Beispiel #7
0
        public static void Before(VariableController variableController, DatabaseController databaseController)
        {
            var connectionsStringBuilder = new SqlConnectionStringBuilder
            {
                DataSource     = variableController.GetVariableValueText("SOURCE"),
                InitialCatalog = variableController.GetVariableValueText("DATABASE"),
                UserID         = variableController.GetVariableValueText("LOGIN"),
                Password       = variableController.GetVariableValueText("PASSWORD"),
                ConnectTimeout = 60
            };

            var connection = new SqlServerClient();

            connection.Create(connectionsStringBuilder);
            connection.IsConnectAlive();
            databaseController.Connections.TryAdd("QA", (connection, typeOfAccess: Molder.Infrastructures.TypeOfAccess.Global, connectionsStringBuilder.ConnectTimeout));
        }