mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
value injector should map lazy loaded values properly.
This commit is contained in:
parent
c34ae218e8
commit
e5cc0c1a93
13 changed files with 163 additions and 267 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue