Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created September 28, 2012 04:46
Show Gist options
  • Save prabirshrestha/3797966 to your computer and use it in GitHub Desktop.
Save prabirshrestha/3797966 to your computer and use it in GitHub Desktop.
public class SqlService {
public string ConnectionStirng { get; private set; }
public SqlService()
:this("defaultConnectionString")
{
}
public SqlService(stirng connectionString) {
this.connectionString = connectionstring;
}
public virtual IList<User> GetUsers() {
using(var cn = new SqlConnection("connectionString")) {
const string sql = "select top 1o * from users where id=@userId";
return cn.Query<User>(sql, new { userId = userId }).ToList();
}
}
}
public class SampleModule : NancyModule {
public SampleModule(SqlService sql) {
Get["/"] = _ => {
var users = sql.GetUsers();
return View["users", users];
}
}
}
public class FakeSqlService {
public ovveride IList<User> GetUsers() {
return new List<User>() {...};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment