Skip to content

Instantly share code, notes, and snippets.

@mhinze
Created December 21, 2010 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinze/750017 to your computer and use it in GitHub Desktop.
Save mhinze/750017 to your computer and use it in GitHub Desktop.
[TestFixture]
public class IdToEntityConverterTester : TestBase
{
[Test]
public void Should_load_entity()
{
Guid userId = Guid.NewGuid();
var user = new User();
var repository = S<IUserRepository>();
repository.Stub(x => x.GetById(userId)).Return(user);
var converter = new IdToEntityConverter<User>(repository);
User converted = converter.Convert(ResolutionContext.New(userId));
converted.ShouldBeTheSameAs(user);
}
[Test]
public void Should_load_null_entity_when_id_is_empty()
{
Guid userId = Guid.Empty;
var converter = new IdToEntityConverter<User>(null);
User converted = converter.Convert(ResolutionContext.New(userId));
converted.ShouldBeNull();
}
[Test]
public void Should_load_null_entity_when_id_is_null()
{
var converter = new NullableIdToEntityConverter<User>(null);
User converted = converter.Convert(new ResolutionContext(null, null,null,null));
converted.ShouldBeNull();
}
[Test]
public void Should_load_null_entity_when_nullable_id_is_empty()
{
var converter = new NullableIdToEntityConverter<User>(null);
User converted = converter.Convert(ResolutionContext.New(Guid.Empty));
converted.ShouldBeNull();
}
[Test]
public void Should_load_null_entity_when_nullable_id_is_populated()
{
Guid? userId = Guid.NewGuid();
var user = new User();
var repository = S<IUserRepository>();
repository.Stub(x => x.GetById(userId.Value)).Return(user);
var converter = new NullableIdToEntityConverter<User>(repository);
User converted = converter.Convert(ResolutionContext.New(userId));
converted.ShouldBeTheSameAs(user);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment