mirror of https://github.com/Sonarr/Sonarr
TestDbHelper cleanup
This commit is contained in:
parent
1b45a85f3f
commit
ed566e6e9a
|
@ -16,9 +16,9 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
private const string DB_TEMPLATE_NAME = "_dbtemplate.sdf";
|
private const string DB_TEMPLATE_NAME = "_dbtemplate.sdf";
|
||||||
|
|
||||||
public static string ConnectionString { get; private set; }
|
internal static string ConnectionString { get; private set; }
|
||||||
|
|
||||||
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
|
internal static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
|
||||||
{
|
{
|
||||||
Console.WriteLine("====================DataBase====================");
|
Console.WriteLine("====================DataBase====================");
|
||||||
Console.WriteLine("Cloning database from template.");
|
Console.WriteLine("Cloning database from template.");
|
||||||
|
@ -41,21 +41,12 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateDataBaseTemplate()
|
internal static void CreateDataBaseTemplate()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Creating an empty PetaPoco database");
|
Console.WriteLine("Creating an empty PetaPoco database");
|
||||||
var connectionString = Connection.GetConnectionString(DB_TEMPLATE_NAME);
|
var connectionString = Connection.GetConnectionString(DB_TEMPLATE_NAME);
|
||||||
var database = Connection.GetPetaPocoDb(connectionString);
|
var database = Connection.GetPetaPocoDb(connectionString);
|
||||||
database.Dispose();
|
database.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Series GetFakeSeries(int id, string title)
|
|
||||||
{
|
|
||||||
return Builder<Series>.CreateNew()
|
|
||||||
.With(c => c.SeriesId = id)
|
|
||||||
.With(c => c.Title = title)
|
|
||||||
.With(c => c.CleanTitle = Parser.NormalizeTitle(title))
|
|
||||||
.Build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,14 +3,12 @@ using System.Linq;
|
||||||
|
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
|
@ -134,14 +132,16 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
|
|
||||||
Db.Insert(TestDbHelper.GetFakeSeries(1, "MyTitle"));
|
var fakeSEries = Builder<Series>.CreateNew()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Db.Insert(fakeSEries);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var seriesProvider = Mocker.Resolve<SeriesProvider>();
|
var seriesProvider = Mocker.Resolve<SeriesProvider>();
|
||||||
var series = seriesProvider.FindSeries("WrongTitle");
|
|
||||||
|
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Assert.IsNull(series);
|
seriesProvider.FindSeries("WrongTitle").Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("The Test", "Test")]
|
[TestCase("The Test", "Test")]
|
||||||
|
@ -150,19 +150,25 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
|
|
||||||
Db.Insert(TestDbHelper.GetFakeSeries(1, title));
|
var fakeSeries = Builder<Series>.CreateNew()
|
||||||
Db.Insert(Builder<QualityProfile>.CreateNew().Build());
|
.With(c => c.Title = title)
|
||||||
Mocker.Resolve<QualityProvider>();
|
.With(c => c.CleanTitle = Parser.NormalizeTitle(title))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var fakeQuality = Builder<QualityProfile>.CreateNew()
|
||||||
|
.With(c => c.QualityProfileId = fakeSeries.QualityProfileId)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Db.Insert(fakeSeries);
|
||||||
|
Db.Insert(fakeQuality);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var seriesProvider = Mocker.Resolve<SeriesProvider>();
|
var series = Mocker.Resolve<SeriesProvider>().FindSeries(searchTitle);
|
||||||
var series = seriesProvider.FindSeries(searchTitle);
|
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Assert.IsNotNull(series);
|
series.Should().NotBeNull();
|
||||||
Assert.AreEqual(title, series.Title);
|
series.SeriesId.Should().Be(series.SeriesId);
|
||||||
series.QualityProfile.Should().NotBeNull();
|
series.Title.Should().BeEquivalentTo(series.Title);
|
||||||
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.AllowedString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
Loading…
Reference in New Issue