Removes FluentAssertions library from test projects, due to licensing changes

This commit is contained in:
BinaryAlley committed 2025-02-03 00:31:15 +02:00
1 parent c1100e5398
commit d46bfae4fc
235 files changed
+4468 -4725

No files matched your search

@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
@@ -71,12 +70,12 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Assert
string content = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
List<DirectoryResponse>? directories = JsonSerializer.Deserialize<List<DirectoryResponse>>(content, _jsonOptions);
directories.Should().NotBeNull();
directories!.Should().BeEmpty();
Assert.NotNull(directories);
Assert.Empty(directories);
}
finally
{
@@ -101,21 +100,21 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<DirectoryResponse>? directories = JsonSerializer.Deserialize<List<DirectoryResponse>>(content, _jsonOptions);
directories.Should().NotBeNull();
directories!.Should().NotBeEmpty();
Assert.NotNull(directories);
Assert.NotNull(directories);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
DirectoryResponse firstDirectory = directories!.First();
firstDirectory.Name.Should().Be((s_isUnix ? "." : string.Empty) + "NestedDirectory_2");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "NestedDirectory_2" + System.IO.Path.DirectorySeparatorChar));
directories!.Count.Should().Be(1); // only directories
Assert.Equal((s_isUnix ? "." : string.Empty) + "NestedDirectory_2", directories!.First().Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "NestedDirectory_2" + System.IO.Path.DirectorySeparatorChar), directories.First().Path);
Assert.Single(directories); // only directories
}
finally
{
@@ -135,17 +134,18 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/directories/get-directories");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/directories/get-directories", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -160,20 +160,23 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/directories/get-directories");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/directories/get-directories", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -185,11 +188,11 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
bool includeHiddenElements = true;
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -201,15 +204,12 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
bool includeHiddenElements = true;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
@@ -67,18 +66,18 @@ public class GetDrivesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? drives = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
drives.Should().NotBeNull();
drives.Should().NotBeEmpty();
Assert.NotNull(drives);
Assert.NotEmpty(drives);
FileSystemTreeNodeResponse firstDrive = drives!.First();
firstDrive.Name.Should().Be(s_isUnix ? "/" : "C:\\");
firstDrive.Path.Should().Be(s_isUnix ? "/" : "C:\\");
firstDrive.ItemType.Should().Be(FileSystemItemType.Root);
drives!.Count.Should().BeGreaterThanOrEqualTo(1);
Assert.Equal(s_isUnix ? "/" : "C:\\", firstDrive.Name);
Assert.Equal(s_isUnix ? "/" : "C:\\", firstDrive.Path);
Assert.Equal(FileSystemItemType.Root, firstDrive.ItemType);
Assert.True(drives.Count >= 1);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -55,11 +54,11 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/file-system/get-type");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
FileSystemTypeResponse? result = JsonSerializer.Deserialize<FileSystemTypeResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.PlatformType.Should().BeOneOf(PlatformType.Unix, PlatformType.Windows);
Assert.NotNull(result);
Assert.True(result!.PlatformType == PlatformType.Unix || result.PlatformType == PlatformType.Windows);
}
[Fact]
@@ -70,8 +69,8 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response2 = await _client.GetAsync("/api/v1/file-system/get-type");
// Assert
response1.StatusCode.Should().Be(HttpStatusCode.OK);
response2.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response1.StatusCode);
Assert.Equal(HttpStatusCode.OK, response2.StatusCode);
string content1 = await response1.Content.ReadAsStringAsync();
string content2 = await response2.Content.ReadAsStringAsync();
@@ -79,9 +78,9 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
FileSystemTypeResponse? result1 = JsonSerializer.Deserialize<FileSystemTypeResponse>(content1, _jsonOptions);
FileSystemTypeResponse? result2 = JsonSerializer.Deserialize<FileSystemTypeResponse>(content2, _jsonOptions);
result1.Should().NotBeNull();
result2.Should().NotBeNull();
result1.Should().BeEquivalentTo(result2);
Assert.NotNull(result1);
Assert.NotNull(result2);
Assert.Equal(result1.PlatformType, result2.PlatformType);
}
[Fact]
@@ -90,11 +89,11 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// Arrange
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync("/api/v1/file-system/get-type", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync("/api/v1/file-system/get-type", cts.Token)
);
Assert.Null(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
@@ -68,21 +67,21 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileResponse>? files = JsonSerializer.Deserialize<List<FileResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(1); // only files
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.Single(files); // only files
}
finally
{
@@ -106,15 +105,15 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileResponse>? files = JsonSerializer.Deserialize<List<FileResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
Assert.NotNull(files);
FileResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
}
finally
{
@@ -138,23 +137,24 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileResponse>? files = JsonSerializer.Deserialize<List<FileResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be((s_isUnix ? "." : string.Empty) + "TestFile_1.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"));
Assert.Equal((s_isUnix ? "." : string.Empty) + "TestFile_1.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"), firstDirectory.Path);
FileResponse secondDirectory = files!.Last();
secondDirectory.Name.Should().Be("TestFile_2.txt");
secondDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(2);
Assert.Equal("TestFile_2.txt", secondDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), secondDirectory.Path);
Assert.Equal(2, files.Count);
}
finally
{
@@ -174,17 +174,18 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-files");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-files", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -199,20 +200,23 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-files");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-files", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -224,11 +228,11 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
bool includeHiddenElements = true;
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -240,15 +244,13 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
bool includeHiddenElements = true;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
@@ -68,21 +67,21 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? files = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileSystemTreeNodeResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(1); // only files
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.Single(files); // only files
}
finally
{
@@ -106,16 +105,16 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? files = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
Assert.NotNull(files);
FileSystemTreeNodeResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
}
finally
{
@@ -139,23 +138,24 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? files = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileSystemTreeNodeResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be((s_isUnix ? "." : string.Empty) + "TestFile_1.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"));
Assert.Equal((s_isUnix ? "." : string.Empty) + "TestFile_1.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"), firstDirectory.Path);
FileSystemTreeNodeResponse secondDirectory = files!.Last();
secondDirectory.Name.Should().Be("TestFile_2.txt");
secondDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(2);
Assert.Equal("TestFile_2.txt", secondDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), secondDirectory.Path);
Assert.Equal(2, files.Count);
}
finally
{
@@ -174,17 +174,18 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-tree-files");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-tree-files", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -199,20 +200,23 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-tree-files");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-tree-files", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -224,11 +228,11 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
bool includeHiddenElements = true;
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -240,15 +244,13 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
bool includeHiddenElements = true;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -59,11 +58,11 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(tempPath)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathExistsResponse? result = JsonSerializer.Deserialize<PathExistsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Exists.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.Exists);
}
[Fact]
@@ -76,11 +75,11 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(nonExistingPath)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathExistsResponse? result = JsonSerializer.Deserialize<PathExistsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Exists.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.Exists);
}
[Fact]
@@ -93,20 +92,22 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(path)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/check-path-exists");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/check-path-exists", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -119,11 +120,11 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(invalidPath)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathExistsResponse? result = JsonSerializer.Deserialize<PathExistsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Exists.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.Exists);
}
[Fact]
@@ -134,15 +135,13 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/check-path-exists?path={encodedPath}&includeHiddenElements=false", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -63,11 +62,11 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathSegmentResponse? result = JsonSerializer.Deserialize<PathSegmentResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Path.Should().Be(expectedPath);
Assert.NotNull(result);
Assert.Equal(expectedPath, result!.Path);
}
[Fact]
@@ -81,20 +80,23 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/combine");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/combine", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -105,11 +107,11 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string newPath = "documents";
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -120,15 +122,13 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string newPath = "testFile.txt";
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -63,11 +62,11 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<PathSegmentResponse>? result = JsonSerializer.Deserialize<IEnumerable<PathSegmentResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Should().NotBeEmpty();
Assert.NotNull(result);
Assert.NotEmpty(result);
List<string> hierarchy = [];
string path = System.IO.Path.GetDirectoryName(testPath)!;
@@ -84,7 +83,7 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
}
hierarchy.Reverse();
result!.Select(r => r.Path).Should().BeEquivalentTo(hierarchy, options => options.WithStrictOrdering());
Assert.Equal(hierarchy, result.Select(r => r.Path));
}
[Fact]
@@ -98,17 +97,18 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("CannotNavigateUp");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetString());
Assert.Equal("CannotNavigateUp", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -122,20 +122,22 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["InvalidPath"]);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidPath", errors["General.Validation"]);
}
[Fact]
@@ -149,20 +151,23 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -173,11 +178,11 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -188,15 +193,13 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -8,7 +7,6 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
@@ -61,11 +59,12 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathSegmentResponse? result = JsonSerializer.Deserialize<PathSegmentResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Path.Should().NotBeNullOrEmpty();
Assert.NotNull(result);
Assert.NotNull(result!.Path);
Assert.NotEmpty(result.Path);
}
[Fact]
@@ -79,20 +78,23 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-root");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-root", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["InvalidPath"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidPath", errors["General.Validation"]);
}
[Fact]
@@ -106,20 +108,23 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-root");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-root", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -130,11 +135,11 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -145,15 +150,13 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using System;
@@ -54,11 +53,11 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-separator");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathSeparatorResponse? result = JsonSerializer.Deserialize<PathSeparatorResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Separator.Should().BeOneOf("/", "\\");
Assert.NotNull(result);
Assert.True(result!.Separator == "/" || result.Separator == "\\");
}
[Fact]
@@ -69,8 +68,8 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response2 = await _client.GetAsync("/api/v1/path/get-path-separator");
// Assert
response1.StatusCode.Should().Be(HttpStatusCode.OK);
response2.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response1.StatusCode);
Assert.Equal(HttpStatusCode.OK, response2.StatusCode);
string content1 = await response1.Content.ReadAsStringAsync();
string content2 = await response2.Content.ReadAsStringAsync();
@@ -78,9 +77,9 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
PathSeparatorResponse? result1 = JsonSerializer.Deserialize<PathSeparatorResponse>(content1, _jsonOptions);
PathSeparatorResponse? result2 = JsonSerializer.Deserialize<PathSeparatorResponse>(content2, _jsonOptions);
result1.Should().NotBeNull();
result2.Should().NotBeNull();
result1.Should().BeEquivalentTo(result2);
Assert.NotNull(result1);
Assert.NotNull(result2);
Assert.Equal(result1, result2);
}
[Fact]
@@ -89,11 +88,11 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
// Arrange
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync("/api/v1/path/get-path-separator", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync("/api/v1/path/get-path-separator", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -102,15 +101,13 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync("/api/v1/path/get-path-separator", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -61,12 +60,15 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/split?path={Uri.EscapeDataString(testPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<PathSegmentResponse>? result = JsonSerializer.Deserialize<IEnumerable<PathSegmentResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Should().HaveCountGreaterThanOrEqualTo(3);
result!.Select(r => r.Path).Should().Contain(["testFolder", "testFile.txt"]);
Assert.NotNull(result);
Assert.True(result!.Count() >= 3);
IEnumerable<string> paths = result.Select(r => r.Path);
Assert.Contains("testFolder", paths);
Assert.Contains("testFile.txt", paths);
}
[Fact]
@@ -79,20 +81,23 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/split?path={Uri.EscapeDataString(path)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/split");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/split", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -105,20 +110,23 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/split?path={Uri.EscapeDataString(path)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/split");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/split", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["InvalidPath"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidPath", errors["General.Validation"]);
}
[Fact]
@@ -129,15 +137,13 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/split?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using System;
@@ -58,11 +57,11 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/validate?path={Uri.EscapeDataString(testPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathValidResponse? result = JsonSerializer.Deserialize<PathValidResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsValid.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.IsValid);
}
[Fact]
@@ -75,11 +74,11 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/validate?path={Uri.EscapeDataString(invalidPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathValidResponse? result = JsonSerializer.Deserialize<PathValidResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsValid.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.IsValid);
}
[Fact]
@@ -92,11 +91,11 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/validate?path={Uri.EscapeDataString(path)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathValidResponse? result = JsonSerializer.Deserialize<PathValidResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsValid.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.IsValid);
}
[Fact]
@@ -107,15 +106,13 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/validate?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Microsoft.AspNetCore.Http;
@@ -62,10 +61,10 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(_testImagePath)}&quality={quality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Content.Headers.ContentType!.MediaType.Should().Be("image/jpeg");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("image/jpeg", response.Content.Headers.ContentType!.MediaType);
byte[] content = await response.Content.ReadAsByteArrayAsync();
content.Should().NotBeEmpty();
Assert.NotEmpty(content);
}
[Fact]
@@ -79,17 +78,18 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(invalidImagePath)}&quality={quality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -103,20 +103,23 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(invalidImagePath)}&quality={quality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -129,20 +132,23 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(_testImagePath)}&quality={invalidQuality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["ImageQualityMustBeBetweenZeroAndOneHundred"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("ImageQualityMustBeBetweenZeroAndOneHundred", errors["General.Validation"]);
}
[Fact]
@@ -152,15 +158,13 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
int quality = 80;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(_testImagePath)}&quality={quality}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>