Ejemplo n.º 1
0
        private void clearSimulationsTables()
        {
            DbContext context = new UnitTestsDbContext();

            context.ClearTable(UNIT_TEST_DB_NAME, SIMULATIONS_TABLE_NAME);
            context.ClearTable(UNIT_TEST_DB_NAME, LASTUPDATES_TABLE_NAME);
        }
Ejemplo n.º 2
0
        private void insertFxPairsToTestDb(IEnumerable <FxPairDto> pairs)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, Name, BaseCurrency, QuoteCurrency, IsActive) VALUE({2}, {3}, {4}, {5}, 1)";

            DbContext context = new UnitTestsDbContext();

            try
            {
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, FX_PAIRS_TABLE_NAME);
                foreach (var pair in pairs)
                {
                    try
                    {
                        string insertSql = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, FX_PAIRS_TABLE_NAME, pair.Id, pair.Name.ToDbString(), pair.BaseCurrency, pair.QuoteCurrency);
                        context.Database.ExecuteSqlCommand(insertSql);
                    }
                    catch (Exception ex)
                    {
                        var x = ex;
                    }
                }
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                context.Database.CurrentTransaction.Rollback();
            }
        }
Ejemplo n.º 3
0
        private void insertAssetsToTestDb(IEnumerable <AssetDto> assets)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, Symbol, MarketId) VALUES({2}, {3}, {4});";

            DbContext context = new UnitTestsDbContext();

            try
            {
                insertMarketsToTestDb();
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, ASSETS_TABLE_NAME);
                foreach (var asset in assets)
                {
                    string insertSql = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, ASSETS_TABLE_NAME, asset.Id, asset.Symbol.ToDbString(), asset.MarketId);
                    context.Database.ExecuteSqlCommand(insertSql);
                }
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                if (context.Database.CurrentTransaction != null)
                {
                    context.Database.CurrentTransaction.Rollback();
                }
            }
        }
Ejemplo n.º 4
0
        public void clearTable_ThrowException_IfGivenTableNameDoestnExists()
        {
            //Arrange.
            DbContext context = new UnitTestsDbContext();

            //Act.
            context.ClearTable(UNIT_TEST_DB_NAME, "nonExistingTable");
        }
Ejemplo n.º 5
0
        private void insertCurrencyToTestDb(CurrencyDto dto)    //int id, string name, string fullName)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, CurrencySymbol, CurrencyFullName) VALUES({2}, '{3}', '{4}');";
            string       insertSql          = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, CURRENCIES_TABLE_NAME, dto.Id, dto.Symbol, dto.Name);

            DbContext context = new UnitTestsDbContext();

            try
            {
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, CURRENCIES_TABLE_NAME);
                context.Database.ExecuteSqlCommand(insertSql);
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                context.Database.CurrentTransaction.Rollback();
            }
        }
Ejemplo n.º 6
0
        private void insertMarketToTestDb(MarketDto market)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, Name, ShortName) VALUES({2}, {3}, {4});";
            string       insertSql          = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, MARKETS_TABLE_NAME, market.Id, market.Name.ToDbString(), market.ShortName.ToDbString());

            DbContext context = new UnitTestsDbContext();

            try
            {
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, MARKETS_TABLE_NAME);
                context.Database.ExecuteSqlCommand(insertSql);
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                context.Database.CurrentTransaction.Rollback();
            }
        }
Ejemplo n.º 7
0
        public void clearTable_DeletesAllRecords_IfTableExists()
        {
            //Arrange.
            const string SQL_COUNT_QUERY_RECORDS = "SELECT COUNT(*) FROM {0}.{1}";
            const string INSERT_SQL_PATTERN      = "INSERT INTO {0}.{1}(Id, CurrencySymbol, CurrencyFullName) VALUES({2}, '{3}', '{4}');";
            string       insertSql = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, UNIT_TEST_TABLE_NAME, 1, "USD", "US Dollar");

            DbContext context = new UnitTestsDbContext();

            context.Database.ExecuteSqlCommand(insertSql);

            //Act.
            context.ClearTable(UNIT_TEST_DB_NAME, UNIT_TEST_TABLE_NAME);
            var sql = string.Format(SQL_COUNT_QUERY_RECORDS, UNIT_TEST_DB_NAME, UNIT_TEST_TABLE_NAME);
            var actualRecordsCounter = context.Database.SqlQuery <int>(sql).Single();

            //Assert.
            int expectedRecordsCounter = 0;

            Assert.AreEqual(expectedRecordsCounter, actualRecordsCounter);
        }
Ejemplo n.º 8
0
        private void insertTimeframeToTestDb(TimeframeDto timeframe)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, Symbol, PeriodCounter, PeriodUnit) VALUES({2}, {3}, {4}, {5});";
            string       insertSql          = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, TIMEFRAMES_TABLE_NAME,
                                                            timeframe.Id, timeframe.Symbol.ToDbString(),
                                                            timeframe.PeriodCounter, timeframe.PeriodUnit.ToDbString());

            DbContext context = new UnitTestsDbContext();

            try
            {
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, TIMEFRAMES_TABLE_NAME);
                context.Database.ExecuteSqlCommand(insertSql);
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                context.Database.CurrentTransaction.Rollback();
            }
        }
Ejemplo n.º 9
0
        private void insertCurrenciesToTestDb(IEnumerable <CurrencyDto> currencies)
        {
            const string INSERT_SQL_PATTERN = "INSERT INTO {0}.{1}(Id, CurrencySymbol, CurrencyFullName) VALUES({2}, '{3}', '{4}');";

            DbContext context = new UnitTestsDbContext();

            try
            {
                context.Database.BeginTransaction();
                context.ClearTable(UNIT_TEST_DB_NAME, CURRENCIES_TABLE_NAME);
                foreach (var currency in currencies)
                {
                    string insertSql = string.Format(INSERT_SQL_PATTERN, UNIT_TEST_DB_NAME, CURRENCIES_TABLE_NAME, currency.Id, currency.Symbol, currency.Name);
                    context.Database.ExecuteSqlCommand(insertSql);
                }
                context.Database.CurrentTransaction.Commit();
            }
            catch (Exception ex)
            {
                context.Database.CurrentTransaction.Rollback();
            }
        }
Ejemplo n.º 10
0
        private void clearTrendRangesTables()
        {
            DbContext context = new UnitTestsDbContext();

            context.ClearTable(UNIT_TEST_DB_NAME, TREND_RANGES_TABLE_NAME);
        }
Ejemplo n.º 11
0
        private void clearTrendBreaksTables()
        {
            DbContext context = new UnitTestsDbContext();

            context.ClearTable(UNIT_TEST_DB_NAME, TREND_BREAKS_TABLE_NAME);
        }