Пример #1
0
        PostgreServer SetupPostgreServer(ErrorResultTO errors)
        {
            var server = new PostgreServer();

            try
            {
                var connected = server.Connect(Source.ConnectionString, CommandType.StoredProcedure, ProcedureName);
                if (!connected)
                {
                    Dev2Logger.Error(string.Format(ErrorResource.FailedToConnectWithConnectionString,
                                                   Source.ConnectionString), GlobalConstants.WarewolfError);
                }
                return(server);
            }
            catch (NpgsqlException ex)
            {
                var errorMessages = new StringBuilder();
                errorMessages.Append(ex.Message);
                errors.AddError(errorMessages.ToString());
                Dev2Logger.Error(errorMessages.ToString(), GlobalConstants.WarewolfError);
            }
            catch (Exception ex)
            {
                errors.AddError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                Dev2Logger.Error(ex, GlobalConstants.WarewolfError);
            }
            return(server);
        }
Пример #2
0
        public void PostgreServer_FetchDataTable_AddParams_VerifyAllAdded()

        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();



            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            var dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            var sqlServer = new PostgreServer(factory.Object);

            try
            {
                var pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                pvt.SetField("_command", mockCommand.Object);
                //------------Execute Test---------------------------
                var param = new IDbDataParameter[] { new SqlParameter("a", "a"), new SqlParameter("b", "b") };

                PostgreServer.AddParameters(mockCommand.Object, param);
                Assert.AreEqual(2, added.Count);


                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #3
0
        public void PostgreServer_FetchDatabases_ConnectionNotInitialized_ThrowsConnectFirstException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.FetchDatabases();

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #4
0
        public void PostgreServer_FetchDataTable_CommandIsNull_ThrowsArgumentNullException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.FetchDataTable(null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #5
0
        public void PostgreServer_Connect_ConnectionStringIsInvalid_ThrowsArgumentException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect("xxx", CommandType.Text, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #6
0
        // ReSharper disable InconsistentNaming
        public void PostgreServer_CreateCommand_ConnectionNotInitialized_ThrowsConnectFirstException()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.CreateCommand();

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #7
0
        // ReSharper disable InconsistentNaming
        public void PostgreServer_Connect_ConnectionStringIsNull_ThrowsArgumentNullException()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect(null, CommandType.Text, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #8
0
        public void PostgreServer_CreateCommand_CreateCommand()

        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            var dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            conn.Setup(a => a.ConnectionString).Returns("bob");
            conn.Setup(a => a.CreateCommand()).Returns(mockCommand.Object);
            factory.Setup(a => a.CreateConnection(It.IsAny <string>())).Returns(conn.Object);
            var sqlServer = new PostgreServer(factory.Object);

            try
            {
                var pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                //------------Execute Test---------------------------
                sqlServer.CreateCommand();
                conn.Verify(a => a.CreateCommand());
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #9
0
        public void PostgreServer_FetchStoredProcedures_FunctionProcessorIsNull_ThrowsArgumentNullException()

        {
            //------------Setup for test--------------------------
            var sqlServer = new PostgreServer();

            try
            {
                //------------Execute Test---------------------------
                Func <IDbCommand, List <IDbDataParameter>, string, string, bool> procProcessor = (command, list, arg3, a) => false;

                sqlServer.FetchStoredProcedures(procProcessor, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #10
0
        // ReSharper disable InconsistentNaming
        public void PostgreServer_FetchDataTable_ConnectionsString()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            DataTable dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            conn.Setup(a => a.ConnectionString).Returns("bob");
            var sqlServer = new PostgreServer(factory.Object);

            try
            {
                PrivateObject pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                pvt.SetField("_command", mockCommand.Object);
                //------------Execute Test---------------------------

                Assert.AreEqual("bob", sqlServer.ConnectionString);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
Пример #11
0
        public void PostgreServer_FetchDataTable_ConnectionsStringNull()

        {
            //------------Setup for test--------------------------
            var factory     = new Mock <IDbFactory>();
            var mockCommand = new Mock <IDbCommand>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var added = new SqlCommand().Parameters;

            mockCommand.Setup(a => a.Parameters).Returns(added);
            var helpTextCommand = new Mock <IDbCommand>();

            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny <CommandBehavior>())).Returns(new Mock <IDataReader>().Object);
            var dt = new DataTable();

            dt.Columns.Add("database_name");
            dt.Rows.Add(new object[] { "Bob" });
            dt.Rows.Add(new object[] { "Dave" });
            factory.Setup(a => a.GetSchema(It.IsAny <IDbConnection>(), "Databases")).Returns(dt);
            var conn = new Mock <IDbConnection>();

            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            conn.Setup(a => a.ConnectionString).Returns("bob");
            var sqlServer = new PostgreServer(factory.Object);

            try
            {
                Assert.IsNull(sqlServer.ConnectionString);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }