Skip to content

Commit

Permalink
Merge pull request #1853 from mregni/features/ES-1828
Browse files Browse the repository at this point in the history
Features/es 1828
  • Loading branch information
mregni authored Aug 2, 2022
2 parents cde5f7f + 1ff37da commit 744d94e
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 18 deletions.
4 changes: 2 additions & 2 deletions EmbyStat.Common/EmbyStat.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="MediaBrowser.Common" Version="4.7.3" />
<PackageReference Include="MediaBrowser.Common" Version="4.7.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.7" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.21.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.22.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Rollbar.NetCore.AspNet" Version="5.2.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
Expand Down
4 changes: 2 additions & 2 deletions EmbyStat.Common/Extensions/ShowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static string GenerateCountQuery(IEnumerable<Filter> filters)
var query = $@"
SELECT COUNT() AS Count
FROM {Constants.Tables.Shows} as s
WHERE 1=1";
WHERE 1=1 ";
query = filters.Aggregate(query, (current, filter) => current + AddShowFilters(filter));

return query;
Expand All @@ -79,7 +79,7 @@ public static string GenerateFullShowQuery()
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";
WHERE 1=1 ";
}

public static string GenerateFullShowWithGenresQuery()
Expand Down
2 changes: 1 addition & 1 deletion EmbyStat.Hosts.Cmd/EmbyStat.Hosts.Cmd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<PackageReference Include="Serilog.Exceptions" Version="8.3.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion EmbyStat.Web/ClientApp/src/pages/shows/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function ShowTable() {
{label: 'COMMON.TOTALRUNTIME', field: 'cumulativeRunTimeTicks', sortable: false, align: 'right'},
{label: 'COMMON.SEASONS', field: 'seasons', sortable: true, align: 'right'},
{label: 'COMMON.EPISODES', field: 'episodes', sortable: true, align: 'right', width: 220},
{label: 'COMMON.OFFICIALRATING', field: 'officielRating', sortable: true, align: 'right'},
{label: 'COMMON.OFFICIALRATING', field: 'officialRating', sortable: true, align: 'right'},
{label: 'COMMON.LINKS', field: '', sortable: false, align: 'right'},
];

Expand Down
22 changes: 11 additions & 11 deletions Tests.Unit/Extensions/RoundNumberExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ public void RoundToFive_Should_Round_Number_To_Five(double input, int output)
}

[Theory]
[InlineData(0d, 0)]
[InlineData(0.1d, 0)]
[InlineData(0.2d, 0)]
[InlineData(0.3d, 0.5)]
[InlineData(0.4d, 0.5)]
[InlineData(0.5d, 0.5)]
[InlineData(0.6d, 0.5)]
[InlineData(0.7d, 0.5)]
[InlineData(0.8d, 1)]
[InlineData(0.9d, 1)]
[InlineData(1d, 1)]
[InlineData(0d, 0d)]
[InlineData(0.1d, 0d)]
[InlineData(0.2d, 0d)]
[InlineData(0.3d, 0.5d)]
[InlineData(0.4d, 0.5d)]
[InlineData(0.5d, 0.5d)]
[InlineData(0.6d, 0.5d)]
[InlineData(0.7d, 0.5d)]
[InlineData(0.8d, 1d)]
[InlineData(0.9d, 1d)]
[InlineData(1d, 1d)]
[InlineData(null, null)]
public void RoundToHalf_Should_Round_Number_To_Half(double? input, double? output)
{
Expand Down
111 changes: 111 additions & 0 deletions Tests.Unit/Extensions/ShowExtensionTests.cs
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);
}
}
46 changes: 46 additions & 0 deletions Tests.Unit/Factory/EmbyClientFactoryTests.cs
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);
}
}
44 changes: 44 additions & 0 deletions Tests.Unit/Factory/JellyfinClientFactoryTests.cs
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);
}
}
2 changes: 1 addition & 1 deletion Tests.Unit/Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="morelinq" Version="3.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 744d94e

Please sign in to comment.