mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 03:28:28 -07:00
Fixed all the unit tests
This commit is contained in:
parent
ae9a4e3b1c
commit
41ebce7cae
14 changed files with 238 additions and 39 deletions
|
@ -181,7 +181,7 @@ namespace Ombi.Core.Tests.Engine
|
||||||
yield return new TestCaseData(new AvailabilityTestModel
|
yield return new TestCaseData(new AvailabilityTestModel
|
||||||
{
|
{
|
||||||
Approved = true
|
Approved = true
|
||||||
}).Returns("teal").SetName("Calendar_ApprovedRequest");
|
}).Returns("blue").SetName("Calendar_ApprovedRequest");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,13 @@
|
||||||
<PackageReference Include="Nunit" Version="3.11.0" />
|
<PackageReference Include="Nunit" Version="3.11.0" />
|
||||||
<PackageReference Include="NUnit.ConsoleRunner" Version="3.9.0" />
|
<PackageReference Include="NUnit.ConsoleRunner" Version="3.9.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
||||||
<packagereference Include="Microsoft.NET.Test.Sdk" Version="16.0.1"></packagereference>
|
<packagereference Include="Microsoft.NET.Test.Sdk" Version="16.0.1"></packagereference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\Ombi.Test.Common\Ombi.Test.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -6,28 +6,41 @@ using Ombi.Store.Entities.Requests;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Ombi.Core.Authentication;
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
|
using Ombi.Test.Common;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Request
|
namespace Ombi.Core.Tests.Rule.Request
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class AutoApproveRuleTests
|
public class AutoApproveRuleTests
|
||||||
{
|
{
|
||||||
|
private List<OmbiUser> _users = new List<OmbiUser>
|
||||||
|
{
|
||||||
|
new OmbiUser { Id = Guid.NewGuid().ToString("N"), UserName="abc" }
|
||||||
|
};
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
PrincipalMock = new Mock<IPrincipal>();
|
PrincipalMock = new Mock<IPrincipal>();
|
||||||
Rule = new AutoApproveRule(PrincipalMock.Object, null);
|
PrincipalMock.Setup(x => x.Identity.Name).Returns("abc");
|
||||||
|
|
||||||
|
UserManager = MockHelper.MockUserManager(_users);
|
||||||
|
Rule = new AutoApproveRule(PrincipalMock.Object, UserManager.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private AutoApproveRule Rule { get; set; }
|
private AutoApproveRule Rule { get; set; }
|
||||||
private Mock<IPrincipal> PrincipalMock { get; set; }
|
private Mock<IPrincipal> PrincipalMock { get; set; }
|
||||||
|
private Mock<OmbiUserManager> UserManager { get; set; }
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAdminAndRequestMovie()
|
public async Task Should_ReturnSuccess_WhenAdminAndRequestMovie()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Admin)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -38,7 +51,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAdminAndRequestTV()
|
public async Task Should_ReturnSuccess_WhenAdminAndRequestTV()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Admin)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -49,7 +62,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie()
|
public async Task Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.AutoApproveMovie)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveMovie)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -57,10 +70,21 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.True(request.Approved);
|
Assert.True(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Should_ReturnFail_WhenAutoApproveMovie_And_RequestTV()
|
||||||
|
{
|
||||||
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveMovie)).ReturnsAsync(true);
|
||||||
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.False(request.Approved);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV()
|
public async Task Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.AutoApproveTv)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveTv)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -68,9 +92,21 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.True(request.Approved);
|
Assert.True(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Should_ReturnFail_WhenAutoApproveTV_And_RequestMovie()
|
||||||
|
{
|
||||||
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveTv)).ReturnsAsync(true);
|
||||||
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.False(request.Approved);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie()
|
public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie()
|
||||||
{
|
{
|
||||||
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), It.IsAny<string>())).ReturnsAsync(false);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -81,6 +117,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenNoClaimsAndRequestTV()
|
public async Task Should_ReturnFail_WhenNoClaimsAndRequestTV()
|
||||||
{
|
{
|
||||||
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), It.IsAny<string>())).ReturnsAsync(false);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,46 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Core.Rule.Rules;
|
using Ombi.Core.Rule.Rules;
|
||||||
using Ombi.Core.Rule.Rules.Request;
|
using Ombi.Core.Rule.Rules.Request;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
using Ombi.Test.Common;
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Request
|
namespace Ombi.Core.Tests.Rule.Request
|
||||||
{
|
{
|
||||||
public class CanRequestRuleTests
|
public class CanRequestRuleTests
|
||||||
{
|
{
|
||||||
|
private List<OmbiUser> _users = new List<OmbiUser>
|
||||||
|
{
|
||||||
|
new OmbiUser { Id = Guid.NewGuid().ToString("N"), UserName="abc" }
|
||||||
|
};
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
PrincipalMock = new Mock<IPrincipal>();
|
PrincipalMock = new Mock<IPrincipal>();
|
||||||
Rule = new CanRequestRule(PrincipalMock.Object, null);
|
PrincipalMock.Setup(x => x.Identity.Name).Returns("abc");
|
||||||
|
|
||||||
|
UserManager = MockHelper.MockUserManager(_users);
|
||||||
|
Rule = new CanRequestRule(PrincipalMock.Object, UserManager.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private CanRequestRule Rule { get; set; }
|
private CanRequestRule Rule { get; set; }
|
||||||
private Mock<IPrincipal> PrincipalMock { get; set; }
|
private Mock<IPrincipal> PrincipalMock { get; set; }
|
||||||
|
private Mock<OmbiUserManager> UserManager { get; set; }
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingMovieWithMovieRole()
|
public async Task Should_ReturnSuccess_WhenRequestingMovieWithMovieRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestMovie)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestMovie)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -36,7 +50,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenRequestingMovieWithoutMovieRole()
|
public async Task Should_ReturnFail_WhenRequestingMovieWithoutMovieRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestMovie)).Returns(false);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestMovie)).ReturnsAsync(false);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -47,7 +61,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingMovieWithAdminRole()
|
public async Task Should_ReturnSuccess_WhenRequestingMovieWithAdminRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Admin)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -57,7 +71,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingTVWithAdminRole()
|
public async Task Should_ReturnSuccess_WhenRequestingTVWithAdminRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Admin)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -67,7 +81,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingTVWithTVRole()
|
public async Task Should_ReturnSuccess_WhenRequestingTVWithTVRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestTv)).Returns(true);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestTv)).ReturnsAsync(true);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
@ -77,7 +91,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenRequestingTVWithoutTVRole()
|
public async Task Should_ReturnFail_WhenRequestingTVWithoutTVRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestTv)).Returns(false);
|
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestTv)).ReturnsAsync(false);
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
var result = await Rule.Execute(request);
|
var result = await Rule.Execute(request);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Ombi.Core.Models.Search;
|
using Ombi.Core.Models.Search;
|
||||||
using Ombi.Core.Rule.Rules.Search;
|
using Ombi.Core.Rule.Rules.Search;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Core.Settings.Models.External;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
using Ombi.Store.Repository.Requests;
|
using Ombi.Store.Repository.Requests;
|
||||||
|
@ -16,15 +18,18 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
ContextMock = new Mock<IEmbyContentRepository>();
|
ContextMock = new Mock<IEmbyContentRepository>();
|
||||||
Rule = new EmbyAvailabilityRule(ContextMock.Object, null);
|
SettingsMock = new Mock<ISettingsService<EmbySettings>>();
|
||||||
|
Rule = new EmbyAvailabilityRule(ContextMock.Object, SettingsMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmbyAvailabilityRule Rule { get; set; }
|
private EmbyAvailabilityRule Rule { get; set; }
|
||||||
private Mock<IEmbyContentRepository> ContextMock { get; set; }
|
private Mock<IEmbyContentRepository> ContextMock { get; set; }
|
||||||
|
private Mock<ISettingsService<EmbySettings>> SettingsMock { get; set; }
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Movie_ShouldBe_Available_WhenFoundInEmby()
|
public async Task Movie_ShouldBe_Available_WhenFoundInEmby()
|
||||||
{
|
{
|
||||||
|
SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new EmbySettings());
|
||||||
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).ReturnsAsync(new EmbyContent
|
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).ReturnsAsync(new EmbyContent
|
||||||
{
|
{
|
||||||
ProviderId = "123"
|
ProviderId = "123"
|
||||||
|
@ -39,6 +44,64 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
Assert.True(search.Available);
|
Assert.True(search.Available);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Movie_Has_Custom_Url_When_Specified_In_Settings()
|
||||||
|
{
|
||||||
|
SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new EmbySettings
|
||||||
|
{
|
||||||
|
Enable = true,
|
||||||
|
Servers = new List<EmbyServers>
|
||||||
|
{
|
||||||
|
new EmbyServers
|
||||||
|
{
|
||||||
|
ServerHostname = "http://test.com/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).ReturnsAsync(new EmbyContent
|
||||||
|
{
|
||||||
|
ProviderId = "123",
|
||||||
|
EmbyId = 1.ToString()
|
||||||
|
});
|
||||||
|
var search = new SearchMovieViewModel()
|
||||||
|
{
|
||||||
|
TheMovieDbId = "123",
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.That(search.EmbyUrl, Is.EqualTo("http://test.com/#!/itemdetails.html?id=1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Movie_Uses_Default_Url_When()
|
||||||
|
{
|
||||||
|
SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new EmbySettings
|
||||||
|
{
|
||||||
|
Enable = true,
|
||||||
|
Servers = new List<EmbyServers>
|
||||||
|
{
|
||||||
|
new EmbyServers
|
||||||
|
{
|
||||||
|
ServerHostname = string.Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny<string>())).ReturnsAsync(new EmbyContent
|
||||||
|
{
|
||||||
|
ProviderId = "123",
|
||||||
|
EmbyId = 1.ToString()
|
||||||
|
});
|
||||||
|
var search = new SearchMovieViewModel()
|
||||||
|
{
|
||||||
|
TheMovieDbId = "123",
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.That(search.EmbyUrl, Is.EqualTo("https://app.emby.media/#!/itemdetails.html?id=1"));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInEmby()
|
public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInEmby()
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@ using Ombi.Store.Repository.Requests;
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Search
|
namespace Ombi.Core.Tests.Rule.Search
|
||||||
{
|
{
|
||||||
public class ExistignRequestRuleTests
|
public class ExistingRequestRuleTests
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
|
@ -39,18 +39,16 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
RequestType = RequestType.Movie
|
RequestType = RequestType.Movie
|
||||||
};
|
};
|
||||||
|
|
||||||
MovieMock.Setup(x => x.GetRequest(123)).Returns(list);
|
MovieMock.Setup(x => x.GetRequestAsync(123)).ReturnsAsync(list);
|
||||||
var search = new SearchMovieViewModel
|
var search = new SearchMovieViewModel
|
||||||
{
|
{
|
||||||
Id = 123,
|
Id = 123,
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
var result = await Rule.Execute(search);
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
Assert.True(result.Success);
|
Assert.That(result.Success, Is.True);
|
||||||
Assert.True(search.Approved);
|
Assert.That(search.Approved, Is.True);
|
||||||
Assert.True(search.Requested);
|
Assert.That(search.Requested, Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -62,7 +60,7 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
Approved = true
|
Approved = true
|
||||||
};
|
};
|
||||||
|
|
||||||
MovieMock.Setup(x => x.GetRequest(123)).Returns(list);
|
MovieMock.Setup(x => x.GetRequestAsync(123)).ReturnsAsync(list);
|
||||||
var search = new SearchMovieViewModel
|
var search = new SearchMovieViewModel
|
||||||
{
|
{
|
||||||
Id = 999,
|
Id = 999,
|
||||||
|
|
|
@ -65,14 +65,17 @@ namespace Ombi.Core.Rule.Rules.Search
|
||||||
{
|
{
|
||||||
obj.Available = true;
|
obj.Available = true;
|
||||||
var s = await EmbySettings.GetSettingsAsync();
|
var s = await EmbySettings.GetSettingsAsync();
|
||||||
var server = s.Servers.FirstOrDefault(x => x.ServerHostname != null);
|
if (s.Enable)
|
||||||
if ((server?.ServerHostname ?? string.Empty).HasValue())
|
|
||||||
{
|
{
|
||||||
obj.EmbyUrl = $"{server.ServerHostname}#!/itemdetails.html?id={item.EmbyId}";
|
var server = s.Servers.FirstOrDefault(x => x.ServerHostname != null);
|
||||||
}
|
if ((server?.ServerHostname ?? string.Empty).HasValue())
|
||||||
else
|
{
|
||||||
{
|
obj.EmbyUrl = $"{server.ServerHostname}#!/itemdetails.html?id={item.EmbyId}";
|
||||||
obj.EmbyUrl = $"https://app.emby.media/#!/itemdetails.html?id={item.EmbyId}";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
obj.EmbyUrl = $"https://app.emby.media/#!/itemdetails.html?id={item.EmbyId}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.Type == RequestType.TvShow)
|
if (obj.Type == RequestType.TvShow)
|
||||||
|
|
|
@ -30,7 +30,6 @@ namespace Ombi.Core.Rule.Rules.Search
|
||||||
var movieRequests = await Movie.GetRequestAsync(obj.Id);
|
var movieRequests = await Movie.GetRequestAsync(obj.Id);
|
||||||
if (movieRequests != null) // Do we already have a request for this?
|
if (movieRequests != null) // Do we already have a request for this?
|
||||||
{
|
{
|
||||||
|
|
||||||
obj.Requested = true;
|
obj.Requested = true;
|
||||||
obj.RequestId = movieRequests.Id;
|
obj.RequestId = movieRequests.Id;
|
||||||
obj.Approved = movieRequests.Approved;
|
obj.Approved = movieRequests.Approved;
|
||||||
|
|
|
@ -44,12 +44,12 @@ namespace Ombi.Schedule.Tests
|
||||||
new Issues
|
new Issues
|
||||||
{
|
{
|
||||||
Status = IssueStatus.Resolved,
|
Status = IssueStatus.Resolved,
|
||||||
ResovledDate = DateTime.Now.AddDays(-5).AddHours(-1)
|
ResovledDate = DateTime.UtcNow.AddDays(-5).AddHours(-8)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
|
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
|
||||||
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
|
Repo.Setup(x => x.GetAll()).Returns(issues.AsQueryable());
|
||||||
await Job.Start();
|
await Job.Start();
|
||||||
|
|
||||||
Assert.That(issues.First().Status, Is.EqualTo(IssueStatus.Deleted));
|
Assert.That(issues.First().Status, Is.EqualTo(IssueStatus.Deleted));
|
||||||
|
@ -57,7 +57,7 @@ namespace Ombi.Schedule.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task DoesNot_Delete_AnyIssues()
|
public async Task DoesNot_Delete_AllIssues()
|
||||||
{
|
{
|
||||||
var issues = new List<Issues>()
|
var issues = new List<Issues>()
|
||||||
{
|
{
|
||||||
|
@ -81,5 +81,31 @@ namespace Ombi.Schedule.Tests
|
||||||
Assert.That(issues[1].Status, Is.EqualTo(IssueStatus.Deleted));
|
Assert.That(issues[1].Status, Is.EqualTo(IssueStatus.Deleted));
|
||||||
Repo.Verify(x => x.SaveChangesAsync(), Times.Once);
|
Repo.Verify(x => x.SaveChangesAsync(), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task DoesNot_Delete_AnyIssues()
|
||||||
|
{
|
||||||
|
var issues = new List<Issues>()
|
||||||
|
{
|
||||||
|
new Issues
|
||||||
|
{
|
||||||
|
Status = IssueStatus.Resolved,
|
||||||
|
ResovledDate = DateTime.Now.AddDays(-2)
|
||||||
|
},
|
||||||
|
new Issues
|
||||||
|
{
|
||||||
|
Status = IssueStatus.Resolved,
|
||||||
|
ResovledDate = DateTime.Now.AddDays(-4)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
|
||||||
|
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
|
||||||
|
await Job.Start();
|
||||||
|
|
||||||
|
Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted));
|
||||||
|
Assert.That(issues[1].Status, Is.Not.EqualTo(IssueStatus.Deleted));
|
||||||
|
Repo.Verify(x => x.SaveChangesAsync(), Times.Once);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -28,9 +28,10 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var deletionDate = DateTime.Now.AddDays(settings.DaysAfterResolvedToDelete).Date;
|
var today = DateTime.UtcNow.Date;
|
||||||
|
|
||||||
var resolved = _issuesRepository.GetAll().Where(x => x.Status == IssueStatus.Resolved);
|
var resolved = _issuesRepository.GetAll().Where(x => x.Status == IssueStatus.Resolved);
|
||||||
var toDelete = resolved.Where(x => x.ResovledDate.HasValue && x.ResovledDate.Value.Date >= deletionDate);
|
var toDelete = resolved.Where(x => x.ResovledDate.HasValue && (today - x.ResovledDate.Value.Date).TotalDays >= settings.DaysAfterResolvedToDelete);
|
||||||
|
|
||||||
foreach (var d in toDelete)
|
foreach (var d in toDelete)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
if (ApplicationUrl.EndsWith("/"))
|
if (ApplicationUrl.EndsWith("/"))
|
||||||
{
|
{
|
||||||
ApplicationUrl.Remove(ApplicationUrl.Length - 1);
|
ApplicationUrl = ApplicationUrl.Remove(ApplicationUrl.Length - 1);
|
||||||
}
|
}
|
||||||
if (!part.StartsWith("/"))
|
if (!part.StartsWith("/"))
|
||||||
{
|
{
|
||||||
|
|
32
src/Ombi.Test.Common/MockHelper.cs
Normal file
32
src/Ombi.Test.Common/MockHelper.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using MockQueryable.Moq;
|
||||||
|
using Moq;
|
||||||
|
using Ombi.Core.Authentication;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Ombi.Test.Common
|
||||||
|
{
|
||||||
|
public static class MockHelper
|
||||||
|
{
|
||||||
|
public static Mock<OmbiUserManager> MockUserManager(List<OmbiUser> ls)
|
||||||
|
{
|
||||||
|
var store = new Mock<IUserStore<OmbiUser>>();
|
||||||
|
//var u = new OmbiUserManager(store.Object, null, null, null, null, null, null, null, null,null,null,null,null)
|
||||||
|
var mgr = new Mock<OmbiUserManager>(store.Object, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
|
mgr.Object.UserValidators.Add(new UserValidator<OmbiUser>());
|
||||||
|
mgr.Object.PasswordValidators.Add(new PasswordValidator<OmbiUser>());
|
||||||
|
|
||||||
|
var userMock = ls.AsQueryable().BuildMock();
|
||||||
|
|
||||||
|
mgr.Setup(x => x.Users).Returns(userMock.Object);
|
||||||
|
mgr.Setup(x => x.DeleteAsync(It.IsAny<OmbiUser>())).ReturnsAsync(IdentityResult.Success);
|
||||||
|
mgr.Setup(x => x.CreateAsync(It.IsAny<OmbiUser>(), It.IsAny<string>())).ReturnsAsync(IdentityResult.Success).Callback<OmbiUser, string>((x, y) => ls.Add(x));
|
||||||
|
mgr.Setup(x => x.UpdateAsync(It.IsAny<OmbiUser>())).ReturnsAsync(IdentityResult.Success);
|
||||||
|
|
||||||
|
return mgr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
src/Ombi.Test.Common/Ombi.Test.Common.csproj
Normal file
17
src/Ombi.Test.Common/Ombi.Test.Common.csproj
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Moq" Version="4.10.0" />
|
||||||
|
<PackageReference Include="MockQueryable.Moq" Version="1.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
13
src/Ombi.sln
13
src/Ombi.sln
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 15.0.27130.2027
|
VisualStudioVersion = 16.0.28729.10
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -100,7 +100,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Helpers.Tests", "Ombi.
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Api.Gotify", "Ombi.Api.Gotify\Ombi.Api.Gotify.csproj", "{105EA346-766E-45B8-928B-DE6991DCB7EB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Api.Gotify", "Ombi.Api.Gotify\Ombi.Api.Gotify.csproj", "{105EA346-766E-45B8-928B-DE6991DCB7EB}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Settings.Tests", "Ombi.Settings.Tests\Ombi.Settings.Tests.csproj", "{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Settings.Tests", "Ombi.Settings.Tests\Ombi.Settings.Tests.csproj", "{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Test.Common", "Ombi.Test.Common\Ombi.Test.Common.csproj", "{27111E7C-748E-4996-BD71-2117027C6460}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -268,6 +270,10 @@ Global
|
||||||
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{27111E7C-748E-4996-BD71-2117027C6460}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{27111E7C-748E-4996-BD71-2117027C6460}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{27111E7C-748E-4996-BD71-2117027C6460}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{27111E7C-748E-4996-BD71-2117027C6460}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -307,6 +313,7 @@ Global
|
||||||
{CC8CEFCD-0CB6-45BB-845F-508BCAB5BDC3} = {6F42AB98-9196-44C4-B888-D5E409F415A1}
|
{CC8CEFCD-0CB6-45BB-845F-508BCAB5BDC3} = {6F42AB98-9196-44C4-B888-D5E409F415A1}
|
||||||
{105EA346-766E-45B8-928B-DE6991DCB7EB} = {9293CA11-360A-4C20-A674-B9E794431BF5}
|
{105EA346-766E-45B8-928B-DE6991DCB7EB} = {9293CA11-360A-4C20-A674-B9E794431BF5}
|
||||||
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94} = {6F42AB98-9196-44C4-B888-D5E409F415A1}
|
{F3969B69-3B07-4884-A7AB-0BAB8B84DF94} = {6F42AB98-9196-44C4-B888-D5E409F415A1}
|
||||||
|
{27111E7C-748E-4996-BD71-2117027C6460} = {6F42AB98-9196-44C4-B888-D5E409F415A1}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {192E9BF8-00B4-45E4-BCCC-4C215725C869}
|
SolutionGuid = {192E9BF8-00B4-45E4-BCCC-4C215725C869}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue