xpf.Script.SQLServer

A powerful library for executing SQL Scripts against a database using a fluent API. This library is especially useful for integration testing with its ability to reference other scripts within a script like SQL Server :r support. See project web site for more details on features.


Keywords
Scripting, xpf.Script, SQLServer, SQL, TDD, BDD, integration, testing, dynamic
License
MS-PL
Install
Install-Package xpf.Script.SQLServer -Version 0.2.0.5

Documentation

xpf.Script

Is a cross platform scripting abstraction for scripting engines such as SQL Server, PowerShell, Razor or Http. With SQL Server being the only currently supported scripting engine. Demand for additional engines can be added with community support.

The following code demonstrates how you can execute a simple SQL Script using the library:

 var result = new Script()
     .Database() // Specifies to use the SQL Server Scripting engine
     .UsingCommand("SELECT @RowCount = COUNT(*) FROM Customer WHERE Name = @Name")
     .WithIn(new {Name = "John"})
     .WithOut(new { RowCount = DbType.Int32})
     .Execute();

The library takes care of defining input and output parameters and provides a more natural way to define them. The library supports the ability to use embedded resource files as script input and have them reference other resource files allowing for easy reuse of scripts.

Scripts.VerifyCustomerRecord.sql

  IF(EXISTS(SELECT 1 FROM Customer WHERE CustomerId = @CustomerId))
    RAISE ERROR (1,23,'Customer Already exists')

Scripts.AddCustomerRecord.sql

  :r Scripts.VerifyCustomerRecord.sql

  INSERT INTO Customer(@CustomerId, CustomerName, Address)
        VALUES(@CustomerId, @CustomerName, @Address)

Execute scripts

 var result = new Script()
     .Database() // Specifies to use the SQL Server Scripting engine
     .UsingNestedScript("Scripts.AddCustomerRecord.sql")
     .WithIn(new {CustomerId = 2, CustomerName = "John", Address = "124 Street"})
     .Execute();

See the WIKI pages for more documentation on how to use the library.

xpf.Script Change List

xpf.Script.SQLServer Change List