mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
!minor unit testing
This commit is contained in:
parent
d6630d9d06
commit
ba04a9d1b1
11 changed files with 230 additions and 103 deletions
|
@ -152,6 +152,7 @@ Task("Package")
|
||||||
});
|
});
|
||||||
|
|
||||||
Task("Publish")
|
Task("Publish")
|
||||||
|
.IsDependentOn("Run-Unit-Tests")
|
||||||
.IsDependentOn("PrePublish")
|
.IsDependentOn("PrePublish")
|
||||||
.IsDependentOn("Publish-Windows")
|
.IsDependentOn("Publish-Windows")
|
||||||
.IsDependentOn("Publish-OSX").IsDependentOn("Publish-Linux")
|
.IsDependentOn("Publish-OSX").IsDependentOn("Publish-Linux")
|
||||||
|
@ -191,9 +192,11 @@ Task("Publish-Linux")
|
||||||
});
|
});
|
||||||
|
|
||||||
Task("Run-Unit-Tests")
|
Task("Run-Unit-Tests")
|
||||||
.IsDependentOn("Publish")
|
|
||||||
.Does(() =>
|
.Does(() =>
|
||||||
{
|
{
|
||||||
|
DotNetCoreTest("./src/Ombi.Core.Tests/");
|
||||||
|
DotNetCoreTest("./src/Ombi.Notifications.Tests/");
|
||||||
|
DotNetCoreTest("./src/Ombi.Schedule.Tests/");
|
||||||
});
|
});
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
@ -201,7 +204,7 @@ Task("Run-Unit-Tests")
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Task("Default")
|
Task("Default")
|
||||||
.IsDependentOn("Run-Unit-Tests");
|
.IsDependentOn("Publish");
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// EXECUTION
|
// EXECUTION
|
||||||
|
|
|
@ -6,20 +6,14 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Moq" Version="4.7.99" />
|
<PackageReference Include="Moq" Version="4.7.99" />
|
||||||
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
|
|
||||||
<PackageReference Include="Nunit" Version="3.8.1" />
|
<PackageReference Include="Nunit" Version="3.8.1" />
|
||||||
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
|
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
|
||||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
|
<packagereference Include="Microsoft.NET.Test.Sdk" Version="15.0.0"></packagereference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -4,22 +4,26 @@ using Moq;
|
||||||
using Ombi.Core.Claims;
|
using Ombi.Core.Claims;
|
||||||
using Ombi.Core.Rule.Rules.Request;
|
using Ombi.Core.Rule.Rules.Request;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
using Xunit;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Request
|
namespace Ombi.Core.Tests.Rule.Request
|
||||||
{
|
{
|
||||||
|
[TestFixture]
|
||||||
public class AutoApproveRuleTests
|
public class AutoApproveRuleTests
|
||||||
{
|
{
|
||||||
public AutoApproveRuleTests()
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
PrincipalMock = new Mock<IPrincipal>();
|
PrincipalMock = new Mock<IPrincipal>();
|
||||||
Rule = new AutoApproveRule(PrincipalMock.Object);
|
Rule = new AutoApproveRule(PrincipalMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AutoApproveRule Rule { get; }
|
|
||||||
private Mock<IPrincipal> PrincipalMock { get; }
|
|
||||||
|
|
||||||
[Fact]
|
private AutoApproveRule Rule { get; set; }
|
||||||
|
private Mock<IPrincipal> PrincipalMock { get; set; }
|
||||||
|
|
||||||
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAdminAndRequestMovie()
|
public async Task Should_ReturnSuccess_WhenAdminAndRequestMovie()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
||||||
|
@ -30,7 +34,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.True(request.Approved);
|
Assert.True(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAdminAndRequestTV()
|
public async Task Should_ReturnSuccess_WhenAdminAndRequestTV()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
||||||
|
@ -41,7 +45,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.True(request.Approved);
|
Assert.True(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie()
|
public async Task Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.AutoApproveMovie)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.AutoApproveMovie)).Returns(true);
|
||||||
|
@ -52,7 +56,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.True(request.Approved);
|
Assert.True(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV()
|
public async Task Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.AutoApproveTv)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.AutoApproveTv)).Returns(true);
|
||||||
|
@ -63,7 +67,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.True(request.Approved);
|
Assert.True(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie()
|
public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie()
|
||||||
{
|
{
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
|
||||||
|
@ -73,7 +77,7 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.False(request.Approved);
|
Assert.False(request.Approved);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenNoClaimsAndRequestTV()
|
public async Task Should_ReturnFail_WhenNoClaimsAndRequestTV()
|
||||||
{
|
{
|
||||||
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
|
||||||
|
|
|
@ -1,26 +1,28 @@
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
using Ombi.Core.Claims;
|
using Ombi.Core.Claims;
|
||||||
using Ombi.Core.Models.Requests;
|
|
||||||
using Ombi.Core.Rule.Rules;
|
using Ombi.Core.Rule.Rules;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule
|
namespace Ombi.Core.Tests.Rule.Request
|
||||||
{
|
{
|
||||||
public class CanRequestRuleTests
|
public class CanRequestRuleTests
|
||||||
{
|
{
|
||||||
public CanRequestRuleTests()
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
PrincipalMock = new Mock<IPrincipal>();
|
PrincipalMock = new Mock<IPrincipal>();
|
||||||
Rule = new CanRequestRule(PrincipalMock.Object);
|
Rule = new CanRequestRule(PrincipalMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CanRequestRule Rule { get; }
|
|
||||||
private Mock<IPrincipal> PrincipalMock { get; }
|
|
||||||
|
|
||||||
[Fact]
|
private CanRequestRule Rule { get; set; }
|
||||||
|
private Mock<IPrincipal> PrincipalMock { get; set; }
|
||||||
|
|
||||||
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingMovieWithMovieRole()
|
public async Task Should_ReturnSuccess_WhenRequestingMovieWithMovieRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestMovie)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestMovie)).Returns(true);
|
||||||
|
@ -30,7 +32,7 @@ namespace Ombi.Core.Tests.Rule
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenRequestingMovieWithoutMovieRole()
|
public async Task Should_ReturnFail_WhenRequestingMovieWithoutMovieRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestMovie)).Returns(false);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestMovie)).Returns(false);
|
||||||
|
@ -41,7 +43,7 @@ namespace Ombi.Core.Tests.Rule
|
||||||
Assert.False(string.IsNullOrEmpty(result.Message));
|
Assert.False(string.IsNullOrEmpty(result.Message));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingMovieWithAdminRole()
|
public async Task Should_ReturnSuccess_WhenRequestingMovieWithAdminRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
||||||
|
@ -51,7 +53,7 @@ namespace Ombi.Core.Tests.Rule
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingTVWithAdminRole()
|
public async Task Should_ReturnSuccess_WhenRequestingTVWithAdminRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.Admin)).Returns(true);
|
||||||
|
@ -61,7 +63,7 @@ namespace Ombi.Core.Tests.Rule
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnSuccess_WhenRequestingTVWithTVRole()
|
public async Task Should_ReturnSuccess_WhenRequestingTVWithTVRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestTv)).Returns(true);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestTv)).Returns(true);
|
||||||
|
@ -71,7 +73,7 @@ namespace Ombi.Core.Tests.Rule
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task Should_ReturnFail_WhenRequestingTVWithoutTVRole()
|
public async Task Should_ReturnFail_WhenRequestingTVWithoutTVRole()
|
||||||
{
|
{
|
||||||
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestTv)).Returns(false);
|
PrincipalMock.Setup(x => x.IsInRole(OmbiRoles.RequestTv)).Returns(false);
|
||||||
|
|
|
@ -1,51 +1,57 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
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.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
using Ombi.Store.Repository.Requests;
|
using Ombi.Store.Repository.Requests;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Search
|
namespace Ombi.Core.Tests.Rule.Search
|
||||||
{
|
{
|
||||||
public class ExistignRequestRuleTests
|
public class ExistignRequestRuleTests
|
||||||
{
|
{
|
||||||
public ExistignRequestRuleTests()
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
MovieMock = new Mock<IMovieRequestRepository>();
|
MovieMock = new Mock<IMovieRequestRepository>();
|
||||||
TvMock = new Mock<ITvRequestRepository>();
|
TvMock = new Mock<ITvRequestRepository>();
|
||||||
Rule = new ExistingRule(MovieMock.Object, TvMock.Object);
|
Rule = new ExistingRule(MovieMock.Object, TvMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExistingRule Rule { get; }
|
private ExistingRule Rule { get; set; }
|
||||||
private Mock<IMovieRequestRepository> MovieMock { get; }
|
private Mock<IMovieRequestRepository> MovieMock { get; set; }
|
||||||
private Mock<ITvRequestRepository> TvMock { get; }
|
private Mock<ITvRequestRepository> TvMock { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task ShouldBe_Requested_WhenExisitngMovie()
|
public async Task ShouldBe_Requested_WhenExisitngMovie()
|
||||||
{
|
{
|
||||||
var list = new MovieRequests
|
var list = new MovieRequests
|
||||||
{
|
{
|
||||||
TheMovieDbId = 123,
|
TheMovieDbId = 123,
|
||||||
Approved = true
|
Approved = true,
|
||||||
|
RequestType = RequestType.Movie
|
||||||
};
|
};
|
||||||
|
|
||||||
MovieMock.Setup(x => x.GetRequest(123)).Returns(list);
|
MovieMock.Setup(x => x.GetRequest(123)).Returns(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.True(result.Success);
|
||||||
Assert.False(search.Approved);
|
Assert.True(search.Approved);
|
||||||
|
Assert.True(search.Requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task ShouldBe_NotRequested_WhenNewMovie()
|
public async Task ShouldBe_NotRequested_WhenNewMovie()
|
||||||
{
|
{
|
||||||
var list = new MovieRequests
|
var list = new MovieRequests
|
||||||
|
@ -64,9 +70,10 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
|
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
Assert.False(search.Approved);
|
Assert.False(search.Approved);
|
||||||
|
Assert.False(search.Requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task ShouldBe_Requested_WhenExisitngTv()
|
public async Task ShouldBe_Requested_WhenExisitngTv()
|
||||||
{
|
{
|
||||||
var list = new TvRequests
|
var list = new TvRequests
|
||||||
|
@ -86,15 +93,15 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
var search = new SearchTvShowViewModel
|
var search = new SearchTvShowViewModel
|
||||||
{
|
{
|
||||||
Id = 123,
|
Id = 123,
|
||||||
|
|
||||||
};
|
};
|
||||||
var result = await Rule.Execute(search);
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
Assert.True(search.Approved);
|
Assert.True(search.Approved);
|
||||||
|
Assert.True(search.Requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task ShouldBe_NotRequested_WhenNewTv()
|
public async Task ShouldBe_NotRequested_WhenNewTv()
|
||||||
{
|
{
|
||||||
var list = new TvRequests
|
var list = new TvRequests
|
||||||
|
@ -121,8 +128,7 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
|
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
Assert.False(search.Approved);
|
Assert.False(search.Approved);
|
||||||
|
Assert.False(search.Requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +1,26 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
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.Store.Context;
|
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Search
|
namespace Ombi.Core.Tests.Rule.Search
|
||||||
{
|
{
|
||||||
public class PlexAvailabilityRuleTests
|
public class PlexAvailabilityRuleTests
|
||||||
{
|
{
|
||||||
public PlexAvailabilityRuleTests()
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
ContextMock = new Mock<IPlexContentRepository>();
|
ContextMock = new Mock<IPlexContentRepository>();
|
||||||
Rule = new PlexAvailabilityRule(ContextMock.Object);
|
Rule = new PlexAvailabilityRule(ContextMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlexAvailabilityRule Rule { get; }
|
private PlexAvailabilityRule Rule { get; set; }
|
||||||
private Mock<IPlexContentRepository> ContextMock { get; }
|
private Mock<IPlexContentRepository> ContextMock { get; set; }
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task ShouldBe_Available_WhenFoundInPlex()
|
public async Task ShouldBe_Available_WhenFoundInPlex()
|
||||||
{
|
{
|
||||||
ContextMock.Setup(x => x.Get(It.IsAny<string>())).ReturnsAsync(new PlexContent
|
ContextMock.Setup(x => x.Get(It.IsAny<string>())).ReturnsAsync(new PlexContent
|
||||||
|
@ -31,11 +31,11 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
var result = await Rule.Execute(search);
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
Assert.True(result.Success);
|
Assert.True(result.Success);
|
||||||
Assert.Equal("TestUrl", search.PlexUrl);
|
Assert.AreEqual("TestUrl", search.PlexUrl);
|
||||||
Assert.True(search.Available);
|
Assert.True(search.Available);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
public async Task ShouldBe_NotAvailable_WhenNotFoundInPlex()
|
public async Task ShouldBe_NotAvailable_WhenNotFoundInPlex()
|
||||||
{
|
{
|
||||||
ContextMock.Setup(x => x.Get(It.IsAny<string>())).Returns(Task.FromResult(default(PlexContent)));
|
ContextMock.Setup(x => x.Get(It.IsAny<string>())).Returns(Task.FromResult(default(PlexContent)));
|
||||||
|
|
|
@ -1,33 +1,56 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query.Internal;
|
||||||
|
using Moq;
|
||||||
|
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.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Search
|
namespace Ombi.Core.Tests.Rule.Search
|
||||||
{
|
{
|
||||||
public class RadarrCacheRuleTests
|
public class RadarrCacheRuleTests
|
||||||
{
|
{
|
||||||
public RadarrCacheRuleTests()
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
ContextMock = new Mock<IOmbiContext>();
|
ContextMock = new Mock<IOmbiContext>();
|
||||||
Rule = new RadarrCacheRule(ContextMock.Object);
|
Rule = new RadarrCacheRule(ContextMock.Object);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private RadarrCacheRule Rule { get; }
|
private RadarrCacheRule Rule { get; set; }
|
||||||
private Mock<IOmbiContext> ContextMock { get; }
|
private Mock<IOmbiContext> ContextMock { get; set; }
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
|
[Ignore("EF IAsyncQueryProvider")]
|
||||||
public async Task Should_ReturnApproved_WhenMovieIsInRadarr()
|
public async Task Should_ReturnApproved_WhenMovieIsInRadarr()
|
||||||
{
|
{
|
||||||
var list = DbHelper.GetQueryableMockDbSet(new RadarrCache
|
var list = new List<RadarrCache>(){new RadarrCache
|
||||||
{
|
{
|
||||||
TheMovieDbId = 123
|
TheMovieDbId = 123
|
||||||
});
|
}}.AsQueryable();
|
||||||
|
var radarrMock = new Mock<DbSet<RadarrCache>>();
|
||||||
|
radarrMock.As<IAsyncEnumerable<RadarrCache>>()
|
||||||
|
.Setup(m => m.GetEnumerator())
|
||||||
|
.Returns(new TestAsyncEnumerator<RadarrCache>(list.GetEnumerator()));
|
||||||
|
|
||||||
ContextMock.Setup(x => x.RadarrCache).Returns(list);
|
|
||||||
|
radarrMock.As<IQueryable<RadarrCache>>()
|
||||||
|
.Setup(m => m.Provider)
|
||||||
|
.Returns(new TestAsyncQueryProvider<RadarrCache>(list.Provider));
|
||||||
|
|
||||||
|
radarrMock.As<IQueryable<RadarrCache>>().Setup(m => m.Expression).Returns(list.Expression);
|
||||||
|
radarrMock.As<IQueryable<RadarrCache>>().Setup(m => m.ElementType).Returns(list.ElementType);
|
||||||
|
radarrMock.As<IQueryable<RadarrCache>>().Setup(m => m.GetEnumerator()).Returns(() => list.GetEnumerator());
|
||||||
|
|
||||||
|
|
||||||
|
ContextMock.Setup(c => c.Set<RadarrCache>()).Returns(radarrMock.Object);
|
||||||
|
|
||||||
var request = new SearchMovieViewModel { Id = 123 };
|
var request = new SearchMovieViewModel { Id = 123 };
|
||||||
var result =await Rule.Execute(request);
|
var result =await Rule.Execute(request);
|
||||||
|
@ -37,7 +60,8 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Test]
|
||||||
|
[Ignore("EF IAsyncQueryProvider")]
|
||||||
public async Task Should_ReturnNotApproved_WhenMovieIsNotInRadarr()
|
public async Task Should_ReturnNotApproved_WhenMovieIsNotInRadarr()
|
||||||
{
|
{
|
||||||
var list = DbHelper.GetQueryableMockDbSet(new RadarrCache
|
var list = DbHelper.GetQueryableMockDbSet(new RadarrCache
|
||||||
|
@ -54,4 +78,87 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
Assert.False(request.Approved);
|
Assert.False(request.Approved);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class TestAsyncQueryProvider<TEntity> : IAsyncQueryProvider
|
||||||
|
{
|
||||||
|
private readonly IQueryProvider _inner;
|
||||||
|
|
||||||
|
internal TestAsyncQueryProvider(IQueryProvider inner)
|
||||||
|
{
|
||||||
|
_inner = inner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable CreateQuery(Expression expression)
|
||||||
|
{
|
||||||
|
return new TestAsyncEnumerable<TEntity>(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
|
||||||
|
{
|
||||||
|
return new TestAsyncEnumerable<TElement>(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Execute(Expression expression)
|
||||||
|
{
|
||||||
|
return _inner.Execute(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TResult Execute<TResult>(Expression expression)
|
||||||
|
{
|
||||||
|
return _inner.Execute<TResult>(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAsyncEnumerable<TResult> ExecuteAsync<TResult>(Expression expression)
|
||||||
|
{
|
||||||
|
return new TestAsyncEnumerable<TResult>(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TResult> ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.FromResult(Execute<TResult>(expression));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestAsyncEnumerable<T> : EnumerableQuery<T>, IAsyncEnumerable<T>, IQueryable<T>
|
||||||
|
{
|
||||||
|
public TestAsyncEnumerable(IEnumerable<T> enumerable)
|
||||||
|
: base(enumerable)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public TestAsyncEnumerable(Expression expression)
|
||||||
|
: base(expression)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public IAsyncEnumerator<T> GetEnumerator()
|
||||||
|
{
|
||||||
|
return new TestAsyncEnumerator<T>(this.AsEnumerable().GetEnumerator());
|
||||||
|
}
|
||||||
|
|
||||||
|
IQueryProvider IQueryable.Provider
|
||||||
|
{
|
||||||
|
get { return new TestAsyncQueryProvider<T>(this); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestAsyncEnumerator<T> : IAsyncEnumerator<T>
|
||||||
|
{
|
||||||
|
private readonly IEnumerator<T> _inner;
|
||||||
|
|
||||||
|
public TestAsyncEnumerator(IEnumerator<T> inner)
|
||||||
|
{
|
||||||
|
_inner = inner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_inner.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Current => _inner.Current;
|
||||||
|
|
||||||
|
public Task<bool> MoveNext(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.FromResult(_inner.MoveNext());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,39 @@
|
||||||
//using System.Linq;
|
using System.Linq;
|
||||||
//using Ombi.Store.Entities;
|
using NUnit.Framework;
|
||||||
//using Xunit;
|
using Ombi.Store.Entities;
|
||||||
//using Xunit.Abstractions;
|
|
||||||
|
|
||||||
//namespace Ombi.Notifications.Tests
|
namespace Ombi.Notifications.Tests
|
||||||
//{
|
{
|
||||||
// public class NotificationMessageResolverTests
|
[TestFixture]
|
||||||
// {
|
public class NotificationMessageResolverTests
|
||||||
// public NotificationMessageResolverTests(ITestOutputHelper helper)
|
{
|
||||||
// {
|
[SetUp]
|
||||||
// _resolver = new NotificationMessageResolver();
|
public void Setup()
|
||||||
// output = helper;
|
{
|
||||||
// }
|
|
||||||
|
|
||||||
// private readonly NotificationMessageResolver _resolver;
|
_resolver = new NotificationMessageResolver();
|
||||||
// private readonly ITestOutputHelper output;
|
}
|
||||||
|
|
||||||
|
private NotificationMessageResolver _resolver;
|
||||||
|
|
||||||
// [Fact]
|
[Test]
|
||||||
// public void Resolved_ShouldResolve_RequestedUser()
|
public void Resolved_ShouldResolveSubject_RequestedUser()
|
||||||
// {
|
{
|
||||||
// var result = _resolver.ParseMessage(new NotificationTemplates
|
var result = _resolver.ParseMessage(new NotificationTemplates
|
||||||
// {
|
{
|
||||||
// Subject = "This is a {RequestedUser}"
|
Subject = "This is a {RequestedUser}"
|
||||||
// }, new NotificationMessageCurlys {RequestedUser = "Abc"});
|
}, new NotificationMessageCurlys { RequestedUser = "Abc" });
|
||||||
// output.WriteLine(result.Message);
|
Assert.True(result.Subject.Equals("This is a Abc"), result.Subject);
|
||||||
// //Assert.True(result.Message.Equals("This is a Abc"));
|
}
|
||||||
|
|
||||||
// Assert.Contains("11a", result.Message);
|
[Test]
|
||||||
// }
|
public void Resolved_ShouldResolveMessage_RequestedUser()
|
||||||
// }
|
{
|
||||||
//}
|
var result = _resolver.ParseMessage(new NotificationTemplates
|
||||||
|
{
|
||||||
|
Message = "This is a {RequestedUser}"
|
||||||
|
}, new NotificationMessageCurlys { RequestedUser = "Abc" });
|
||||||
|
Assert.True(result.Message.Equals("This is a Abc"), result.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170914-09" />
|
<PackageReference Include="Nunit" Version="3.8.1" />
|
||||||
|
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
|
||||||
|
<packagereference Include="Microsoft.NET.Test.Sdk" Version="15.0.0"></packagereference>
|
||||||
<PackageReference Include="Moq" Version="4.7.99" />
|
<PackageReference Include="Moq" Version="4.7.99" />
|
||||||
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -17,21 +17,22 @@ namespace Ombi.Schedule.Tests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class PlexAvailabilityCheckerTests
|
public class PlexAvailabilityCheckerTests
|
||||||
{
|
{
|
||||||
public PlexAvailabilityCheckerTests()
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
_repo = new Mock<IPlexContentRepository>();
|
_repo = new Mock<IPlexContentRepository>();
|
||||||
_tv = new Mock<ITvRequestRepository>();
|
_tv = new Mock<ITvRequestRepository>();
|
||||||
_movie = new Mock<IMovieRequestRepository>();
|
_movie = new Mock<IMovieRequestRepository>();
|
||||||
_movie = new Mock<IMovieRequestRepository>();
|
|
||||||
_notify = new Mock<INotificationService>();
|
_notify = new Mock<INotificationService>();
|
||||||
Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock<IBackgroundJobClient>().Object);
|
Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock<IBackgroundJobClient>().Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Mock<IPlexContentRepository> _repo;
|
|
||||||
private readonly Mock<ITvRequestRepository> _tv;
|
private Mock<IPlexContentRepository> _repo;
|
||||||
private readonly Mock<IMovieRequestRepository> _movie;
|
private Mock<ITvRequestRepository> _tv;
|
||||||
private readonly Mock<INotificationService> _notify;
|
private Mock<IMovieRequestRepository> _movie;
|
||||||
private PlexAvailabilityChecker Checker { get; }
|
private Mock<INotificationService> _notify;
|
||||||
|
private PlexAvailabilityChecker Checker;
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task ProcessMovies_ShouldMarkAvailable_WhenInPlex()
|
public async Task ProcessMovies_ShouldMarkAvailable_WhenInPlex()
|
||||||
|
|
|
@ -66,6 +66,8 @@ namespace Ombi.Store.Context
|
||||||
.WithMany(b => b.Episodes)
|
.WithMany(b => b.Episodes)
|
||||||
.HasPrincipalKey(x => x.EmbyId)
|
.HasPrincipalKey(x => x.EmbyId)
|
||||||
.HasForeignKey(p => p.ParentId);
|
.HasForeignKey(p => p.ParentId);
|
||||||
|
|
||||||
|
builder.Ignore<Logs>();
|
||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue