New: Rebuilt Completed/Failed download handling from scratch

This commit is contained in:
Keivan Beigi
2014-12-18 16:26:42 -08:00
parent 264bb66c16
commit a6d34caf2c
79 changed files with 1221 additions and 2389 deletions
@@ -1,5 +1,4 @@
using System;
using FizzWare.NBuilder;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.History;
@@ -11,25 +10,6 @@ namespace NzbDrone.Core.Test.HistoryTests
[TestFixture]
public class HistoryRepositoryFixture : DbTest<HistoryRepository, History.History>
{
[Test]
public void Trim_Items()
{
var historyItem = Builder<History.History>.CreateListOfSize(30)
.All()
.With(c => c.Id = 0)
.With(c => c.Quality = new QualityModel())
.TheFirst(10).With(c => c.Date = DateTime.Now)
.TheNext(20).With(c => c.Date = DateTime.Now.AddDays(-31))
.Build();
Db.InsertMany(historyItem);
AllStoredModels.Should().HaveCount(30);
Subject.Trim();
AllStoredModels.Should().HaveCount(10);
AllStoredModels.Should().OnlyContain(s => s.Date > DateTime.Now.AddDays(-30));
}
[Test]
public void should_read_write_dictionary()
@@ -38,29 +18,37 @@ namespace NzbDrone.Core.Test.HistoryTests
.With(c => c.Quality = new QualityModel())
.BuildNew();
history.Data.Add("key1","value1");
history.Data.Add("key2","value2");
history.Data.Add("key1", "value1");
history.Data.Add("key2", "value2");
Subject.Insert(history);
StoredModel.Data.Should().HaveCount(2);
}
[Test]
public void grabbed_should_return_grabbed_items()
public void should_get_download_history()
{
var history = Builder<History.History>
.CreateListOfSize(5)
.All()
.With(c => c.Quality = new QualityModel())
.With(c => c.EventType = HistoryEventType.Unknown)
.Random(3)
var historyBluray = Builder<History.History>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.SeriesId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.BuildListOfNew();
.BuildNew();
Subject.InsertMany(history);
var historyDvd = Builder<History.History>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.DVD))
.With(c => c.SeriesId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.BuildNew();
Subject.Grabbed().Should().HaveCount(3);
Subject.Insert(historyBluray);
Subject.Insert(historyDvd);
var downloadHistory = Subject.FindDownloadHistory(12, new QualityModel(Quality.Bluray1080p));
downloadHistory.Should().HaveCount(1);
}
}
}
@@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.HistoryTests
Path = @"C:\Test\Unsorted\Series.s01e01.mkv"
};
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true));
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true, "sab","abcd"));
Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));