Created
July 18, 2012 14:44
-
-
Save glauco/3136604 to your computer and use it in GitHub Desktop.
BaseTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Data.SqlClient; | |
namespace MT.SmsNavigationFactory.Tests | |
{ | |
public abstract class BaseTest | |
{ | |
protected void Delete(string sql) | |
{ | |
using (var connection = new SqlConnection("Data Source=.;Initial Catalog=SmsNavigationFactory;Integrated Security=True;MultipleActiveResultSets=True")) | |
{ | |
connection.Open(); | |
using (var command = new SqlCommand(sql, connection)) | |
{ | |
command.ExecuteNonQuery(); | |
} | |
connection.Close(); | |
} | |
} | |
protected T Create<T>(string sql) | |
{ | |
T id; | |
using (var connection = new SqlConnection("Data Source=.;Initial Catalog=SmsNavigationFactory;Integrated Security=True;MultipleActiveResultSets=True")) | |
{ | |
connection.Open(); | |
using (SqlCommand command = new SqlCommand(sql, connection)) | |
{ | |
var result = command.ExecuteScalar(); | |
id = (T)result; | |
} | |
connection.Close(); | |
} | |
return id; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment