mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
4 files changed
+130
-40
No files matched your search
+13
-4
@@ -125,16 +125,25 @@ public class DrivesControllerTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_fileSystemTreeNodeResponseFixture.CreateMany(3, 1, 1).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.GetDrives(cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.GetDrives(cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -91,16 +91,25 @@ public class FileSystemControllerTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<FileSystemTypeResponse>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new FileSystemTypeResponse(PlatformType.Windows);
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.GetType(cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.GetType(cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
}
|
||||
+91
-28
@@ -148,17 +148,26 @@ public class PathControllerTests
|
||||
// Arrange
|
||||
string path = @"C:\Users\TestUser";
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<PathSegmentResponse>>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_pathSegmentResponseFixture.Create());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.GetPathRoot(path, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.GetPathRoot(path, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -199,17 +208,26 @@ public class PathControllerTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<PathSeparatorResponse>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return _pathSeparatorResponseFixture.Create();
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.GetPathSeparator(cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.GetPathSeparator(cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -314,20 +332,29 @@ public class PathControllerTests
|
||||
// Arrange
|
||||
string path = @"C:\Users\TestUser\Documents";
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new List<PathSegmentResponse>
|
||||
{
|
||||
_pathSegmentResponseFixture.Create()
|
||||
}.AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.GetPathParent(path, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.GetPathParent(path, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -432,17 +459,26 @@ public class PathControllerTests
|
||||
string originalPath = @"C:\Users";
|
||||
string newPath = "TestUser";
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<PathSegmentResponse>>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_pathSegmentResponseFixture.Create());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.CombinePath(originalPath, newPath, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.CombinePath(originalPath, newPath, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -548,20 +584,29 @@ public class PathControllerTests
|
||||
// Arrange
|
||||
string path = @"C:\Users\TestUser\Documents";
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new List<PathSegmentResponse>
|
||||
{
|
||||
_pathSegmentResponseFixture.Create()
|
||||
}.AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.SplitPath(path, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.SplitPath(path, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -605,17 +650,26 @@ public class PathControllerTests
|
||||
// Arrange
|
||||
string path = @"C:\Users\TestUser\Documents";
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<PathValidResponse>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new PathValidResponse(true);
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.ValidatePath(path, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.ValidatePath(path, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -659,16 +713,25 @@ public class PathControllerTests
|
||||
// Arrange
|
||||
string path = @"C:\Users\TestUser\Documents";
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<PathExistsResponse>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new PathExistsResponse(true);
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.CheckPathExists(path, true, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.CheckPathExists(path, true, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -133,16 +133,25 @@ public class ThumbnailsControllerTests
|
||||
string path = "/path/to/file.jpg";
|
||||
int quality = 80;
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockMediator.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<ThumbnailResponse>>(Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(100, callInfo.Arg<CancellationToken>());
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(ThumbnailResponseFixture.CreateThumbnailResponse());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
|
||||
// Act & Assert
|
||||
cts.CancelAfter(50);
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => _sut.GetThumbnail(path, quality, cts.Token));
|
||||
// Act
|
||||
Task<IActionResult> operationTask = _sut.GetThumbnail(path, quality, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user