From ba5ccfec3312cd40ec6da90606151d3ea4a79d82 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 15 Mar 2016 12:21:41 +0000 Subject: [PATCH] Fixed #5 and also added some tests to the availability checker --- .../PlexAvailabilityCheckerTests.cs | 102 ++++++++++++++++ .../PlexRequests.Services.Tests.csproj | 113 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ PlexRequests.Services.Tests/packages.config | 5 + .../AvailabilityUpdateService.cs | 3 +- .../Interfaces/IAvailabilityChecker.cs | 1 + .../PlexAvailabilityChecker.cs | 68 +++++++++-- .../PlexRequests.UI.Tests.csproj | 4 +- PlexRequests.UI.Tests/packages.config | 2 +- PlexRequests.UI/Modules/SearchModule.cs | 47 +++++--- PlexRequests.sln | 6 + 11 files changed, 356 insertions(+), 31 deletions(-) create mode 100644 PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs create mode 100644 PlexRequests.Services.Tests/PlexRequests.Services.Tests.csproj create mode 100644 PlexRequests.Services.Tests/Properties/AssemblyInfo.cs create mode 100644 PlexRequests.Services.Tests/packages.config diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs new file mode 100644 index 000000000..44f960c87 --- /dev/null +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -0,0 +1,102 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: PlexAvailabilityCheckerTests.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +using System; +using System.Collections.Generic; + +using Moq; + +using NUnit.Framework; + +using PlexRequests.Api.Interfaces; +using PlexRequests.Api.Models; +using PlexRequests.Core; +using PlexRequests.Core.SettingModels; +using PlexRequests.Helpers.Exceptions; +using PlexRequests.Services.Interfaces; + +namespace PlexRequests.Services.Tests +{ + [TestFixture] + public class PlexAvailabilityCheckerTests + { + public IAvailabilityChecker Checker { get; set; } + + [Test] + public void IsAvailableWithEmptySettingsTest() + { + var settingsMock = new Mock>(); + var authMock = new Mock>(); + var requestMock = new Mock(); + var plexMock = new Mock(); + Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); + + Assert.Throws(() => Checker.IsAvailable("title"), "We should be throwing an exception since we cannot talk to the services."); + } + + [Test] + public void IsAvailableTest() + { + var settingsMock = new Mock>(); + var authMock = new Mock>(); + var requestMock = new Mock(); + var plexMock = new Mock(); + + var searchResult = new PlexSearch {Video = new List