Skip to content

Instantly share code, notes, and snippets.

View stefansedich's full-sized avatar

Stefan Sedich stefansedich

  • Sage AI
  • San Francisco, California
View GitHub Profile
@stefansedich
stefansedich / CleanupTestDataEventListener.cs
Created May 22, 2011 00:18
CleanupTestDataEventListener
public class CleanupTestDataEventListener : IPostInsertEventListener
{
private readonly HashSet<object> _insertedEntities = new HashSet<object>();
public IEnumerable<object> InsertedEntities
{
get { return _insertedEntities.Reverse(); }
}
public void OnPostInsert(PostInsertEvent @event)
[SetUp]
public void SetUp()
{
_cleanupListener = new CleanupTestDataEventListener();
var cfg = new Configuration()
.DataBaseIntegration(x =>
{
x.Dialect<SQLiteDialect>();
x.ConnectionString = "Data Source=test.db;Version=3;";
[TearDown]
public void TearDown()
{
using(var session = CreateSession())
{
using(var tx = session.BeginTransaction())
{
foreach (var entity in _cleanupListener.InsertedEntities)
{
session.Delete(entity);
[Test]
public void Create_Some_Data()
{
var person = new Person{Name = "dsd", Age = 22};
var foo = new Foo {Description = "Testing"};
using(var session = CreateSession())
{
using(var tx = session.BeginTransaction())
{
NHibernate: INSERT INTO Person (Name, Age, Id) VALUES (@p0, @p1, @p2);@p0 = 'dsd' [Type: String (0)], @p1 = 22 [Type: Int32 (0)], @p2 = 0 [Type: Int32 (0)]
NHibernate: INSERT INTO Foo (Description, Id) VALUES (@p0, @p1);@p0 = 'Testing' [Type: String (0)], @p1 = 0 [Type: Int32 (0)]
NHibernate: SELECT person_.Id, person_.Name as Name0_, person_.Age as Age0_ FROM Person person_ WHERE person_.Id=@p0;@p0 = 0 [Type: Int32 (0)]
NHibernate: SELECT foo_.Id, foo_.Description as Descript2_1_ FROM Foo foo_ WHERE foo_.Id=@p0;@p0 = 0 [Type: Int32 (0)]
NHibernate: DELETE FROM Person WHERE Id = @p0;@p0 = 0 [Type: Int32 (0)]
NHibernate: DELETE FROM Foo WHERE Id = @p0;@p0 = 0 [Type: Int32 (0)]
// Rhino Mocks
var foo = MockRepository.GenerateStub<IFoo>();
var foo = MockRepository.GenerateMock<IFoo>();
var foo = MockRepository.GeneratePartialMock<IFoo>();
var foo = MockRepository.GenerateStrictMock()<IFoo>();
// NSubstitute
var foo = Substitute.For<IFoo>();
[Test]
public void Some_Test_Rhino()
{
// Arrange
var foo = MockRepository.GenerateStub<IFoo>();
var someClass = new SomeClass(foo);
// Act
someClass.DoWork();
// Rhino Mocks
var foo = MockRepository.GenerateStub<IFoo>();
foo.Stub(x => x.GetValue())
.Return("testing");
// NSubstitute
var foo = Substitute.For<IFoo>();
foo.GetValue().Returns("testing");
public void Foo(int bah) {
//if(bah > 1) {
if(bah > 2) {
}
}
//public class Foo {
// public void Bah() {
//
// }
//}