public void ConnectBehavesAsExpected() { var connected = false; _connection .SetupGet(m => m.Connected) .Returns(() => connected); _connection .Setup(m => m.Connect(AnyConnectionStringWillDo)) .Callback(() => connected = true); using (var sut = new BulkCopy()) { sut.Connect(AnyConnectionStringWillDo); } _connection.VerifyGet(m => m.Connected, Times.Once); _connection.Verify(m => m.Connect(AnyConnectionStringWillDo), Times.Once); }
private BulkCopy GetInitializedSubjectUnderTest() { var connected = false; var initialized = false; _connection .SetupGet(m => m.Connected) .Returns(() => connected); _connection .SetupGet(m => m.Initialized) .Returns(() => initialized); _connection .Setup(m => m.Connect(AnyConnectionStringWillDo)) .Callback(() => connected = true); _connection .Setup(m => m.Initialize(AnyTableNameWillDo)) .Callback(() => initialized = true); var sut = new BulkCopy(); sut.Connect(AnyConnectionStringWillDo); sut.Initialize(AnyTableNameWillDo); return sut; }
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); }