-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1853 from mregni/features/ES-1828
Features/es 1828
- Loading branch information
Showing
9 changed files
with
219 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using EmbyStat.Common; | ||
using EmbyStat.Common.Extensions; | ||
using EmbyStat.Common.Models.Query; | ||
using FluentAssertions; | ||
using Tests.Unit.Builders; | ||
using Xunit; | ||
|
||
namespace Tests.Unit.Extensions; | ||
|
||
public class ShowExtensionTests | ||
{ | ||
[Fact] | ||
public void GenerateCountQuery_Should_Return_Query_Without_Filters() | ||
{ | ||
var query = ShowExtensions.GenerateCountQuery(Array.Empty<Filter>()); | ||
|
||
var wantedQuery = $@" | ||
SELECT COUNT() AS Count | ||
FROM {Constants.Tables.Shows} as s | ||
WHERE 1=1 "; | ||
query.Should().NotBeNullOrWhiteSpace(); | ||
query.Should().Be(wantedQuery); | ||
} | ||
|
||
[Fact] | ||
public void GenerateFullShowQuery_Should_Return_Query() | ||
{ | ||
var query = ShowExtensions.GenerateFullShowQuery(); | ||
|
||
var wantedQuery = $@" | ||
SELECT s.*, se.*, e.* | ||
FROM {Constants.Tables.Shows} as s | ||
LEFT JOIN {Constants.Tables.Seasons} AS se ON (s.Id = se.ShowId) | ||
LEFT JOIN {Constants.Tables.Episodes} AS e ON (se.Id = e.SeasonId) | ||
WHERE 1=1 "; | ||
query.Should().NotBeNullOrWhiteSpace(); | ||
query.Should().Be(wantedQuery); | ||
} | ||
|
||
[Fact] | ||
public void GenerateFullShowWithGenresQuery_Should_Return_Query() | ||
{ | ||
var query = ShowExtensions.GenerateFullShowWithGenresQuery(); | ||
|
||
var wantedQuery = $@" | ||
SELECT s.*, g.*, se.*, e.* | ||
FROM {Constants.Tables.Shows} as s | ||
LEFT JOIN {Constants.Tables.GenreShow} AS gs ON (gs.ShowsId = s.Id) | ||
LEFT JOIN {Constants.Tables.Genres} AS g ON (gs.GenresId = g.Id) | ||
LEFT JOIN {Constants.Tables.Seasons} AS se ON (s.Id = se.ShowId) | ||
LEFT JOIN {Constants.Tables.Episodes} AS e ON (se.Id = e.SeasonId) | ||
WHERE 1=1 "; | ||
query.Should().NotBeNullOrWhiteSpace(); | ||
query.Should().Be(wantedQuery); | ||
} | ||
|
||
[Theory] | ||
[InlineData("sortName", "asc", "ASC")] | ||
[InlineData("Name", "desc", "DESC")] | ||
public void GenerateShowPageQuery_Should_Return_Query_With_SortField(string field, string order, string orderResult) | ||
{ | ||
var query = ShowExtensions.GenerateShowPageQuery(Array.Empty<Filter>(), field, order); | ||
|
||
var wantedQuery = $@" | ||
SELECT s.*, g.*, se.*, e.* | ||
FROM {Constants.Tables.Shows} as s | ||
LEFT JOIN {Constants.Tables.GenreShow} AS gs ON (gs.ShowsId = s.Id) | ||
LEFT JOIN {Constants.Tables.Genres} AS g ON (gs.GenresId = g.Id) | ||
LEFT JOIN {Constants.Tables.Seasons} AS se ON (s.Id = se.ShowId) | ||
LEFT JOIN {Constants.Tables.Episodes} AS e ON (se.Id = e.SeasonId) | ||
WHERE 1=1 ORDER BY {field.FirstCharToUpper()} {orderResult} "; | ||
query.Should().NotBeNullOrWhiteSpace(); | ||
query.Should().Be(wantedQuery); | ||
} | ||
|
||
[Fact] | ||
public void GenerateShowPageQuery_Should_Return_Query_Without_SortField() | ||
{ | ||
var query = ShowExtensions.GenerateShowPageQuery(Array.Empty<Filter>(), "", ""); | ||
|
||
var wantedQuery = $@" | ||
SELECT s.*, g.*, se.*, e.* | ||
FROM {Constants.Tables.Shows} as s | ||
LEFT JOIN {Constants.Tables.GenreShow} AS gs ON (gs.ShowsId = s.Id) | ||
LEFT JOIN {Constants.Tables.Genres} AS g ON (gs.GenresId = g.Id) | ||
LEFT JOIN {Constants.Tables.Seasons} AS se ON (s.Id = se.ShowId) | ||
LEFT JOIN {Constants.Tables.Episodes} AS e ON (se.Id = e.SeasonId) | ||
WHERE 1=1 "; | ||
query.Should().NotBeNullOrWhiteSpace(); | ||
query.Should().Be(wantedQuery); | ||
} | ||
|
||
[Fact] | ||
public void GetShowSize_Should_Return_Size() | ||
{ | ||
var show = new ShowBuilder("1").Build(); | ||
var size = show.GetShowSize(); | ||
size.Should().Be(404); | ||
} | ||
|
||
[Fact] | ||
public void GetShowSize_Should_Filter_Out_Virtual_Episodes() | ||
{ | ||
var show = new ShowBuilder("1") | ||
.AddMissingEpisodes(1, 1) | ||
.Build(); | ||
var size = show.GetShowSize(); | ||
size.Should().Be(404); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using EmbyStat.Clients.Emby; | ||
using EmbyStat.Clients.Emby.Http; | ||
using EmbyStat.Clients.Jellyfin; | ||
using EmbyStat.Clients.Jellyfin.Http; | ||
using EmbyStat.Common.Enums; | ||
using FluentAssertions; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Tests.Unit.Factory; | ||
|
||
public class EmbyClientFactoryTests | ||
{ | ||
[Fact] | ||
public void CreateHttpClient_Should_Return_Client() | ||
{ | ||
var baseHttpClientMock = new Mock<IEmbyBaseHttpClient>(); | ||
var factory = new EmbyClientFactory(baseHttpClientMock.Object); | ||
|
||
var client = factory.CreateHttpClient(); | ||
client.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void CreateWebSocketClient_Should_Return_Client() | ||
{ | ||
var baseHttpClientMock = new Mock<IEmbyBaseHttpClient>(); | ||
var factory = new EmbyClientFactory(baseHttpClientMock.Object); | ||
|
||
var act = () => factory.CreateWebSocketClient(); | ||
act.Should().Throw<NotImplementedException>(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(ServerType.Emby, true)] | ||
[InlineData(ServerType.Jellyfin, false)] | ||
public void AppliesTo_Should_Return_Correct_Value(ServerType serverType, bool result) | ||
{ | ||
var baseHttpClientMock = new Mock<IEmbyBaseHttpClient>(); | ||
var factory = new EmbyClientFactory(baseHttpClientMock.Object); | ||
|
||
var client = factory.AppliesTo(serverType); | ||
client.Should().Be(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using EmbyStat.Clients.Jellyfin; | ||
using EmbyStat.Clients.Jellyfin.Http; | ||
using EmbyStat.Common.Enums; | ||
using FluentAssertions; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Tests.Unit.Factory; | ||
|
||
public class JellyfinClientFactoryTests | ||
{ | ||
[Fact] | ||
public void CreateHttpClient_Should_Return_Client() | ||
{ | ||
var baseHttpClientMock = new Mock<IJellyfinBaseHttpClient>(); | ||
var factory = new JellyfinClientFactory(baseHttpClientMock.Object); | ||
|
||
var client = factory.CreateHttpClient(); | ||
client.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void CreateWebSocketClient_Should_Return_Client() | ||
{ | ||
var baseHttpClientMock = new Mock<IJellyfinBaseHttpClient>(); | ||
var factory = new JellyfinClientFactory(baseHttpClientMock.Object); | ||
|
||
var act = () => factory.CreateWebSocketClient(); | ||
act.Should().Throw<NotImplementedException>(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(ServerType.Emby, false)] | ||
[InlineData(ServerType.Jellyfin, true)] | ||
public void AppliesTo_Should_Return_Correct_Value(ServerType serverType, bool result) | ||
{ | ||
var baseHttpClientMock = new Mock<IJellyfinBaseHttpClient>(); | ||
var factory = new JellyfinClientFactory(baseHttpClientMock.Object); | ||
|
||
var client = factory.AppliesTo(serverType); | ||
client.Should().Be(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters