Fix warnings in test projects

pull/10463/head
Bond_009 6 months ago
parent b62b0ec2b5
commit 0fd36a5bf1

@ -109,7 +109,7 @@ public class UserControllerTests
v.ErrorMessage.Contains("required", StringComparison.CurrentCultureIgnoreCase));
}
private IList<ValidationResult> Validate(object model)
private List<ValidationResult> Validate(object model)
{
var result = new List<ValidationResult>();
var context = new ValidationContext(model, null, null);

@ -7,135 +7,128 @@ using Xunit;
namespace Jellyfin.Extensions.Tests.Json.Converters
{
public static class JsonCommaDelimitedArrayTests
public class JsonCommaDelimitedArrayTests
{
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
{
Converters =
{
new JsonStringEnumConverter()
}
};
[Fact]
public static void Deserialize_String_Null_Success()
public void Deserialize_String_Null_Success()
{
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": null }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": null }", _jsonOptions);
Assert.Null(value?.Value);
}
[Fact]
public static void Deserialize_Empty_Success()
public void Deserialize_Empty_Success()
{
var desiredValue = new GenericBodyArrayModel<string>
{
Value = Array.Empty<string>()
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": """" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": """" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_String_Valid_Success()
public void Deserialize_String_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<string>
{
Value = new[] { "a", "b", "c" }
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": ""a,b,c"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_String_Space_Valid_Success()
public void Deserialize_String_Space_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<string>
{
Value = new[] { "a", "b", "c" }
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": ""a, b, c"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Valid_Success()
public void Deserialize_GenericCommandType_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_EmptyEntry_Success()
public void Deserialize_GenericCommandType_EmptyEntry_Success()
{
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Invalid_Success()
public void Deserialize_GenericCommandType_Invalid_Success()
{
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,TotallyNotAVallidCommand,MoveDown"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,TotallyNotAVallidCommand,MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Space_Valid_Success()
public void Deserialize_GenericCommandType_Space_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_String_Array_Valid_Success()
public void Deserialize_String_Array_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<string>
{
Value = new[] { "a", "b", "c" }
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Array_Valid_Success()
public void Deserialize_GenericCommandType_Array_Valid_Success()
{
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options);
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
}

@ -6,86 +6,85 @@ using Xunit;
namespace Jellyfin.Extensions.Tests.Json.Converters
{
public static class JsonCommaDelimitedIReadOnlyListTests
public class JsonCommaDelimitedIReadOnlyListTests
{
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
{
Converters =
{
new JsonStringEnumConverter()
}
};
[Fact]
public static void Deserialize_String_Valid_Success()
public void Deserialize_String_Valid_Success()
{
var desiredValue = new GenericBodyIReadOnlyListModel<string>
{
Value = new[] { "a", "b", "c" }
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a,b,c"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_String_Space_Valid_Success()
public void Deserialize_String_Space_Valid_Success()
{
var desiredValue = new GenericBodyIReadOnlyListModel<string>
{
Value = new[] { "a", "b", "c" }
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a, b, c"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Valid_Success()
public void Deserialize_GenericCommandType_Valid_Success()
{
var desiredValue = new GenericBodyIReadOnlyListModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Space_Valid_Success()
public void Deserialize_GenericCommandType_Space_Valid_Success()
{
var desiredValue = new GenericBodyIReadOnlyListModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options);
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_String_Array_Valid_Success()
public void Deserialize_String_Array_Valid_Success()
{
var desiredValue = new GenericBodyIReadOnlyListModel<string>
{
Value = new[] { "a", "b", "c" }
};
var options = new JsonSerializerOptions();
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", options);
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
[Fact]
public static void Deserialize_GenericCommandType_Array_Valid_Success()
public void Deserialize_GenericCommandType_Array_Valid_Success()
{
var desiredValue = new GenericBodyIReadOnlyListModel<GeneralCommandType>
{
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
};
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options);
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions);
Assert.Equal(desiredValue.Value, value?.Value);
}
}

@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
using IConfigurationManager = MediaBrowser.Common.Configuration.IConfigurationManager;
namespace Jellyfin.Networking.Tests
{

@ -27,7 +27,7 @@ namespace Jellyfin.Providers.Tests.Manager
{
public partial class ItemImageProviderTests
{
private const string TestDataImagePath = "Test Data/Images/blank{0}.jpg";
private static readonly CompositeFormat _testDataImagePath = CompositeFormat.Parse("Test Data/Images/blank{0}.jpg");
[GeneratedRegex("[0-9]+")]
private static partial Regex NumbersRegex();
@ -275,7 +275,7 @@ namespace Jellyfin.Providers.Tests.Manager
{
HasImage = true,
Format = ImageFormat.Jpg,
Path = responseHasPath ? string.Format(CultureInfo.InvariantCulture, TestDataImagePath, 0) : null,
Path = responseHasPath ? string.Format(CultureInfo.InvariantCulture, _testDataImagePath, 0) : null,
Protocol = protocol
};
@ -563,21 +563,21 @@ namespace Jellyfin.Providers.Tests.Manager
mockFileSystem.Setup(fs => fs.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new[]
{
string.Format(CultureInfo.InvariantCulture, TestDataImagePath, 0),
string.Format(CultureInfo.InvariantCulture, TestDataImagePath, 1)
string.Format(CultureInfo.InvariantCulture, _testDataImagePath, 0),
string.Format(CultureInfo.InvariantCulture, _testDataImagePath, 1)
});
return new ItemImageProvider(new NullLogger<ItemImageProvider>(), providerManager, mockFileSystem.Object);
}
private static BaseItem GetItemWithImages(ImageType type, int count, bool validPaths)
private static Video GetItemWithImages(ImageType type, int count, bool validPaths)
{
// Has to exist for querying DateModified time on file, results stored but not checked so not populating
BaseItem.FileSystem ??= Mock.Of<IFileSystem>();
var item = new Video();
var path = validPaths ? TestDataImagePath : "invalid path {0}";
var path = validPaths ? _testDataImagePath.Format : "invalid path {0}";
for (int i = 0; i < count; i++)
{
item.SetImagePath(type, i, new FileSystemMetadata
@ -604,7 +604,7 @@ namespace Jellyfin.Providers.Tests.Manager
/// </summary>
private static LocalImageInfo[] GetImages(ImageType type, int count, bool validPaths)
{
var path = validPaths ? TestDataImagePath : "invalid path {0}";
var path = validPaths ? _testDataImagePath.Format : "invalid path {0}";
var images = new LocalImageInfo[count];
for (int i = 0; i < count; i++)
{

@ -9,22 +9,21 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting
{
public class AiredEpisodeOrderComparerTests
{
private readonly AiredEpisodeOrderComparer _cmp = new AiredEpisodeOrderComparer();
[Theory]
[ClassData(typeof(EpisodeBadData))]
public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem? x, BaseItem? y)
{
var cmp = new AiredEpisodeOrderComparer();
Assert.Throws<ArgumentNullException>(() => cmp.Compare(x, y));
Assert.Throws<ArgumentNullException>(() => _cmp.Compare(x, y));
}
[Theory]
[ClassData(typeof(EpisodeTestData))]
public void AiredEpisodeOrderCompareTest(BaseItem x, BaseItem y, int expected)
{
var cmp = new AiredEpisodeOrderComparer();
Assert.Equal(expected, cmp.Compare(x, y));
Assert.Equal(-expected, cmp.Compare(y, x));
Assert.Equal(expected, _cmp.Compare(x, y));
Assert.Equal(-expected, _cmp.Compare(y, x));
}
private sealed class EpisodeBadData : TheoryData<BaseItem?, BaseItem?>

@ -9,7 +9,7 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting;
public class IndexNumberComparerTests
{
private readonly IBaseItemComparer _cmp = new IndexNumberComparer();
private readonly IndexNumberComparer _cmp = new IndexNumberComparer();
public static TheoryData<BaseItem?, BaseItem?> Compare_GivenNull_ThrowsArgumentNullException_TestData()
=> new()

@ -9,7 +9,7 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting;
public class ParentIndexNumberComparerTests
{
private readonly IBaseItemComparer _cmp = new ParentIndexNumberComparer();
private readonly ParentIndexNumberComparer _cmp = new ParentIndexNumberComparer();
public static TheoryData<BaseItem?, BaseItem?> Compare_GivenNull_ThrowsArgumentNullException_TestData()
=> new()

@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
using IConfigurationManager = MediaBrowser.Common.Configuration.IConfigurationManager;
namespace Jellyfin.Server.Tests
{
@ -98,7 +99,7 @@ namespace Jellyfin.Server.Tests
Assert.Equal(knownNetworks.Length, options.KnownNetworks.Count);
foreach (var item in knownNetworks)
{
Assert.NotNull(options.KnownNetworks.FirstOrDefault(x => x.BaseAddress.Equals(item.BaseAddress) && x.PrefixLength == item.PrefixLength));
Assert.NotNull(options.KnownNetworks.FirstOrDefault(x => x.Prefix.Equals(item.BaseAddress) && x.PrefixLength == item.PrefixLength));
}
}

Loading…
Cancel
Save