Better handling of xml errors on tvrage

This commit is contained in:
Mark McDowall 2012-12-22 17:18:05 -08:00
commit 2bd866f590
7 changed files with 152 additions and 55 deletions

View file

@ -0,0 +1,36 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.HelperTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SortHelperTest : CoreTest
{
[TestCase("The Office (US)", "Office (US)")]
[TestCase("A Man in Anger", "Man in Anger")]
[TestCase("An Idiot Abroad", "Idiot Abroad")]
[TestCase("American Gladiators", "American Gladiators")]
[TestCase("Ancient Apocalyps", "Ancient Apocalyps")]
[TestCase("There Will Be Brawl", "There Will Be Brawl")]
[TestCase("30 Rock", "30 Rock")]
[TestCase(null, "")]
public void SkipArticles(string title, string expected)
{
var result = title.IgnoreArticles();
result.Should().Be(expected);
}
}
}

View file

@ -0,0 +1,67 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using FluentAssertions;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using TvdbLib.Data;
using TvdbLib.Exceptions;
namespace NzbDrone.Core.Test.HelperTests.XElementHelperTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class ParseDayOfWeekFixture : CoreTest
{
[Test]
public void should_return_null_if_xelement_is_null()
{
XElement test = null;
test.ConvertToDayOfWeek().Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_null()
{
new XElement("airday", null).ConvertToDayOfWeek().Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_empty()
{
new XElement("airday", "").ConvertToDayOfWeek().Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_daily()
{
new XElement("airday", "Daily").ConvertToDayOfWeek().Should().Be(null);
}
[Test]
public void should_return_null_if_value_is_weekdays()
{
Mocker.Resolve<TvRageProvider>().ParseDayOfWeek(new XElement("airday", "Weekdays")).Should().Be(null);
}
[TestCase("Sunday", DayOfWeek.Sunday)]
[TestCase("Monday", DayOfWeek.Monday)]
[TestCase("Tuesday", DayOfWeek.Tuesday)]
[TestCase("Wednesday", DayOfWeek.Wednesday)]
[TestCase("Thursday", DayOfWeek.Thursday)]
[TestCase("Friday", DayOfWeek.Friday)]
[TestCase("Saturday", DayOfWeek.Saturday)]
public void should_return_dayOfWeek_when_it_is_valid(string value, DayOfWeek expected)
{
new XElement("airday", value).ConvertToDayOfWeek().Should().Be(expected);
}
}
}

View file

@ -0,0 +1,70 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.HelperTests.XElementHelperTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class XElementHelperTest : CoreTest
{
[Test]
public void Int32_should_return_zero_when_xelement_is_null()
{
XElement test = null;
test.ConvertTo<Int32>().Should().Be(0);
}
[Test]
public void Int32_should_return_zero_when_value_is_null()
{
new XElement("test", null).ConvertTo<Int32>().Should().Be(0);
}
[Test]
public void Int32_should_return_value_when_value_is_an_int()
{
new XElement("test", 10).ConvertTo<Int32>().Should().Be(10);
}
[Test]
public void Nullable_Int32_should_return_null_when_xelement_is_null()
{
XElement test = null;
test.ConvertTo<Nullable<Int32>>().Should().Be(null);
}
[Test]
public void DateTime_should_return_zero_when_xelement_is_null()
{
XElement test = null;
test.ConvertTo<DateTime>().Should().Be(DateTime.MinValue);
}
[Test]
public void DateTime_should_return_zero_when_value_is_null()
{
new XElement("test", null).ConvertTo<DateTime>().Should().Be(DateTime.MinValue);
}
[Test]
public void DateTime_should_return_value_when_value_is_a_date()
{
var date = DateTime.Today;
new XElement("test", date.ToString()).ConvertTo<DateTime>().Should().Be(date);
}
}
}