public void SetupTable_Compare_TwoSetupTables_WithDifferentSyncDirection_ShouldBe_Different()
        {
            SetupTable table1 = new SetupTable("Customer");
            SetupTable table2 = new SetupTable("Customer");

            table1.SyncDirection = SyncDirection.UploadOnly;
            table2.SyncDirection = SyncDirection.Bidirectional;

            Assert.NotEqual(table1, table2);
            Assert.False(table1.Equals(table2));
        }
        public void SetupTable_Compare_TwoSetupTables_WithSameColumns_ShouldBe_Equals()
        {
            SetupTable table1 = new SetupTable("Customer");
            SetupTable table2 = new SetupTable("Customer");

            table1.Columns.Add("CustomerID");
            table2.Columns.Add("CustomerID");

            Assert.Equal(table1, table2);
            Assert.True(table1.Equals(table2));
        }
        public void SetupTable_Compare_TwoSetupTables_WithSameSyncDirection_ShouldBe_Equals()
        {
            SetupTable table1 = new SetupTable("Customer");
            SetupTable table2 = new SetupTable("Customer");

            table1.SyncDirection = SyncDirection.Bidirectional;
            table2.SyncDirection = SyncDirection.Bidirectional;

            Assert.Equal(table1, table2);
            Assert.True(table1.Equals(table2));
        }
        public void SetupTable_Compare_TwoSetupTables_ShouldBe_Different()
        {
            SetupTable table1 = new SetupTable("Customer1");
            SetupTable table2 = new SetupTable("Customer2");

            Assert.NotEqual(table1, table2);
            Assert.False(table1.Equals(table2));

            SetupTable table3 = new SetupTable("ProductCategory", "dbo");
            SetupTable table4 = new SetupTable("ProductCategory", "SalesLT");

            Assert.NotEqual(table3, table4);
            Assert.False(table3.Equals(table4));
        }
        public void SetupTable_Compare_TwoSetupTables_ShouldBe_Equals()
        {
            SetupTable table1 = new SetupTable("Customer");
            SetupTable table2 = new SetupTable("Customer");

            Assert.Equal(table1, table2);
            Assert.True(table1.Equals(table2));

            SetupTable table3 = new SetupTable("ProductCategory", "SalesLT");
            SetupTable table4 = new SetupTable("ProductCategory", "SalesLT");

            Assert.Equal(table3, table4);
            Assert.True(table3.Equals(table4));
        }
        /// <summary>
        /// Get all Tables
        /// </summary>
        public static async Task <SyncSetup> GetAllTablesAsync(SqlConnection connection, SqlTransaction transaction)
        {
            var command = $"Select tbl.name as TableName, " +
                          $"sch.name as SchemaName " +
                          $"  from sys.tables as tbl  " +
                          $"  Inner join sys.schemas as sch on tbl.schema_id = sch.schema_id;";

            var syncSetup = new SyncSetup();

            using (var sqlCommand = new SqlCommand(command, connection))
            {
                bool alreadyOpened = connection.State == ConnectionState.Open;

                if (!alreadyOpened)
                {
                    await connection.OpenAsync().ConfigureAwait(false);
                }

                sqlCommand.Transaction = transaction;

                using (var reader = await sqlCommand.ExecuteReaderAsync().ConfigureAwait(false))
                {
                    while (reader.Read())
                    {
                        var tableName  = reader.GetString(0);
                        var schemaName = reader.GetString(1);
                        var setupTable = new SetupTable(tableName, schemaName);
                        syncSetup.Tables.Add(setupTable);
                    }
                }

                foreach (var setupTable in syncSetup.Tables)
                {
                    var syncTableColumnsList = await GetColumnsForTableAsync(connection, transaction, setupTable.TableName, setupTable.SchemaName).ConfigureAwait(false);

                    foreach (var column in syncTableColumnsList.Rows)
                    {
                        setupTable.Columns.Add(column["name"].ToString());
                    }
                }


                if (!alreadyOpened)
                {
                    connection.Close();
                }
            }
            return(syncSetup);
        }
        public void SetupTable_Compare_TwoSetupTables_WithDifferentColumns_ShouldBe_Equals()
        {
            SetupTable table1 = new SetupTable("Customer");
            SetupTable table2 = new SetupTable("Customer");

            table1.Columns.Add("CustomerID");

            Assert.NotEqual(table1, table2);
            Assert.False(table1.Equals(table2));

            table2.Columns.Add("ID");

            Assert.NotEqual(table1, table2);
            Assert.False(table1.Equals(table2));
        }
 public ServiceConsoleState()
 {
     Main            = new MainTable();
     Setup           = new SetupTable();
     InterlockTrig   = new InterlockTrigTable();
     Interlocks      = new InterlockTable();
     Modes           = new ModeTable();
     TreatmentModes  = new TreatmentModeTable();
     Energies        = new EnergyTable();
     RepRates        = new RepRateTable(Energies);
     Accessories     = new AccessoryTable();
     Cones           = new ConeTable();
     Motor           = new MotorTable();
     GantryAutomatic = new GantryAutomaticTable();
     CouchAutomatic  = new CouchAutomaticTable();
 }
        /// <summary>
        /// Get all Tables
        /// </summary>
        public static async Task <SyncSetup> GetAllTablesAsync(MySqlConnection connection, MySqlTransaction transaction)
        {
            var command = $"select TABLE_NAME from information_schema.TABLES where table_schema = schema()";

            var syncSetup = new SyncSetup();

            using (var mySqlCommand = new MySqlCommand(command, connection))
            {
                bool alreadyOpened = connection.State == ConnectionState.Open;

                if (!alreadyOpened)
                {
                    await connection.OpenAsync().ConfigureAwait(false);
                }

                mySqlCommand.Transaction = transaction;

                using (var reader = await mySqlCommand.ExecuteReaderAsync().ConfigureAwait(false))
                {
                    while (reader.Read())
                    {
                        var tableName  = reader.GetString(0);
                        var setupTable = new SetupTable(tableName);
                        syncSetup.Tables.Add(setupTable);
                    }
                }

                foreach (var setupTable in syncSetup.Tables)
                {
                    var syncTableColumnsList = await GetColumnsForTableAsync(connection, transaction, setupTable.TableName).ConfigureAwait(false);

                    foreach (var column in syncTableColumnsList.Rows)
                    {
                        setupTable.Columns.Add(column["column_name"].ToString());
                    }
                }

                if (!alreadyOpened)
                {
                    connection.Close();
                }
            }
            return(syncSetup);
        }
        /// <summary>
        /// Get all Tables
        /// </summary>
        public static async Task <SyncSetup> GetAllTablesAsync(SqliteConnection connection, SqliteTransaction transaction)
        {
            var command = $"select tbl_name from sqlite_master where type='table';";

            var syncSetup = new SyncSetup();

            using (var sqlCommand = new SqliteCommand(command, connection))
            {
                bool alreadyOpened = connection.State == ConnectionState.Open;

                if (!alreadyOpened)
                {
                    await connection.OpenAsync().ConfigureAwait(false);
                }

                sqlCommand.Transaction = transaction;

                using (var reader = await sqlCommand.ExecuteReaderAsync().ConfigureAwait(false))
                {
                    while (reader.Read())
                    {
                        var tableName  = reader.GetString(0);
                        var setupTable = new SetupTable(tableName);
                        syncSetup.Tables.Add(setupTable);
                    }
                }

                foreach (var setupTable in syncSetup.Tables)
                {
                    var syncTableColumnsList = await GetColumnsForTableAsync(connection, transaction, setupTable.TableName).ConfigureAwait(false);

                    foreach (var column in syncTableColumnsList.Rows)
                    {
                        setupTable.Columns.Add(column["name"].ToString());
                    }
                }

                if (!alreadyOpened)
                {
                    connection.Close();
                }
            }
            return(syncSetup);
        }