aFixed QualityProfile storage test

This commit is contained in:
Keivan 2010-09-29 23:59:00 -07:00
parent 27164d422c
commit 899e5a9a22
6 changed files with 69 additions and 10 deletions

View File

@ -0,0 +1,27 @@
using System;
using System.IO;
using MbUnit.Framework;
namespace NzbDrone.Core.Test
{
[AssemblyFixture]
public class Fixtures
{
[TearDown]
public void TearDown()
{
var dbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.testdb");
foreach (var dbFile in dbFiles)
{
try
{
File.Delete(dbFile);
}
catch
{ }
}
}
}
}

View File

@ -19,14 +19,15 @@ namespace NzbDrone.Core.Test
get { return new string[] { "C:\\TV\\The Simpsons", "C:\\TV\\Family Guy" }; }
}
public const string MemoryConnection = "Data Source=:memory:;Version=3;New=True";
public static IRepository MemoryRepository
public static IRepository EmptyRepository
{
get
{
var provider = ProviderFactory.GetProvider(MemoryConnection, "System.Data.SQLite");
var provider = ProviderFactory.GetProvider("Data Source=" + Guid.NewGuid() + ".testdb;Version=3;New=True", "System.Data.SQLite");
return new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
}
}

View File

@ -69,6 +69,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DbConfigControllerTest.cs" />
<Compile Include="Fixtures.cs" />
<Compile Include="MockLib.cs" />
<Compile Include="Ninject.Moq\ExtensionsForBindingSyntax.cs" />
<Compile Include="Ninject.Moq\MockingKernel.cs" />

View File

@ -1,6 +1,8 @@
using System.Reflection;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using MbUnit.Framework;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.IO;
using MbUnit.Framework;
using NzbDrone.Core.Repository;
@ -14,12 +16,13 @@ namespace NzbDrone.Core.Test
[Test]
public void Test_Storage()
{
//Arrange
var repo = MockLib.MemoryRepository;
var repo = MockLib.EmptyRepository;
var testProfile = new QualityProfile
{
Cutoff = Quality.SDTV,
Q = new[] { Quality.HDTV, Quality.DVD }
Allowed = new List<Quality>() { Quality.HDTV, Quality.DVD },
};
//Act
@ -29,8 +32,7 @@ namespace NzbDrone.Core.Test
//Assert
Assert.AreEqual(id, fetch.Id);
Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff);
Assert.AreEqual(testProfile.Qualitys, fetch.Qualitys);
Assert.AreElementsEqual(testProfile.Q, fetch.Q);
Assert.AreEqual(testProfile.Allowed, fetch.Allowed);
}
}
}

View File

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository
{
@ -9,7 +11,31 @@ namespace NzbDrone.Core.Repository
{
public int Id { get; set; }
public Quality Cutoff { get; set; }
public string Qualitys { get; set; }
public Quality[] Q { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public string SonicAllowed
{
get
{
string result = String.Empty;
foreach (var q in Allowed)
{
result += (int)q + "|";
}
return result.Trim('|');
}
private set
{
var qualities = value.Split('|');
Allowed = new List<Quality>(qualities.Length);
foreach (var quality in qualities)
{
Allowed.Add((Quality)Convert.ToInt32(quality));
}
}
}
[SubSonicIgnore]
public List<Quality> Allowed { get; set; }
}
}