Removed the service locator from the base classes and added in some Api tests

added all the tests back in!
This commit is contained in:
tidusjar 2016-05-19 17:02:46 +01:00
commit 84dc4515fd
21 changed files with 251 additions and 176 deletions

View file

@ -25,6 +25,7 @@
// ************************************************************************/
#endregion
using System.Collections.Generic;
using System.Linq;
using Moq;
@ -32,6 +33,7 @@ using Nancy;
using Nancy.Testing;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
@ -50,7 +52,6 @@ using PlexRequests.UI.Helpers;
namespace PlexRequests.UI.Tests
{
[TestFixture]
[Ignore("Needs rework")]
public class AdminModuleTests
{
private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
@ -71,6 +72,7 @@ namespace PlexRequests.UI.Tests
private Mock<IRepository<LogEntity>> LogRepo { get; set; }
private Mock<INotificationService> NotificationService { get; set; }
private Mock<ICacheProvider> Cache { get; set; }
private Mock<ISettingsService<LogSettings>> Log { get; set; }
private ConfigurableBootstrapper Bootstrapper { get; set; }
@ -83,9 +85,10 @@ namespace PlexRequests.UI.Tests
PlexMock = new Mock<IPlexApi>();
PlexMock.Setup(x => x.SignIn("Username1", "Password1"))
.Returns(new PlexAuthentication { user = new User { authentication_token = "abc", username = "Username1" } });
.Returns(new PlexAuthentication { user = new User { authentication_token = "abc", title = "Username1" } });
PlexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
PlexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
CpMock = new Mock<ISettingsService<CouchPotatoSettings>>();
PlexSettingsMock = new Mock<ISettingsService<PlexSettings>>();
SonarrApiMock = new Mock<ISonarrApi>();
@ -101,6 +104,7 @@ namespace PlexRequests.UI.Tests
NotificationService = new Mock<INotificationService>();
HeadphonesSettings = new Mock<ISettingsService<HeadphonesSettings>>();
Cache = new Mock<ICacheProvider>();
Log = new Mock<ISettingsService<LogSettings>>();
Bootstrapper = new ConfigurableBootstrapper(with =>
{
@ -123,16 +127,11 @@ namespace PlexRequests.UI.Tests
with.Dependency(NotificationService.Object);
with.Dependency(HeadphonesSettings.Object);
with.Dependency(Cache.Object);
with.ApplicationStartup(
(container, pipelines) =>
{
var loc = ServiceLocator.Instance;
loc.SetContainer(container);
});
with.Dependency(Log.Object);
with.RootPathProvider<TestRootPathProvider>();
with.RequestStartup((container, pipelines, context) =>
{
context.CurrentUser = new UserIdentity { UserName = "user" };
context.CurrentUser = new UserIdentity { UserName = "user", Claims = new List<string> {"Admin"} };
});
});
@ -240,7 +239,7 @@ namespace PlexRequests.UI.Tests
[Test]
public void GetUsersSuccessfully()
{
var users = new PlexFriends { User = new[] { new UserFriends { Username = "abc2" }, } };
var users = new PlexFriends { User = new[] { new UserFriends { Title = "abc2" }, } };
PlexMock.Setup(x => x.GetUsers(It.IsAny<string>())).Returns(users);
var browser = new Browser(Bootstrapper);
@ -255,9 +254,11 @@ namespace PlexRequests.UI.Tests
Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
var body = result.Body.AsString();
var body = JsonConvert.DeserializeObject<JObject>(result.Body.AsString());
var user = body["users"];
Assert.That(body, Is.Not.Null);
Assert.That(body, Contains.Substring("abc2"));
Assert.That(user.ToString().Contains("abc"), Is.True);
PlexMock.Verify(x => x.GetUsers(It.IsAny<string>()), Times.Once);
AuthMock.Verify(x => x.GetSettings(), Times.Once);
@ -276,6 +277,7 @@ namespace PlexRequests.UI.Tests
with.Header("Accept", "application/json");
with.FormValue("username", "Username1");
with.FormValue("password", "Password1");
});