public void ExecuteDirectBehavesAsExpected() { _connection .SetupGet(m => m.Connected) .Returns(true); using (var sut = new BulkCopy()) { sut.ExecuteDirect(AnyCommandTextWillDo); } _connection.VerifyGet(m => m.Connected, Times.Once); _connection.Verify(m => m.ExecuteDirect(AnyCommandTextWillDo), Times.Once); }
private static void VerifyRoundtripsAsExpected(OdbcDriver driver) { /* * Reasons this test might fail: * 1. You need to execute SqlBulkCopy.sql (in the same directory as this test) to create the test database. * 2. You need to update the connection string to specify the location of your instance of the test database. * 3. The particular driver is not installed on your PC. */ const string connectionString = "Server=WORKSTATION\\SQL2012;Database=SqlBulkCopy;Trusted_Connection=yes;"; const string tableName = "SqlBulkCopyTest"; List<IBulkCopyBoundColumn> columns; var data = TestData.GetSampleData(); BulkCopy.Driver = driver; BulkCopy.Trace = true; try { using (var sut = new BulkCopy()) { sut.LoginTimeout = 2; try { sut.Connect(string.Concat(sut.DriverOptionString, ";", connectionString)); } catch (Exception ex) { const string message = "Please refer to this test for possible solutions." + "\r\n\r\nTesting: {0}." + "\r\n\r\nODBC exception text: {1}."; Assert.Fail(message, sut.DriverOptionString, ex.Message); } sut.ConnectionTimeout = 2; sut.ExecuteDirect("TRUNCATE TABLE SqlBulkCopyTest;"); sut.Initialize(tableName); var importer = new TestDataImporter(sut); columns = sut.Columns .Where(c => c.Index > 0) .Cast<IBulkCopyBoundColumn>() .ToList(); LoadData(importer, data); } } finally { BulkCopy.Trace = false; } List<object[]> rows; using (var cn = new SqlConnection(connectionString)) { cn.Open(); rows = FetchData(cn, columns.Count); } VerifyFetchedData(columns, data, rows); }