Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
refactor(style): fix various warnings (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored May 14, 2024
1 parent 027139f commit 514c029
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 173 deletions.
22 changes: 14 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@ csharp_style_var_elsewhere = true:silent
## SonarAnalyzers.CSharp

# Remove this commented out code.
dotnet_diagnostic.s125.severity = None
dotnet_diagnostic.s125.severity = warning

# Complete the task associated to this 'TODO' comment.
dotnet_diagnostic.s1135.severity = None
dotnet_diagnostic.s1135.severity = warning

# Remove the unused local variable 'foo'.
dotnet_diagnostic.S1481.severity = error

# Remove this empty class, write its code or make it an "interface".
dotnet_diagnostic.s2094.severity = None
dotnet_diagnostic.s2094.severity = error

# Either implement 'IDisposable.Dispose', or totally rename this method to prevent confusion.
dotnet_diagnostic.s2953.severity = error

# Fix this implementation of 'IDisposable' to conform to the dispose pattern.
dotnet_diagnostic.s3881.severity = None
dotnet_diagnostic.s3881.severity = warning

# Logging in a catch clause should pass the caught exception as a parameter.
dotnet_diagnostic.s6667.severity = error
Expand All @@ -125,6 +128,9 @@ dotnet_diagnostic.s6668.severity = error
# Update this logger to use its enclosing type.
dotnet_diagnostic.s6672.severity = error

# REST API controller actions should be annotated with the appropriate HTTP verb attribute.
dotnet_diagnostic.s6965.severity = error


## StyleCop.Analyzers

Expand All @@ -135,10 +141,10 @@ dotnet_diagnostic.sa0001.severity = None
dotnet_diagnostic.sa1101.severity = None

# Opening brace should be followed by a space
dotnet_diagnostic.sa1012.severity = None
dotnet_diagnostic.sa1012.severity = error

# Closing brace should be preceded by a space
dotnet_diagnostic.sa1013.severity = None
dotnet_diagnostic.sa1013.severity = error

# Code should not contain trailing whitespace
dotnet_diagnostic.SA1028.severity = error
Expand All @@ -150,10 +156,10 @@ dotnet_diagnostic.sa1200.severity = None
dotnet_diagnostic.sa1309.severity = None

# Use trailing comma in multi-line initializers
dotnet_diagnostic.sa1413.severity = None
dotnet_diagnostic.sa1413.severity = error

# Single-line comments should not be followed by blank line
dotnet_diagnostic.sa1512.severity = None
dotnet_diagnostic.sa1512.severity = error

# The file header is missing or not located at the top of the file
dotnet_diagnostic.sa1633.severity = None
3 changes: 0 additions & 3 deletions Jellyfin.Plugin.Themerr.Tests/FixtureCollection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider;
using Movie = MediaBrowser.Controller.Entities.Movies.Movie;

namespace Jellyfin.Plugin.Themerr.Tests;

/// <summary>
Expand Down
56 changes: 28 additions & 28 deletions Jellyfin.Plugin.Themerr.Tests/FixtureJellyfinServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,70 +40,70 @@ private static List<BaseItem> MockItems()
ProductionYear = 2006,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt0807840"},
{ MetadataProvider.Tmdb.ToString(), "9761"},
}
{ MetadataProvider.Imdb.ToString(), "tt0807840" },
{ MetadataProvider.Tmdb.ToString(), "9761" },
},
},
new Movie
{
Name = "Sita Sings the Blues",
ProductionYear = 2008,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt1172203"},
{ MetadataProvider.Tmdb.ToString(), "20529"},
}
{ MetadataProvider.Imdb.ToString(), "tt1172203" },
{ MetadataProvider.Tmdb.ToString(), "20529" },
},
},
new Movie
{
Name = "Big Buck Bunny",
ProductionYear = 2008,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt1254207"},
{ MetadataProvider.Tmdb.ToString(), "10378"},
}
{ MetadataProvider.Imdb.ToString(), "tt1254207" },
{ MetadataProvider.Tmdb.ToString(), "10378" },
},
},
new Movie
{
Name = "Sintel",
ProductionYear = 2010,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt1727587"},
{ MetadataProvider.Tmdb.ToString(), "45745"},
}
{ MetadataProvider.Imdb.ToString(), "tt1727587" },
{ MetadataProvider.Tmdb.ToString(), "45745" },
},
},
new Series
{
Name = "Game of Thrones",
ProductionYear = 2011,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt0944947"},
{ MetadataProvider.Tmdb.ToString(), "1399"},
}
{ MetadataProvider.Imdb.ToString(), "tt0944947" },
{ MetadataProvider.Tmdb.ToString(), "1399" },
},
},
new Series
{
Name = "The 100",
ProductionYear = 2014,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt2661044"},
{ MetadataProvider.Tmdb.ToString(), "48866"},
}
{ MetadataProvider.Imdb.ToString(), "tt2661044" },
{ MetadataProvider.Tmdb.ToString(), "48866" },
},
},
new Series
{
Name = "Steins;Gate",
ProductionYear = 2011,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt1910272"},
{ MetadataProvider.Tmdb.ToString(), "42509"},
}
}
{ MetadataProvider.Imdb.ToString(), "tt1910272" },
{ MetadataProvider.Tmdb.ToString(), "42509" },
},
},
};
}

