HttpClient

This commit is contained in:
Keivan Beigi
2014-09-11 16:49:41 -07:00
parent 3a287bf7e7
commit 2c1d3339d0
55 changed files with 995 additions and 582 deletions
@@ -1,53 +1,33 @@
using System;
using System.Net;
using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Common.Http;
using NzbDrone.Core.DataAugmentation.Scene;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.Categories;
namespace NzbDrone.Core.Test.DataAugmentationFixture.Scene
{
[TestFixture]
[IntegrationTest]
public class SceneMappingProxyFixture : CoreTest<SceneMappingProxy>
{
private const string SCENE_MAPPING_URL = "http://services.nzbdrone.com/v1/SceneMapping";
[SetUp]
public void Setup()
{
UseRealHttp();
}
[Test]
public void fetch_should_return_list_of_mappings()
{
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(SCENE_MAPPING_URL))
.Returns(ReadAllText("Files", "SceneMappings.json"));
var mappings = Subject.Fetch();
mappings.Should().NotBeEmpty();
mappings.Should().NotContain(c => String.IsNullOrWhiteSpace(c.SearchTerm));
mappings.Should().NotContain(c => String.IsNullOrWhiteSpace(c.Title));
mappings.Should().NotContain(c => c.TvdbId == 0);
mappings.Should().NotContain(c => c.SearchTerm.IsNullOrWhiteSpace());
mappings.Should().NotContain(c => c.Title.IsNullOrWhiteSpace());
mappings.Should().Contain(c => c.SeasonNumber > 0);
}
[Test]
public void should_throw_on_server_error()
{
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(SCENE_MAPPING_URL))
.Throws(new WebException());
Assert.Throws<WebException>(() => Subject.Fetch());
}
[Test]
public void should_throw_on_bad_json()
{
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(SCENE_MAPPING_URL))
.Returns("bad json");
Assert.Throws<JsonReaderException>(() => Subject.Fetch());
}
}
}