Permalink
Browse files

Added stored procedure creation to database reset

  • Loading branch information...
1 parent e0bcc0b commit 296ef11ab42ced347d9abba7653823d3452f5657 @markrendle committed Jan 21, 2011
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
+using System.Data.SqlClient;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
namespace Simple.Data.SqlTest
{
@@ -11,5 +13,21 @@ public static dynamic Open()
{
return Database.Opener.OpenConnection(Properties.Settings.Default.ConnectionString);
}
+
+ public static void Reset()
+ {
+ using (var cn = new SqlConnection(Properties.Settings.Default.ConnectionString))
+ {
+ cn.Open();
+ using (var cmd = cn.CreateCommand())
+ {
+ foreach (var sql in Regex.Split(Properties.Resources.DatabaseReset, @"^\s*GO\s*$",RegexOptions.Multiline))
+ {
+ cmd.CommandText = sql;
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ }
}
}
@@ -18,14 +18,7 @@ public class FindTests
[TestFixtureSetUp]
public void Setup()
{
- using (var cn = new SqlConnection(Properties.Settings.Default.ConnectionString))
- {
- using (var cmd = new SqlCommand(Properties.Resources.DatabaseReset, cn))
- {
- cn.Open();
- cmd.ExecuteNonQuery();
- }
- }
+ DatabaseHelper.Reset();
}
[Test]
@@ -84,3 +84,33 @@ ALTER TABLE [dbo].[OrderItems] WITH NOCHECK
ALTER TABLE [dbo].[OrderItems] WITH NOCHECK
ADD CONSTRAINT [FK_OrderItems_Orders] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([OrderId]) ON DELETE NO ACTION ON UPDATE NO ACTION;
+
+IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomers]') AND type in (N'P', N'PC'))
+DROP PROCEDURE [dbo].[GetCustomers]
+IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomerAndOrders]') AND type in (N'P', N'PC'))
+DROP PROCEDURE [dbo].[GetCustomerAndOrders]
+IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomerCount]') AND type in (N'P', N'PC'))
+DROP PROCEDURE [dbo].[GetCustomerCount]
+GO
+CREATE PROCEDURE [dbo].[GetCustomers]
+AS
+BEGIN
+ SET NOCOUNT ON;
+ SELECT * FROM Customers
+ ORDER BY CustomerId
+END
+GO
+CREATE PROCEDURE [dbo].[GetCustomerAndOrders] (@CustomerId int)
+AS
+BEGIN
+ SET NOCOUNT ON;
+ SELECT * FROM Customers WHERE CustomerId = @CustomerId;
+ SELECT * FROM Orders WHERE CustomerId = @CustomerId;
+END
+GO
+CREATE PROCEDURE [dbo].[GetCustomerCount]
+AS
+BEGIN
+ SET NOCOUNT ON;
+ RETURN 1
+END
@@ -13,14 +13,7 @@ public class TransactionTests
[SetUp]
public void Setup()
{
- using (var cn = new SqlConnection(Properties.Settings.Default.ConnectionString))
- {
- using (var cmd = new SqlCommand(Properties.Resources.DatabaseReset, cn))
- {
- cn.Open();
- cmd.ExecuteNonQuery();
- }
- }
+ DatabaseHelper.Reset();
}
[Test]
@@ -4,7 +4,7 @@
</configSections>
<connectionStrings>
<add name="Simple.Data.SqlTest.Properties.Settings.ConnectionString"
- connectionString="Data Source=.;Initial Catalog=SimpleTest;Integrated Security=True"
+ connectionString="Data Source=.\SQLSERVER2008;Initial Catalog=SimpleTest;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

0 comments on commit 296ef11

Please sign in to comment.