Expand All @@ -121,19 +121,19 @@ private static List<BaseItem> MockItems2()
ProductionYear = 1970,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt0000000"},
{ MetadataProvider.Tmdb.ToString(), "0"},
}
{ MetadataProvider.Imdb.ToString(), "tt0000000" },
{ MetadataProvider.Tmdb.ToString(), "0" },
},
},
new Series
{
Name = "Themerr Test Show",
ProductionYear = 1970,
ProviderIds = new Dictionary<string, string>
{
{ MetadataProvider.Imdb.ToString(), "tt0000000"},
{ MetadataProvider.Tmdb.ToString(), "0"},
}
{ MetadataProvider.Imdb.ToString(), "tt0000000" },
{ MetadataProvider.Tmdb.ToString(), "0" },
},
},
};
}
Expand Down
49 changes: 27 additions & 22 deletions Jellyfin.Plugin.Themerr.Tests/TestLogger.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,76 @@
namespace Jellyfin.Plugin.Themerr.Tests
{
/// <summary>
/// A simple logger for tests
/// A simple logger for tests.
/// </summary>
public static class TestLogger
{
// log a message to console
private static ITestOutputHelper? _output;

public static void Initialize(ITestOutputHelper output)
{
_output = output ?? throw new ArgumentNullException(nameof(output));
}

/// <summary>
/// Logs a message to the test output
/// Initializes the logger with the given output.
/// </summary>
/// <param name="message"></param>
/// <param name="type"></param>
public static void Log(string message, string type = "INFO")
/// <param name="output">The output to log to.</param>
/// <exception cref="ArgumentNullException">Thrown when the output is null.</exception>
public static void Initialize(ITestOutputHelper output)
{
_output?.WriteLine($"[{type}] {message}");
_output = output ?? throw new ArgumentNullException(nameof(output));
}

/// <summary>
/// Logs a critical message to the test output
/// Logs a critical message to the test output.
/// </summary>
/// <param name="message"></param>
/// <param name="message">The message to log.</param>
public static void Critical(string message)
{
Log(message, "CRITICAL");
}

/// <summary>
/// Logs a debug message to the test output
/// Logs a debug message to the test output.
/// </summary>
/// <param name="message"></param>
/// <param name="message">The message to log.</param>
public static void Debug(string message)
{
Log(message, "DEBUG");
}

/// <summary>
/// Logs an error message to the test output
/// Logs an error message to the test output.
/// </summary>
/// <param name="message"></param>
/// <param name="message">The message to log.</param>
public static void Error(string message)
{
Log(message, "ERROR");
}

/// <summary>
/// Logs an info message to the test output
/// Logs an info message to the test output.
/// </summary>
/// <param name="message"></param>
/// <param name="message">The message to log.</param>
public static void Info(string message)
{
Log(message, "INFO");
Log(message);
}

/// <summary>
/// Logs a warning message to the test output
/// Logs a warning message to the test output.
/// </summary>
/// <param name="message"></param>
/// <param name="message">The message to log.</param>
public static void Warn(string message)
{
Log(message, "WARN");
}

/// <summary>
/// Logs a message to the test output.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="type">The type of message to log.</param>
private static void Log(string message, string type = "INFO")
{
_output?.WriteLine($"[{type}] {message}");
}
}
}
39 changes: 2 additions & 37 deletions Jellyfin.Plugin.Themerr.Tests/TestThemerrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TestThemerrController(ITestOutputHelper output)
// Create a TestableServerConfiguration with UICulture set to "en-US"
var testableServerConfiguration = new TestableServerConfiguration("en-US");

// Setup the Configuration property of the IServerConfigurationManager mock to return the TestableServerConfiguration
// Set up the Configuration property of the IServerConfigurationManager mock to return the TestableServerConfiguration
mockServerConfigurationManager.Setup(x => x.Configuration).Returns(testableServerConfiguration);

_controller = new ThemerrController(
Expand Down Expand Up @@ -64,7 +64,7 @@ public void TestGetProgress()
// ensure result["media_percent_complete"] is an int
Assert.IsType<int>(((JsonResult)result).Value?.GetType().GetProperty("media_percent_complete")?.GetValue(((JsonResult)result).Value, null));

// ensure result["items"] is a an array list
// ensure result["items"] is an array list
Assert.IsType<ArrayList>(((JsonResult)result).Value?.GetType().GetProperty("items")?.GetValue(((JsonResult)result).Value, null));

// ensure int values are 0
Expand Down Expand Up @@ -99,39 +99,4 @@ public void TestGetTranslations()
Assert.True(data.ContainsKey("locale"));
Assert.True(data.ContainsKey("fallback"));
}

/// <summary>
/// Test GetCultureResource function.
/// </summary>
/// <param name="culture">The culture to test.</param>
[Theory]
[Trait("Category", "Unit")]
[InlineData("de")]
[InlineData("en")]
[InlineData("en-GB")]
[InlineData("en-US")]
[InlineData("es")]
[InlineData("fr")]
[InlineData("it")]
[InlineData("ru")]
[InlineData("sv")]
[InlineData("zh")]
public void TestGetCultureResource(string culture)
{
var result = _controller.GetCultureResource(culture);
Assert.IsType<List<string>>(result);

// replace - with _ in the culture
var culture2 = culture.Replace("-", "_");

// en is not included in the list
if (culture != "en")
{
// assert that `en_<>.json` is in the list
Assert.Contains(culture2 + ".json", result);
}

// assert that `en` is NOT in the list
Assert.DoesNotContain("en.json", result);
}
}
Loading

0 comments on commit 514c029

Please sign in to comment.