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,31 +0,0 @@
using System.Reflection;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.Datastore;
using NzbDrone.Test.Common;
namespace NzbDrone.Api.Test.MappingTests
{
public class ReflectionExtensionFixture : TestBase
{
[Test]
public void should_get_properties_from_models()
{
var models = Assembly.Load("NzbDrone.Core").ImplementationsOf<ModelBase>();
foreach (var model in models)
{
model.GetSimpleProperties().Should().NotBeEmpty();
}
}
[Test]
public void should_be_able_to_get_implementations()
{
var models = Assembly.Load("NzbDrone.Core").ImplementationsOf<ModelBase>();
models.Should().NotBeEmpty();
}
}
}

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();
}
}
}

View file

@ -73,11 +73,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ClientSchemaTests\SchemaBuilderFixture.cs" />
<Compile Include="MappingTests\ReflectionExtensionFixture.cs" />
<Compile Include="MappingTests\ResourceMappingFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Marr.Data\Marr.Data.csproj">
<Project>{F6FC6BE7-0847-4817-A1ED-223DC647C3D7}</Project>
<Name>Marr.Data</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Api\NzbDrone.Api.csproj">
<Project>{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}</Project>
<Name>NzbDrone.Api</Name>