I have a test method that builds up a DataTable with a certain schema to use during the test. If I inline the code for the building up of the DataTable then the test runs in Debug Mode just fine. If I encapsulate it in a function it throws an AccessViolationException when the test is run in debug mode. When run in Release mode it succeeds without a problem. I have included the code below. I tried setting some of the compiler switches and test environment settings thinking they were the cause, but they had no effect. I am using MSTest and VS 2012 RC. The Test Project is .NET 4.5
[TestMethod]
public void PkColumnSortedToTopWhenColumnMappingIsExisting()
{
// arrange
var sourceMart = new TableMap();
//var schema = new DataTable();
var schema = GetDataBaseSchemaTable();
schema.Rows.Add("Column1", 1, 2, 3, 4, true, /* isKey: */ false, true, "BaseColumn1", "BaseTable1", typeof(int), 24, true, false,
false, false, false);
schema.Rows.Add("Column2", 1, 2, 3, 4, true, /* isKey: */ false, true, "BaseColumn2", "BaseTable1", typeof(int), 24, true, false,
false, false, false);
var columnMapping1 = new ColumnMapping(schema.Rows[0], DatabaseType.MicrosoftSql);
var columnMapping2 = new ColumnMapping(schema.Rows[1], DatabaseType.MicrosoftSql);
sourceMart.Mappings.Add(columnMapping1);
sourceMart.Mappings.Add(columnMapping2);
var viewModel = new MappingViewModel(sourceMart);
// Navigate to next page (first time building mappings)
viewModel.Activate();
// Set second column to be a PK
sourceMart.Mappings.First(m => m.SourceColumnName == "Column2").IsDestinationColumnPartOfPrimaryKey = true;
//Reactivate which simulates as if we navigated away and back which should resort it
viewModel.Activate();
// assert
Assert.IsTrue(viewModel.ColumnMappingVMs.First().ColumnMapping.IsDestinationColumnPartOfPrimaryKey);
}
public DataTable GetDataBaseSchemaTable()
{
var schemaTable = new DataTable();
schemaTable.Columns.Add(new DataColumn("ColumnName", typeof(string)));
schemaTable.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
schemaTable.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
schemaTable.Columns.Add(new DataColumn("SourceNumericPrecision", typeof(short)));
schemaTable.Columns.Add(new DataColumn("SourceNumericScale", typeof(short)));
schemaTable.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsKey", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsRowID", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("BaseColumnName", typeof(string)));
schemaTable.Columns.Add(new DataColumn("BaseTableName", typeof(string)));
schemaTable.Columns.Add(new DataColumn("DataType", typeof(Type)));
schemaTable.Columns.Add(new DataColumn("ProviderType", typeof(int)));
schemaTable.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsAliased", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsExpression", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsHidden", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsReadOnly", typeof(bool)));
schemaTable.Columns.Add(new DataColumn("IsLong", typeof(bool)));
return schemaTable;
}