本文整理汇总了C#中SqlServer.FetchDatabases方法的典型用法代码示例。如果您正苦于以下问题:C# SqlServer.FetchDatabases方法的具体用法?C# SqlServer.FetchDatabases怎么用?C# SqlServer.FetchDatabases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlServer
的用法示例。
在下文中一共展示了SqlServer.FetchDatabases方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SqlServer_FetchDatabases_ConnectionNotInitialized_ThrowsConnectFirstException
// ReSharper disable InconsistentNaming
public void SqlServer_FetchDatabases_ConnectionNotInitialized_ThrowsConnectFirstException()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
sqlServer.FetchDatabases();
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例2: SqlServer_FetchDatabases_OnException
// ReSharper disable InconsistentNaming
public void SqlServer_FetchDatabases_OnException()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var factory = new Mock<IDbFactory>();
var mockCommand = new Mock<IDbCommand>();
var mockReader = new Mock<IDataReader>();
mockCommand.Setup(a => a.ExecuteReader(It.IsAny<CommandBehavior>())).Returns(mockReader.Object);
mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
var helpTextCommand = new Mock<IDbCommand>();
helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny<CommandBehavior>())).Throws(new DbEx("There is no text for object "));
DataTable dt = new DataTable();
dt.Columns.Add("database_name");
dt.Rows.Add(new object[] { "Bob" });
dt.Rows.Add(new object[] { "Dave" });
factory.Setup(a => a.GetSchema(It.IsAny<IDbConnection>(), "Databases")).Returns(dt);
var conn = new Mock<IDbConnection>();
conn.Setup(a => a.State).Returns(ConnectionState.Open);
var sqlServer = new SqlServer(factory.Object);
try
{
PrivateObject pvt = new PrivateObject(sqlServer);
pvt.SetField("_connection", conn.Object);
//------------Execute Test---------------------------
var output = sqlServer.FetchDatabases();
Assert.AreEqual("Bob", output[0]);
Assert.AreEqual("Dave", output[1]);
factory.Verify(a => a.GetSchema(It.IsAny<IDbConnection>(), "Databases"), Times.Once());
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例3: SqlServer_FetchDatabases_SortedListOfNames
public void SqlServer_FetchDatabases_SortedListOfNames()
{
//------------Setup for test--------------------------
var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
var expected = new List<string>();
using (var connection = new SqlConnection(dbSource.ConnectionString))
{
connection.Open();
var databases = connection.GetSchema("Databases");
connection.Close();
var names = databases.Rows.Cast<DataRow>().Select(row => (row["database_name"] ?? string.Empty).ToString()).Distinct().OrderBy(s => s);
expected.AddRange(names);
}
var sqlServer = new SqlServer();
try
{
sqlServer.Connect(dbSource.ConnectionString);
//------------Execute Test---------------------------
var actual = sqlServer.FetchDatabases();
//------------Assert Results-------------------------
CollectionAssert.AreEqual(expected, actual);
}
finally
{
sqlServer.Dispose();
}
}