Created
December 21, 2010 15:05
-
-
Save mhinze/750017 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[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