2013-04-21 21:04:09 +00:00
|
|
|
|
using System;
|
2013-06-01 04:59:54 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using FizzWare.NBuilder;
|
2013-06-01 02:49:15 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Marr.Data;
|
2013-04-21 21:04:09 +00:00
|
|
|
|
using NUnit.Framework;
|
2013-09-11 06:33:47 +00:00
|
|
|
|
using NzbDrone.Api.Commands;
|
2013-04-25 04:27:49 +00:00
|
|
|
|
using NzbDrone.Api.Config;
|
2013-04-21 21:04:09 +00:00
|
|
|
|
using NzbDrone.Api.Episodes;
|
2013-05-03 15:23:31 +00:00
|
|
|
|
using NzbDrone.Api.History;
|
2013-04-28 00:50:49 +00:00
|
|
|
|
using NzbDrone.Api.Indexers;
|
2013-06-05 00:49:53 +00:00
|
|
|
|
using NzbDrone.Api.Logs;
|
2013-04-21 21:04:09 +00:00
|
|
|
|
using NzbDrone.Api.Mapping;
|
2013-05-31 01:22:28 +00:00
|
|
|
|
using NzbDrone.Api.Qualities;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
using NzbDrone.Api.RootFolders;
|
2013-04-21 21:04:09 +00:00
|
|
|
|
using NzbDrone.Api.Series;
|
2013-09-11 23:33:34 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-04-28 00:25:28 +00:00
|
|
|
|
using NzbDrone.Core.Indexers;
|
2013-06-05 00:49:53 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
2013-09-11 06:33:47 +00:00
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
2013-04-25 04:27:49 +00:00
|
|
|
|
using NzbDrone.Core.Organizer;
|
2013-04-28 19:46:13 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-05-31 01:22:28 +00:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
using NzbDrone.Core.RootFolders;
|
2013-07-24 05:35:32 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-09-11 06:33:47 +00:00
|
|
|
|
using NzbDrone.Core.Update.Commands;
|
2013-04-21 21:04:09 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2013-06-01 04:59:54 +00:00
|
|
|
|
using System.Linq;
|
2013-04-21 21:04:09 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Test.MappingTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class ResourceMappingFixture : TestBase
|
|
|
|
|
{
|
|
|
|
|
[TestCase(typeof(Core.Tv.Series), typeof(SeriesResource))]
|
2013-07-24 05:35:32 +00:00
|
|
|
|
[TestCase(typeof(Episode), typeof(EpisodeResource))]
|
2013-04-22 03:18:08 +00:00
|
|
|
|
[TestCase(typeof(RootFolder), typeof(RootFolderResource))]
|
2013-04-25 04:27:49 +00:00
|
|
|
|
[TestCase(typeof(NamingConfig), typeof(NamingConfigResource))]
|
2013-05-02 23:06:08 +00:00
|
|
|
|
[TestCase(typeof(Indexer), typeof(IndexerResource))]
|
2013-09-13 23:17:58 +00:00
|
|
|
|
[TestCase(typeof(ReleaseInfo), typeof(ReleaseResource))]
|
2013-04-28 19:46:13 +00:00
|
|
|
|
[TestCase(typeof(ParsedEpisodeInfo), typeof(ReleaseResource))]
|
|
|
|
|
[TestCase(typeof(DownloadDecision), typeof(ReleaseResource))]
|
2013-05-03 15:23:31 +00:00
|
|
|
|
[TestCase(typeof(Core.History.History), typeof(HistoryResource))]
|
2013-05-31 01:22:28 +00:00
|
|
|
|
[TestCase(typeof(Quality), typeof(QualityResource))]
|
2013-06-05 00:49:53 +00:00
|
|
|
|
[TestCase(typeof(Log), typeof(LogResource))]
|
2013-09-11 06:33:47 +00:00
|
|
|
|
[TestCase(typeof(Command), typeof(CommandResource))]
|
2013-04-21 21:04:09 +00:00
|
|
|
|
public void matching_fields(Type modelType, Type resourceType)
|
|
|
|
|
{
|
|
|
|
|
MappingValidation.ValidateMapping(modelType, resourceType);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-01 02:49:15 +00:00
|
|
|
|
|
|
|
|
|
[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();
|
|
|
|
|
}
|
2013-06-01 04:59:54 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_be_able_to_map_lists()
|
|
|
|
|
{
|
|
|
|
|
var modelList = Builder<TestModel>.CreateListOfSize(10).Build();
|
|
|
|
|
|
|
|
|
|
var resourceList = modelList.InjectTo<List<TestResource>>();
|
|
|
|
|
|
|
|
|
|
resourceList.Should().HaveSameCount(modelList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_map_wrapped_models()
|
|
|
|
|
{
|
|
|
|
|
var modelList = Builder<TestModel>.CreateListOfSize(10).Build().ToList();
|
|
|
|
|
|
|
|
|
|
var wrapper = new TestModelWrapper
|
|
|
|
|
{
|
|
|
|
|
TestlList = modelList
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
wrapper.InjectTo<TestResourceWrapper>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_map_qualityprofile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var profileResource = new QualityProfileResource
|
|
|
|
|
{
|
|
|
|
|
Allowed = Builder<QualityResource>.CreateListOfSize(1).Build().ToList(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profileResource.InjectTo<QualityProfile>();
|
|
|
|
|
|
|
|
|
|
}
|
2013-09-11 06:33:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_map_tracked_command()
|
|
|
|
|
{
|
|
|
|
|
var profileResource = new ApplicationUpdateCommand();
|
|
|
|
|
profileResource.InjectTo<CommandResource>();
|
|
|
|
|
}
|
2013-06-01 02:49:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ModelWithLazy
|
|
|
|
|
{
|
|
|
|
|
public LazyLoaded<Guid> Guid { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ModelWithNoLazy
|
|
|
|
|
{
|
|
|
|
|
public Guid Guid { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TestLazyLoaded<T> : LazyLoaded<T>
|
|
|
|
|
{
|
|
|
|
|
public override void Prepare(Func<IDataMapper> dataMapperFactory, object parent)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
2013-04-21 21:04:09 +00:00
|
|
|
|
}
|
2013-06-01 04:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TestModelWrapper
|
|
|
|
|
{
|
|
|
|
|
public List<TestModel> TestlList { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TestResourceWrapper
|
|
|
|
|
{
|
|
|
|
|
public List<TestResource> TestList { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TestModel
|
|
|
|
|
{
|
|
|
|
|
public string Field1 { get; set; }
|
|
|
|
|
public string Field2 { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TestResource
|
|
|
|
|
{
|
|
|
|
|
public string Field1 { get; set; }
|
|
|
|
|
public string Field2 { get; set; }
|
|
|
|
|
}
|
2013-04-21 21:04:09 +00:00
|
|
|
|
}
|