Esempio n. 1
0
        public void ExecuteSql(string commandText, Action <DbDataReader> readerAction)
        {
            var factory = new StubbedDataContextFactory();

            using (var dbConnection = factory.GetContext().Database.GetDbConnection())
            {
                dbConnection.ConnectionString = factory.Config.GetConnectionString();
                dbConnection.Open();
                using (var command = dbConnection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText =
                        commandText;
                    DbDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        readerAction(reader);
                    }
                }
                dbConnection.Close();
            }
        }
Esempio n. 2
0
        public void LoadLocalData()
        {
            new DatabaseTester().Clean();


            using (var context = new StubbedDataContextFactory().GetContext())
            {
                for (int i = 0; i < 20; i++)
                {
                    var newGuid = Guid.NewGuid();
                    var report  = new ExpenseReport
                    {
                        Title       = "TestExpense " + newGuid,
                        Description = "This is an expense" + newGuid,
                        Number      = newGuid.ToString().Substring(0, 6),
                        Status      = ExpenseReportStatus.Cancelled
                    };
                    context.Add(report);
                }
                context.SaveChanges();
            }
        }