Fixed: History Repo GetById not always ordered by Date

pull/2/head
Qstick 5 years ago
parent 415c2821c8
commit 975d31178b

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
@ -57,5 +59,58 @@ namespace NzbDrone.Core.Test.HistoryTests
downloadHistory.Should().HaveCount(1); downloadHistory.Should().HaveCount(1);
} }
[Test]
public void should_get_movie_history()
{
var historyMovie1 = Builder<History.History>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.BuildNew();
var historyMovie2 = Builder<History.History>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 13)
.With(c => c.EventType = HistoryEventType.Grabbed)
.BuildNew();
Subject.Insert(historyMovie1);
Subject.Insert(historyMovie2);
var movieHistory = Subject.GetByMovieId(12, null);
movieHistory.Should().HaveCount(1);
}
[Test]
public void should_sort_movie_history_by_date()
{
var historyFirst = Builder<History.History>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.MovieFileRenamed)
.With(c => c.Date = DateTime.UtcNow)
.BuildNew();
var historySecond = Builder<History.History>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.Bluray1080p))
.With(c => c.Languages = new List<Language> { Language.English })
.With(c => c.MovieId = 12)
.With(c => c.EventType = HistoryEventType.Grabbed)
.With(c => c.Date = DateTime.UtcNow.AddMinutes(10))
.BuildNew();
Subject.Insert(historyFirst);
Subject.Insert(historySecond);
var movieHistory = Subject.GetByMovieId(12, null);
movieHistory.Should().HaveCount(2);
movieHistory.First().EventType.Should().Be(HistoryEventType.Grabbed);
}
} }
} }

@ -66,9 +66,7 @@ namespace NzbDrone.Core.History
query = query.Where(h => h.EventType == eventType).ToList(); query = query.Where(h => h.EventType == eventType).ToList();
} }
query.OrderByDescending(h => h.Date); return query.OrderByDescending(h => h.Date).ToList();
return query;
} }
public void DeleteForMovie(int movieId) public void DeleteForMovie(int movieId)

Loading…
Cancel
Save