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.
Radarr/NzbDrone.Core.Test/ProviderTests/SeasonProviderTest.cs

194 lines
5.4 KiB

// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
using PetaPoco;
using TvdbLib.Data;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SeasonProviderTest : CoreTest
{
[Test]
public void AddSeason_should_insert_season_to_database_with_ignored_false()
{
WithRealDb();
var seriesId = 10;
var seasonNumber = 50;
//Act
Mocker.Resolve<SeasonProvider>().Add(seriesId, seasonNumber);
//Assert
var result = Db.Fetch<Season>();
result.Should().HaveCount(1);
result.First().SeriesId.Should().Be(seriesId);
result.First().SeasonNumber.Should().Be(seasonNumber);
result.First().Ignored.Should().BeFalse();
}
[TestCase(true)]
[TestCase(false)]
public void AddSeason_should_insert_season_to_database_with_preset_ignored_status(bool isIgnored)
{
WithRealDb();
var seriesId = 10;
var seasonNumber = 50;
//Act
Mocker.Resolve<SeasonProvider>().Add(seriesId, seasonNumber, isIgnored);
//Assert
var result = Db.Fetch<Season>();
result.Should().HaveCount(1);
result.First().SeriesId.Should().Be(seriesId);
result.First().SeasonNumber.Should().Be(seasonNumber);
result.First().Ignored.Should().Be(isIgnored);
}
[Test]
public void DeleteSeason_should_remove_season_from_database()
{
WithRealDb();
var fakeSeason = Builder<Season>.CreateNew().Build();
Db.Insert(fakeSeason);
//Act
Mocker.Resolve<SeasonProvider>().Delete(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
//Assert
var result = Db.Fetch<Season>();
result.Should().BeEmpty();
}
[Test]
public void SetIgnore_should_update_ignored_status()
{
WithRealDb();
var fakeSeason = Builder<Season>.CreateNew()
.With(s => s.Ignored = false)
.Build();
var id = Db.Insert(fakeSeason);
//Act
Mocker.Resolve<SeasonProvider>().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, true);
//Assert
var result = Db.SingleOrDefault<Season>(id);
result.Ignored.Should().BeTrue();
}
[Test]
public void IsIgnored_should_return_ignored_status_of_season()
{
//Setup
var fakeSeason = Builder<Season>.CreateNew()
.With(s => s.Ignored = false)
.Build();
Db.Insert(fakeSeason);
//Act
var result = Mocker.Resolve<SeasonProvider>().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
//Assert
result.Should().Be(fakeSeason.Ignored);
Db.Fetch<Season>().Count.Should().Be(1);
}
[Test]
public void IsIgnored_should_return_true_if_not_in_db_and_is_season_zero()
{
//Setup
WithRealDb();
//Act
var result = Mocker.Resolve<SeasonProvider>().IsIgnored(10, 0);
//Assert
result.Should().BeTrue();
Db.Fetch<Season>().Should().HaveCount(1);
}
[Test]
public void IsIgnored_should_return_false_if_not_in_db_and_is_season_one()
{
//Setup
WithRealDb();
//Act
var result = Mocker.Resolve<SeasonProvider>().IsIgnored(10, 1);
//Assert
result.Should().BeFalse();
Db.Fetch<Season>().Should().HaveCount(1);
}
[Test]
public void IsIgnored_should_return_false_if_not_in_db_and_previous_season_is_not_ignored()
{
//Setup
WithRealDb();
var lastSeason = Builder<Season>.CreateNew()
.With(s => s.SeriesId = 10)
.With(s => s.SeasonNumber = 4)
.With(s => s.Ignored = true)
.Build();
Db.Insert(lastSeason);
//Act
var result = Mocker.Resolve<SeasonProvider>().IsIgnored(10, 5);
//Assert
result.Should().BeFalse();
Db.Fetch<Season>().Should().HaveCount(2);
}
[Test]
public void IsIgnored_should_return_true_if_not_in_db_and_previous_season_is_ignored()
{
//Setup
WithRealDb();
var lastSeason = Builder<Season>.CreateNew()
.With(s => s.SeriesId = 10)
.With(s => s.SeasonNumber = 4)
.With(s => s.Ignored = true)
.Build();
Db.Insert(lastSeason);
//Act
var result = Mocker.Resolve<SeasonProvider>().IsIgnored(10, 5);
//Assert
result.Should().BeTrue();
Db.Fetch<Season>().Should().HaveCount(2);
}
}
}