public void ToSqlDefinitionTest() { var scripts = new SqlScriptCollection(); scripts.Add.FromString("key", "test sql"); var connectionFactory = new SqlScriptConnectionFactory(scripts); using (var tokenSource = new CancellationTokenSource()) { var scriptCommandDefinition = new ScriptCommandDefinition { Key = "key", Parameters = new { param = "test", }, Transaction = null, CommandTimeout = 123, CommandType = CommandType.StoredProcedure, Flags = CommandFlags.Pipelined, CancellationToken = tokenSource.Token, }; using (var connection = connectionFactory.Connect()) { var commandDefinition = scriptCommandDefinition.ToSqlDefinition(connection); Assert.Equal("test sql", commandDefinition.CommandText); Assert.Equal(scriptCommandDefinition.Parameters, commandDefinition.Parameters); Assert.Equal(scriptCommandDefinition.Transaction, commandDefinition.Transaction); Assert.Equal(scriptCommandDefinition.CommandTimeout, commandDefinition.CommandTimeout); Assert.Equal(scriptCommandDefinition.CommandType, commandDefinition.CommandType); Assert.Equal(scriptCommandDefinition.Flags, commandDefinition.Flags); Assert.Equal(scriptCommandDefinition.CancellationToken, commandDefinition.CancellationToken); } } }
public void LoadsAllScriptsFromFile() { var collection = new SqlScriptCollection(); collection.Add.FromFile(".\\Scripts\\SqlTest.sql"); var sql = collection.GetScriptSql("SqlTest.sql"); Assert.Equal(SqlLiteral, sql.Trim()); }
public void LoadsAllScriptsFromAssemblyWithEncoding() { var collection = new SqlScriptCollection(); collection.Add.FromAssembly(assembly, "Dapper.Scripts.Tests.Scripts", Encoding.UTF8); var sql = collection.GetScriptSql("SqlTest.sql"); Assert.Equal(SqlLiteral, sql.Trim()); }
public async Task LoadsAllScriptsFromAssemblyAsync() { var collection = new SqlScriptCollection(); await collection.Add.FromAssemblyAsync(assembly, "Dapper.Scripts.Tests.Scripts"); var sql = collection.GetScriptSql("SqlTest.sql"); Assert.Equal(SqlLiteral, sql.Trim()); }
public void ScriptReplacesTags() { var collection = new SqlScriptCollection(); collection.Add.FromDirectory(".\\Scripts"); var sql = collection.GetScriptSql("SqlTransformTest.sql", _params); Assert.Equal(SqlLiteral, sql.Trim()); }
static UsageExample() { var scripts = new SqlScriptCollection(); scripts.Add.FromAssembly("namespace.Sql."); DatabaseName = new SqlScriptConnectionFactory(scripts); DatabaseName.ConnectionString = "Server: xxx;"; }
static Database() { #if NETCOREAPP1_0 var assembly = typeof(Database).GetTypeInfo().Assembly; #else var assembly = Assembly.GetExecutingAssembly(); #endif var scripts = new SqlScriptCollection(); scripts.Add.FromAssembly(assembly, "Dapper.Scripts.Tests.Scripts"); Testing = new SqlScriptConnectionFactory(scripts) { ConnectionString = "Server=.\\SQLExpress; Integrated Security=true; Initial Catalog=DapperScripts_Testing;", }; }