value injector should map lazy loaded values properly.

This commit is contained in:
kay.one 2013-05-31 19:49:15 -07:00
commit e5cc0c1a93
13 changed files with 163 additions and 267 deletions

View file

@ -1,4 +1,6 @@
using System;
using FluentAssertions;
using Marr.Data;
using NUnit.Framework;
using NzbDrone.Api.Config;
using NzbDrone.Api.Episodes;
@ -40,5 +42,58 @@ namespace NzbDrone.Api.Test.MappingTests
MappingValidation.ValidateMapping(modelType, resourceType);
}
[Test]
public void should_map_lay_loaded_values_should_not_be_inject_if_not_loaded()
{
var modelWithLazy = new ModelWithLazy()
{
Guid = new TestLazyLoaded<Guid>()
};
modelWithLazy.InjectTo<ModelWithNoLazy>().Guid.Should().BeEmpty();
modelWithLazy.Guid.IsLoaded.Should().BeFalse();
}
[Test]
public void should_map_lay_loaded_values_should_be_inject_if_loaded()
{
var guid = Guid.NewGuid();
var modelWithLazy = new ModelWithLazy()
{
Guid = new LazyLoaded<Guid>(guid)
};
modelWithLazy.InjectTo<ModelWithNoLazy>().Guid.Should().Be(guid);
modelWithLazy.Guid.IsLoaded.Should().BeTrue();
}
}
public class ModelWithLazy
{
public LazyLoaded<Guid> Guid { get; set; }
}
public class ModelWithNoLazy
{
public Guid Guid { get; set; }
}
public class TestLazyLoaded<T> : LazyLoaded<T>
{
public TestLazyLoaded()
{
}
public override void Prepare(Func<IDataMapper> dataMapperFactory, object parent)
{
throw new InvalidOperationException();
}
}
}