本文整理汇总了C#中SqlServer类的典型用法代码示例。如果您正苦于以下问题:C# SqlServer类的具体用法?C# SqlServer怎么用?C# SqlServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlServer类属于命名空间,在下文中一共展示了SqlServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get_Table_Definition
public void Get_Table_Definition()
{
var server = new SqlServer();
var table = server.GetTableDefinition("localhost", "master", "spt_fallback_db");
table.ShouldNotBeNull();
table.Columns.Count().ShouldNotEqual(0);
}
示例2: SqlServer_Connect_UserIDInDomainFormat_ConnectionStringIsNotIntegratedSecurityEqualsSSPI
public void SqlServer_Connect_UserIDInDomainFormat_ConnectionStringIsNotIntegratedSecurityEqualsSSPI()
{
//------------Setup for test--------------------------
var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
dbSource.UserID = "Dev2\\TestUser";
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
try
{
// expect this call to throw a 'login failed' exception
sqlServer.Connect(dbSource.ConnectionString);
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
}
//------------Assert Results-------------------------
Assert.IsFalse(sqlServer.ConnectionString.Contains("Integrated Security=SSPI"));
}
finally
{
sqlServer.Dispose();
}
}
示例3: SqlDataBase
/// <summary>
/// �õ�ʵ��
/// </summary>
/// <returns></returns>
public static SqlServer SqlDataBase()
{
if (_SqlDataBase == null)
{
_SqlDataBase = new Universal_ClassLibrary.DataBase.SqlServer(ConfigHelper.GetAppSettings("SqlServer_NewSaaS"));
}
return _SqlDataBase;
}
示例4: FecharCaixa
public void FecharCaixa()
{
var impostos = 200;
var database = new SqlServer();
var vendas = database.Selecionar("Dinheiro em caixa");
var vendasDeOntem = database.Selecionar("Dinheiro em caixa de ontem");
var totalDeVendas = vendas - vendasDeOntem;
totalDeVendas = totalDeVendas - impostos;
database.Atualizar("vendas líquidas", totalDeVendas.ToString());
database.Deletar("venda bruta");
}
示例5: Should_replace_where_with_included_databases
public void Should_replace_where_with_included_databases()
{
var queryType = new SqlServerConnections();
var sqlServer = new SqlServer("foo", "foo", true, new[] {new Database {Name = "bar"},}, null);
var queryLocator = new QueryLocator(null);
var queries = queryLocator.PrepareQueries(new[] {queryType.GetType()}, false);
foreach (var query in queries)
{
var actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
Assert.That(actual, Is.StringContaining("AND (d.Name IN ('bar')"));
}
}
示例6: Test_Type_SQLServerDatabase
public void Test_Type_SQLServerDatabase()
{
// Define tipo Sql
AbstractDataBase dataBase = new SqlServer();
// Atribuindo command
DbCommand cmd = dataBase.Command;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT, DELETE, INSERT, UPDATE";
cmd.Connection.Open();
DbDataReader reader = cmd.ExecuteReader();
reader.Close();
cmd.Connection.Close();
Assert.IsInstanceOfType(dataBase, typeof(SqlServer));
}
示例7: SqlServer_Connect_CommandTextIsNull_ThrowsArgumentNullException
// ReSharper disable InconsistentNaming
public void SqlServer_Connect_CommandTextIsNull_ThrowsArgumentNullException()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
sqlServer.Connect("Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=SSPI;", CommandType.Text, null);
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例8: SqlServer_Connect_ConnectionStringIsInvalid_ThrowsArgumentException
// ReSharper disable InconsistentNaming
public void SqlServer_Connect_ConnectionStringIsInvalid_ThrowsArgumentException()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
sqlServer.Connect("xxx", CommandType.Text, null);
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例9: SqlServer_Connect_ValidLogin_IsConnectedIsTrue
public void SqlServer_Connect_ValidLogin_IsConnectedIsTrue()
{
//------------Setup for test--------------------------
var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
sqlServer.Connect(dbSource.ConnectionString);
//------------Assert Results-------------------------
Assert.IsTrue(sqlServer.IsConnected);
}
finally
{
sqlServer.Dispose();
}
}
示例10: SqlServer_Connect_InvalidLogin_ThrowsSqlException
public void SqlServer_Connect_InvalidLogin_ThrowsSqlException()
{
//------------Setup for test--------------------------
var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
dbSource.Password = Guid.NewGuid().ToString(); // Random invalid password
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
sqlServer.Connect(dbSource.ConnectionString);
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例11: 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();
}
}
示例12: SqlServer_FetchDataTable_CommandIsNull_ThrowsArgumentNullException
// ReSharper disable InconsistentNaming
public void SqlServer_FetchDataTable_CommandIsNull_ThrowsArgumentNullException()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var sqlServer = new SqlServer();
try
{
//------------Execute Test---------------------------
sqlServer.FetchDataTable((IDbCommand)null);
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例13: Execute_Arbitrary_Sql
public void Execute_Arbitrary_Sql()
{
var server = new SqlServer();
Assert.DoesNotThrow(() => server.Execute("localhost", "master", "SELECT COUNT(*) FROM sys.databases"));
}
示例14: SqlServer_FetchDataSet_CorrectDataReturned
public void SqlServer_FetchDataSet_CorrectDataReturned()
{
//------------Setup for test--------------------------
var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
var sqlServer = new SqlServer();
try
{
sqlServer.Connect(dbSource.ConnectionString, CommandType.StoredProcedure, "Pr_CitiesGetCountries");
//------------Execute Test---------------------------
var actualDataSet = sqlServer.FetchDataSet(new SqlParameter("@Prefix", "a"));
//------------Assert Results-------------------------
Assert.AreEqual(1, actualDataSet.Tables.Count);
var actual = actualDataSet.Tables[0];
SqlServerTestUtils.Verify_DataTable_CountriesPrefixIsA(actual);
}
finally
{
sqlServer.Dispose();
}
}
示例15: SqlServer_FetchStoredProcedures_FuncReturnsSPs
// ReSharper disable InconsistentNaming
public void SqlServer_FetchStoredProcedures_FuncReturnsSPs()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var factory = new Mock<IDbFactory>();
var mockCommand = new Mock<IDbCommand>();
var mockReader = new Mock<IDataReader>();
var queue = new Queue<DataTable>();
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>())).Returns(new Mock<IDataReader>().Object);
var somethingAdded = false;
var funcAdded = false;
factory.Setup(a => a.CreateCommand(It.IsAny<IDbConnection>(), CommandType.Text, GlobalConstants.SchemaQuery)).Returns(mockCommand.Object);
factory.Setup(a => a.CreateCommand(It.IsAny<IDbConnection>(), CommandType.StoredProcedure, "Dave.Bob")).Returns(mockCommand.Object);
factory.Setup(a => a.CreateCommand(It.IsAny<IDbConnection>(), CommandType.Text, "sp_helptext 'Dave.Bob'")).Returns(helpTextCommand.Object);
DataTable dt = new DataTable();
dt.Columns.Add("ROUTINE_NAME");
dt.Columns.Add("ROUTINE_TYPE");
dt.Columns.Add("SPECIFIC_SCHEMA");
dt.Rows.Add(new object[] { "Bob", "SQL_SCALAR_FUNCTION", "Dave" });
queue.Enqueue(dt);
queue.Enqueue(new DataTable()); // no params
factory.Setup(a => a.CreateTable(mockReader.Object, LoadOption.OverwriteChanges)).Returns(queue.Dequeue);
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---------------------------
Func<IDbCommand, List<IDbDataParameter>, string, string, bool> procProcessor = (command, list, arg3, a) =>
{
somethingAdded = true; return true;
};
Func<IDbCommand, List<IDbDataParameter>, string, string, bool> funcProcessor = (command, list, arg3, a) =>
{
funcAdded = true; return true;
};
sqlServer.FetchStoredProcedures(procProcessor, funcProcessor);
Assert.IsTrue(funcAdded);
Assert.IsFalse(somethingAdded);
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}