sonarr-repo-only/NzbDrone.Core.Test/Datastore/SQLiteMigrationHelperFixtur...

110 lines
3.4 KiB
C#
Raw Normal View History

2013-09-01 19:07:48 +00:00
using System.Collections.Generic;
using FizzWare.NBuilder;
2013-07-05 03:56:27 +00:00
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
2013-09-03 04:55:04 +00:00
using System.Linq;
2013-07-05 03:56:27 +00:00
namespace NzbDrone.Core.Test.Datastore
{
[TestFixture]
public class SQLiteMigrationHelperFixture : DbTest
{
private SQLiteMigrationHelper _subject;
[SetUp]
public void SetUp()
{
_subject = Mocker.Resolve<SQLiteMigrationHelper>();
}
[Test]
public void should_parse_existing_columns()
{
var columns = _subject.GetColumns("Series");
columns.Should().NotBeEmpty();
columns.Values.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Name));
columns.Values.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Schema));
}
[Test]
public void should_create_table_from_column_list()
{
var columns = _subject.GetColumns("Series");
columns.Remove("Title");
2013-09-01 19:07:48 +00:00
_subject.CreateTable("Series_New", columns.Values, new List<SQLiteMigrationHelper.SQLiteIndex>());
2013-07-05 03:56:27 +00:00
var newColumns = _subject.GetColumns("Series_New");
newColumns.Values.Should().HaveSameCount(columns.Values);
newColumns.Should().NotContainKey("Title");
}
[Test]
public void should_be_able_to_transfer_empty_tables()
{
var columns = _subject.GetColumns("Series");
2013-09-03 04:55:04 +00:00
var indexes = _subject.GetIndexes("Series");
2013-07-05 03:56:27 +00:00
columns.Remove("Title");
2013-09-03 04:55:04 +00:00
_subject.CreateTable("Series_New", columns.Values, indexes);
2013-07-05 03:56:27 +00:00
_subject.CopyData("Series", "Series_New", columns.Values);
}
[Test]
public void should_transfer_table_with_data()
{
var originalEpisodes = Builder<Episode>.CreateListOfSize(10).BuildListOfNew();
Mocker.Resolve<EpisodeRepository>().InsertMany(originalEpisodes);
var columns = _subject.GetColumns("Episodes");
2013-09-03 04:55:04 +00:00
var indexes = _subject.GetIndexes("Episodes");
2013-07-05 03:56:27 +00:00
columns.Remove("Title");
2013-09-03 04:55:04 +00:00
_subject.CreateTable("Episodes_New", columns.Values, indexes);
2013-07-05 03:56:27 +00:00
_subject.CopyData("Episodes", "Episodes_New", columns.Values);
_subject.GetRowCount("Episodes_New").Should().Be(originalEpisodes.Count);
}
2013-09-01 19:07:48 +00:00
[Test]
public void should_read_existing_indexes()
{
var indexes = _subject.GetIndexes("QualitySizes");
indexes.Should().NotBeEmpty();
indexes.Should().OnlyContain(c => c != null);
indexes.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Column));
indexes.Should().OnlyContain(c => c.Table == "QualitySizes");
indexes.Should().OnlyContain(c => c.Unique);
}
[Test]
public void should_add_indexes_when_creating_new_table()
{
var columns = _subject.GetColumns("QualitySizes");
var indexes = _subject.GetIndexes("QualitySizes");
_subject.CreateTable("QualityB", columns.Values, indexes);
var newIndexes = _subject.GetIndexes("QualityB");
newIndexes.Should().HaveSameCount(indexes);
2013-09-03 04:55:04 +00:00
newIndexes.Select(c=>c.Column).Should().BeEquivalentTo(indexes.Select(c=>c.Column));
2013-09-01 19:07:48 +00:00
}
2013-07-05 03:56:27 +00:00
}
}