mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-27 12:33:00 +02:00
value injector should map lazy loaded values properly.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user