You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/NzbDrone.Core.Test/Framework/MockLib.cs

57 lines
1.7 KiB

// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
14 years ago
using FizzWare.NBuilder;
using Moq;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Providers.Core;
14 years ago
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
14 years ago
using PetaPoco;
namespace NzbDrone.Core.Test.Framework
{
/// <summary>
/// Provides the standard Mocks needed for a typical test
/// </summary>
internal static class MockLib
{
private const string DbTemplateName = "_dbtemplate.sdf";
14 years ago
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
{
Console.WriteLine("Cloning database from template.");
14 years ago
if (String.IsNullOrWhiteSpace(fileName))
{
fileName = Guid.NewGuid() + ".sdf";
14 years ago
}
File.Copy(DbTemplateName, fileName);
14 years ago
var connectionString = Connection.GetConnectionString(fileName);
14 years ago
var database = Connection.GetPetaPocoDb(connectionString);
return database;
}
public static void CreateDataBaseTemplate()
{
Console.WriteLine("Creating an empty PetaPoco database");
var connectionString = Connection.GetConnectionString(DbTemplateName);
var database = Connection.GetPetaPocoDb(connectionString);
database.Dispose();
}
public static Series GetFakeSeries(int id, string title)
14 years ago
{
return Builder<Series>.CreateNew()
.With(c => c.SeriesId = id)
.With(c => c.Title = title)
.With(c => c.CleanTitle = Parser.NormalizeTitle(title))
.Build();
}
}
}