diff --git a/src/UnitTests/CommandLine/Commands/Generic/ElementCommandTest.cs b/src/UnitTests/CommandLine/Commands/Generic/ElementCommandTest.cs index 795df13c..fe195baf 100644 --- a/src/UnitTests/CommandLine/Commands/Generic/ElementCommandTest.cs +++ b/src/UnitTests/CommandLine/Commands/Generic/ElementCommandTest.cs @@ -10,7 +10,7 @@ public async Task TestRead() var entity = new MockEntity(5, "test"); ConsoleMock.Setup(x => x.Write(entity)); - EndpointMock.Setup(x => x.ReadAsync(default)).ReturnsAsync(entity); + EndpointMock.Setup(x => x.ReadAsync(It.IsAny())).ReturnsAsync(entity); await ExecuteAsync(); } @@ -21,7 +21,7 @@ public async Task TestSet() var entity = new MockEntity(5, "test"); ConsoleMock.Setup(x => x.Read()).Returns(entity); - EndpointMock.Setup(x => x.SetAsync(entity, default)).ReturnsAsync(entity); + EndpointMock.Setup(x => x.SetAsync(entity, It.IsAny())).ReturnsAsync(entity); ConsoleMock.Setup(x => x.Write(entity)); await ExecuteAsync("set"); @@ -33,7 +33,7 @@ public async Task TestMerge() var entity = new MockEntity(5, "test"); ConsoleMock.Setup(x => x.Read()).Returns(entity); - EndpointMock.Setup(x => x.MergeAsync(entity, default)).ReturnsAsync(entity); + EndpointMock.Setup(x => x.MergeAsync(entity, It.IsAny())).ReturnsAsync(entity); ConsoleMock.Setup(x => x.Write(entity)); await ExecuteAsync("merge"); @@ -42,8 +42,8 @@ public async Task TestMerge() [Fact] public async Task TestDelete() { - EndpointMock.Setup(x => x.DeleteAsync(default)).Returns(Task.CompletedTask); + EndpointMock.Setup(x => x.DeleteAsync(It.IsAny())).Returns(Task.CompletedTask); await ExecuteAsync("delete"); } -} \ No newline at end of file +} diff --git a/src/UnitTests/CommandLine/Commands/Rpc/ActionCommandTest.cs b/src/UnitTests/CommandLine/Commands/Rpc/ActionCommandTest.cs index 612d6b09..1f640494 100644 --- a/src/UnitTests/CommandLine/Commands/Rpc/ActionCommandTest.cs +++ b/src/UnitTests/CommandLine/Commands/Rpc/ActionCommandTest.cs @@ -7,8 +7,8 @@ public class ActionCommandTest : CommandTestBase [Fact] public async Task TestInvoke() { - EndpointMock.Setup(x => x.InvokeAsync(default)).Returns(Task.CompletedTask); + EndpointMock.Setup(x => x.InvokeAsync(It.IsAny())).Returns(Task.CompletedTask); await ExecuteAsync(); } -} \ No newline at end of file +} diff --git a/src/UnitTests/CommandLine/Commands/Rpc/ConsumerCommandTest.cs b/src/UnitTests/CommandLine/Commands/Rpc/ConsumerCommandTest.cs index 8791b0bb..f46b30ab 100644 --- a/src/UnitTests/CommandLine/Commands/Rpc/ConsumerCommandTest.cs +++ b/src/UnitTests/CommandLine/Commands/Rpc/ConsumerCommandTest.cs @@ -10,8 +10,8 @@ public async Task TestInvoke() var input = new MockEntity(1, "a"); ConsoleMock.Setup(x => x.Read()).Returns(input); - EndpointMock.Setup(x => x.InvokeAsync(input, default)).Returns(Task.CompletedTask); + EndpointMock.Setup(x => x.InvokeAsync(input, It.IsAny())).Returns(Task.CompletedTask); await ExecuteAsync(); } -} \ No newline at end of file +} diff --git a/src/UnitTests/CommandLine/Commands/Rpc/FunctionCommandTest.cs b/src/UnitTests/CommandLine/Commands/Rpc/FunctionCommandTest.cs index bab77acb..cb8b54a6 100644 --- a/src/UnitTests/CommandLine/Commands/Rpc/FunctionCommandTest.cs +++ b/src/UnitTests/CommandLine/Commands/Rpc/FunctionCommandTest.cs @@ -11,9 +11,9 @@ public async Task TestInvoke() var output = new MockEntity(2, "b"); ConsoleMock.Setup(x => x.Read()).Returns(input); - EndpointMock.Setup(x => x.InvokeAsync(input, default)).ReturnsAsync(output); + EndpointMock.Setup(x => x.InvokeAsync(input, It.IsAny())).ReturnsAsync(output); ConsoleMock.Setup(x => x.Write(output)); await ExecuteAsync(); } -} \ No newline at end of file +} diff --git a/src/UnitTests/CommandLine/Commands/Rpc/ProducerCommandTest.cs b/src/UnitTests/CommandLine/Commands/Rpc/ProducerCommandTest.cs index f82cf635..f9af4235 100644 --- a/src/UnitTests/CommandLine/Commands/Rpc/ProducerCommandTest.cs +++ b/src/UnitTests/CommandLine/Commands/Rpc/ProducerCommandTest.cs @@ -9,10 +9,10 @@ public async Task TestInvoke() { var output = new MockEntity(2, "b"); - EndpointMock.Setup(x => x.InvokeAsync(default)) + EndpointMock.Setup(x => x.InvokeAsync(It.IsAny())) .Returns(Task.FromResult(output).AsITask()); ConsoleMock.Setup(x => x.Write(output)); await ExecuteAsync(); } -} \ No newline at end of file +} diff --git a/src/UnitTests/Endpoints/Generic/CollectionEndpointTest.cs b/src/UnitTests/Endpoints/Generic/CollectionEndpointTest.cs index 3008ae17..db5f908a 100644 --- a/src/UnitTests/Endpoints/Generic/CollectionEndpointTest.cs +++ b/src/UnitTests/Endpoints/Generic/CollectionEndpointTest.cs @@ -28,7 +28,7 @@ public async Task TestGetByIdWithLinkHeaderRelative() {"Link", "; rel=child; templated=true"} } }); - await _endpoint.ReadAllAsync(); + await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); _endpoint["1"] .Uri.Should().Be(new Uri("http://localhost/children?id=1")); @@ -46,7 +46,7 @@ public async Task TestGetByIdWithLinkHeaderAbsolute() {"Link", "; rel=child; templated=true"} } }); - await _endpoint.ReadAllAsync(); + await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); _endpoint["1"] .Uri.Should().Be(new Uri("http://localhost/children?id=1")); @@ -68,7 +68,7 @@ public async Task TestGetByEntityWithLinkHeaderRelative() {"Link", "; rel=child; templated=true"} } }); - await _endpoint.ReadAllAsync(); + await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); _endpoint[new MockEntity(1, "test")] .Uri.Should().Be(new Uri("http://localhost/children/1")); @@ -86,7 +86,7 @@ public async Task TestGetByEntityWithLinkHeaderAbsolute() {"Link", "; rel=child; templated=true"} } }); - await _endpoint.ReadAllAsync(); + await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); _endpoint[new MockEntity(1, "test")] .Uri.Should().Be(new Uri("http://localhost/children/1")); @@ -98,7 +98,7 @@ public async Task TestReadAll() Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .Respond(JsonMime, """[{"id":5,"name":"test1"},{"id":6,"name":"test2"}]"""); - var result = await _endpoint.ReadAllAsync(); + var result = await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); result.Should().Equal(new MockEntity(5, "test1"), new MockEntity(6, "test2")); } @@ -111,13 +111,13 @@ public async Task TestReadAllCache() Content = new StringContent("""[{"id":5,"name":"test1"},{"id":6,"name":"test2"}]""", Encoding.UTF8, JsonMime), Headers = {ETag = new("\"123abc\"")} }); - var result1 = await _endpoint.ReadAllAsync(); + var result1 = await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); result1.Should().Equal(new MockEntity(5, "test1"), new MockEntity(6, "test2")); Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .WithHeaders("If-None-Match", "\"123abc\"") .Respond(HttpStatusCode.NotModified); - var result2 = await _endpoint.ReadAllAsync(); + var result2 = await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); result2.Should().Equal(new MockEntity(5, "test1"), new MockEntity(6, "test2")); result2.Should().NotBeSameAs(result1, @@ -135,7 +135,7 @@ public async Task TestReadRangeOffset() Headers = {ContentRange = new(from: 1, to: 1, length: 2) {Unit = "elements"}} }); - var response = await _endpoint.ReadRangeAsync(new(from: 1, to: null)); + var response = await _endpoint.ReadRangeAsync(new(from: 1, to: null), TestContext.Current.CancellationToken); response.Elements.Should().Equal(new MockEntity(6, "test2")); response.Range.Should().Be(new ContentRangeHeaderValue(from: 1, to: 1, length: 2) {Unit = "elements"}); } @@ -151,7 +151,7 @@ public async Task TestReadRangeHead() Headers = {ContentRange = new(from: 0, to: 1, length: 2) {Unit = "elements"}} }); - var response = await _endpoint.ReadRangeAsync(new(from: 0, to: 1)); + var response = await _endpoint.ReadRangeAsync(new(from: 0, to: 1), TestContext.Current.CancellationToken); response.Elements.Should().Equal(new MockEntity(5, "test1"), new MockEntity(6, "test2")); response.Range.Should().Be(new ContentRangeHeaderValue(from: 0, to: 1, length: 2) {Unit = "elements"}); } @@ -167,7 +167,7 @@ public async Task TestReadRangeTail() Headers = {ContentRange = new(from: 2, to: 2) {Unit = "elements"}} }); - var response = await _endpoint.ReadRangeAsync(new(from: null, to: 1)); + var response = await _endpoint.ReadRangeAsync(new(from: null, to: 1), TestContext.Current.CancellationToken); response.Elements.Should().Equal(new MockEntity(6, "test2")); response.Range.Should().Be(new ContentRangeHeaderValue(from: 2, to: 2) {Unit = "elements"}); } @@ -182,7 +182,7 @@ public async Task TestReadRangeException() string? exceptionMessage = null; try { - await _endpoint.ReadRangeAsync(new RangeItemHeaderValue(from: 5, to: 10)); + await _endpoint.ReadRangeAsync(new RangeItemHeaderValue(from: 5, to: 10), TestContext.Current.CancellationToken); } catch (InvalidOperationException ex) { @@ -199,7 +199,7 @@ public async Task TestCreate() .WithContent("""{"id":0,"name":"test"}""") .Respond(JsonMime, """{"id":5,"name":"test"}"""); - var element = (await _endpoint.CreateAsync(new MockEntity(0, "test")))!; + var element = (await _endpoint.CreateAsync(new MockEntity(0, "test"), TestContext.Current.CancellationToken))!; element.Response.Should().Be(new MockEntity(5, "test")); element.Uri.Should().Be(new Uri("http://localhost/endpoint/5")); } @@ -215,7 +215,7 @@ public async Task TestCreateLocation() Headers = {Location = new Uri("/endpoint/new", UriKind.Relative)} }); - var element = (await _endpoint.CreateAsync(new MockEntity(0, "test")))!; + var element = (await _endpoint.CreateAsync(new MockEntity(0, "test"), TestContext.Current.CancellationToken))!; element.Response.Should().Be(new MockEntity(5, "test")); element.Uri.Should().Be(new Uri("http://localhost/endpoint/new")); } @@ -227,7 +227,7 @@ public async Task TestCreateNull() .WithContent("""{"id":0,"name":"test"}""") .Respond(_ => new(HttpStatusCode.Accepted)); - var element = (await _endpoint.CreateAsync(new MockEntity(0, "test")))!; + var element = (await _endpoint.CreateAsync(new MockEntity(0, "test"), TestContext.Current.CancellationToken))!; element.Should().BeNull(); } @@ -238,7 +238,7 @@ public async Task TestCreateAll() .WithContent("""[{"id":5,"name":"test1"},{"id":6,"name":"test2"}]""") .Respond(_ => new(HttpStatusCode.Accepted)); - await _endpoint.CreateAllAsync(new MockEntity[] {new(5, "test1"), new(6, "test2")}); + await _endpoint.CreateAllAsync(new MockEntity[] {new(5, "test1"), new(6, "test2")}, TestContext.Current.CancellationToken); } [Fact] @@ -248,7 +248,7 @@ public async Task TestSetAll() .WithContent("""[{"id":5,"name":"test1"},{"id":6,"name":"test2"}]""") .Respond(_ => new(HttpStatusCode.NoContent)); - await _endpoint.SetAllAsync(new MockEntity[] {new(5, "test1"), new(6, "test2")}); + await _endpoint.SetAllAsync(new MockEntity[] {new(5, "test1"), new(6, "test2")}, TestContext.Current.CancellationToken); } [Fact] @@ -260,12 +260,12 @@ public async Task TestSetAllETag() Content = new StringContent("""[{"id":5,"name":"test1"},{"id":6,"name":"test2"}]""", Encoding.UTF8, JsonMime), Headers = {ETag = new("\"123abc\"")} }); - var result = await _endpoint.ReadAllAsync(); + var result = await _endpoint.ReadAllAsync(TestContext.Current.CancellationToken); Mock.Expect(HttpMethod.Put, "http://localhost/endpoint") .WithContent("""[{"id":5,"name":"test1"},{"id":6,"name":"test2"}]""") .WithHeaders("If-Match", "\"123abc\"") .Respond(_ => new(HttpStatusCode.NoContent)); - await _endpoint.SetAllAsync(result); + await _endpoint.SetAllAsync(result, TestContext.Current.CancellationToken); } } diff --git a/src/UnitTests/Endpoints/Generic/ElementEndpointTestBase.cs b/src/UnitTests/Endpoints/Generic/ElementEndpointTestBase.cs index 333614c9..895a4f4b 100644 --- a/src/UnitTests/Endpoints/Generic/ElementEndpointTestBase.cs +++ b/src/UnitTests/Endpoints/Generic/ElementEndpointTestBase.cs @@ -15,7 +15,7 @@ public async Task TestRead() Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .Respond(JsonMime, """{"id":5,"name":"test"}"""); - var result = await Endpoint.ReadAsync(); + var result = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(5, "test")); } @@ -25,7 +25,7 @@ public async Task TestReadCustomMimeWithJsonSuffix() Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .Respond("application/sample+json", """{"id":5,"name":"test"}"""); - var result = await Endpoint.ReadAsync(); + var result = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(5, "test")); } @@ -38,13 +38,13 @@ public async Task TestReadCacheETag() Content = new StringContent("""{"id":5,"name":"test"}""", Encoding.UTF8, JsonMime), Headers = {ETag = new("\"123abc\"")} }); - var result1 = await Endpoint.ReadAsync(); + var result1 = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); result1.Should().Be(new MockEntity(5, "test")); Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .WithHeaders("If-None-Match", "\"123abc\"") .Respond(HttpStatusCode.NotModified); - var result2 = await Endpoint.ReadAsync(); + var result2 = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); result2.Should().Be(new MockEntity(5, "test")); result2.Should().NotBeSameAs(result1, @@ -62,13 +62,13 @@ public async Task TestReadCacheLastModified() Headers = {LastModified = new(new DateTime(2015, 10, 21), TimeSpan.Zero)} } }); - var result1 = await Endpoint.ReadAsync(); + var result1 = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); result1.Should().Be(new MockEntity(5, "test")); Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .WithHeaders("If-Modified-Since", "Wed, 21 Oct 2015 00:00:00 GMT") .Respond(HttpStatusCode.NotModified); - var result2 = await Endpoint.ReadAsync(); + var result2 = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); result2.Should().Be(new MockEntity(5, "test")); result2.Should().NotBeSameAs(result1, @@ -81,7 +81,7 @@ public async Task TestExistsTrue() Mock.Expect(HttpMethod.Head, "http://localhost/endpoint") .Respond(HttpStatusCode.OK); - bool result = await Endpoint.ExistsAsync(); + bool result = await Endpoint.ExistsAsync(TestContext.Current.CancellationToken); result.Should().BeTrue(); } @@ -91,7 +91,7 @@ public async Task TestExistsFalse() Mock.Expect(HttpMethod.Head, "http://localhost/endpoint") .Respond(HttpStatusCode.NotFound); - bool result = await Endpoint.ExistsAsync(); + bool result = await Endpoint.ExistsAsync(TestContext.Current.CancellationToken); result.Should().BeFalse(); } @@ -102,7 +102,7 @@ public async Task TestSetResult() .WithContent("""{"id":5,"name":"test"}""") .Respond(JsonMime, """{"id":5,"name":"testXXX"}"""); - var result = await Endpoint.SetAsync(new MockEntity(5, "test")); + var result = await Endpoint.SetAsync(new MockEntity(5, "test"), TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(5, "testXXX")); } @@ -113,7 +113,7 @@ public async Task TestSetNoResult() .WithContent("""{"id":5,"name":"test"}""") .Respond(HttpStatusCode.NoContent); - var result = await Endpoint.SetAsync(new MockEntity(5, "test")); + var result = await Endpoint.SetAsync(new MockEntity(5, "test"), TestContext.Current.CancellationToken); result.Should().BeNull(); } @@ -126,13 +126,13 @@ public async Task TestSetETag() Content = new StringContent("""{"id":5,"name":"test"}""", Encoding.UTF8, JsonMime), Headers = {ETag = new("\"123abc\"")} }); - var result = await Endpoint.ReadAsync(); + var result = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); Mock.Expect(HttpMethod.Put, "http://localhost/endpoint") .WithContent("""{"id":5,"name":"test"}""") .WithHeaders("If-Match", "\"123abc\"") .Respond(HttpStatusCode.NoContent); - await Endpoint.SetAsync(result); + await Endpoint.SetAsync(result, TestContext.Current.CancellationToken); } [Fact] @@ -146,13 +146,13 @@ public async Task TestSetLastModified() Headers = {LastModified = new(new DateTime(2015, 10, 21), TimeSpan.Zero)} } }); - var result = await Endpoint.ReadAsync(); + var result = await Endpoint.ReadAsync(TestContext.Current.CancellationToken); Mock.Expect(HttpMethod.Put, "http://localhost/endpoint") .WithContent("""{"id":5,"name":"test"}""") .WithHeaders("If-Unmodified-Since", "Wed, 21 Oct 2015 00:00:00 GMT") .Respond(HttpStatusCode.NoContent); - await Endpoint.SetAsync(result); + await Endpoint.SetAsync(result, TestContext.Current.CancellationToken); } [Fact] @@ -179,7 +179,7 @@ public async Task TestUpdateRetry() .WithHeaders("If-Match", "\"2\"") .Respond(HttpStatusCode.NoContent); - await Endpoint.UpdateAsync(x => x.Name = "testX"); + await Endpoint.UpdateAsync(x => x.Name = "testX", cancellationToken: TestContext.Current.CancellationToken); } [Fact] @@ -196,7 +196,7 @@ public async Task TestUpdateFail() .WithHeaders("If-Match", "\"1\"") .Respond(HttpStatusCode.PreconditionFailed); - await Assert.ThrowsAsync(() => Endpoint.UpdateAsync(x => x.Name = "testX", maxRetries: 0)); + await Assert.ThrowsAsync(() => Endpoint.UpdateAsync(x => x.Name = "testX", maxRetries: 0, cancellationToken: TestContext.Current.CancellationToken)); } [Fact] @@ -206,7 +206,7 @@ public async Task TestMergeResult() .WithContent("""{"id":5,"name":"test"}""") .Respond(JsonMime, """{"id":5,"name":"testXXX"}"""); - var result = await Endpoint.MergeAsync(new MockEntity(5, "test")); + var result = await Endpoint.MergeAsync(new MockEntity(5, "test"), TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(5, "testXXX")); } @@ -217,7 +217,7 @@ public async Task TestMergeNoResult() .WithContent("""{"id":5,"name":"test"}""") .Respond(HttpStatusCode.NoContent); - var result = await Endpoint.MergeAsync(new MockEntity(5, "test")); + var result = await Endpoint.MergeAsync(new MockEntity(5, "test"), TestContext.Current.CancellationToken); result.Should().BeNull(); } @@ -227,7 +227,7 @@ public async Task TestDelete() Mock.Expect(HttpMethod.Delete, "http://localhost/endpoint") .Respond(HttpStatusCode.NoContent); - await Endpoint.DeleteAsync(); + await Endpoint.DeleteAsync(TestContext.Current.CancellationToken); } [Fact] @@ -239,12 +239,12 @@ public async Task TestDeleteETag() Content = new StringContent("""{"id":5,"name":"test"}""", Encoding.UTF8, JsonMime), Headers = {ETag = new("\"123abc\"")} }); - await Endpoint.ReadAsync(); + await Endpoint.ReadAsync(TestContext.Current.CancellationToken); Mock.Expect(HttpMethod.Delete, "http://localhost/endpoint") .WithHeaders("If-Match", "\"123abc\"") .Respond(HttpStatusCode.NoContent); - await Endpoint.DeleteAsync(); + await Endpoint.DeleteAsync(TestContext.Current.CancellationToken); } } diff --git a/src/UnitTests/Endpoints/Generic/NewtonsoftJsonElementEndpointTest.cs b/src/UnitTests/Endpoints/Generic/NewtonsoftJsonElementEndpointTest.cs index 2bb5e4de..a44c2e52 100644 --- a/src/UnitTests/Endpoints/Generic/NewtonsoftJsonElementEndpointTest.cs +++ b/src/UnitTests/Endpoints/Generic/NewtonsoftJsonElementEndpointTest.cs @@ -12,7 +12,7 @@ public async Task TestJsonPatch() .WithContent("""[{"value":"testX","path":"/name","op":"replace"}]""") .Respond(JsonMime, """{"id":5,"name":"testX"}"""); - var result = await Endpoint.UpdateAsync(patch => patch.Replace(x => x.Name, "testX")); + var result = await Endpoint.UpdateAsync(patch => patch.Replace(x => x.Name, "testX"), cancellationToken: TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(5, "testX")); } @@ -31,7 +31,7 @@ public async Task TestJsonPatchFallback() .WithContent("""{"id":5,"name":"testX"}""") .Respond(JsonMime, """{"id":5,"name":"testX"}"""); - var result = await Endpoint.UpdateAsync(patch => patch.Replace(x => x.Name, "testX")); + var result = await Endpoint.UpdateAsync(patch => patch.Replace(x => x.Name, "testX"), cancellationToken: TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(5, "testX")); } } diff --git a/src/UnitTests/Endpoints/Raw/BlobEndpointTest.cs b/src/UnitTests/Endpoints/Raw/BlobEndpointTest.cs index e7ff04ab..5a19ba1c 100644 --- a/src/UnitTests/Endpoints/Raw/BlobEndpointTest.cs +++ b/src/UnitTests/Endpoints/Raw/BlobEndpointTest.cs @@ -16,7 +16,7 @@ public async Task TestProbe() Mock.Expect(HttpMethod.Options, "http://localhost/endpoint") .Respond(_ => new StringContent("") {Headers = {Allow = {HttpMethod.Put.Method}}}); - await _endpoint.ProbeAsync(); + await _endpoint.ProbeAsync(TestContext.Current.CancellationToken); _endpoint.DownloadAllowed.Should().BeFalse(); _endpoint.UploadAllowed.Should().BeTrue(); @@ -30,9 +30,13 @@ public async Task TestDownload() Mock.Expect(HttpMethod.Get, "http://localhost/endpoint") .Respond(_ => new ByteArrayContent(data)); - using var downloadStream = await _endpoint.DownloadAsync(); + using var downloadStream = await _endpoint.DownloadAsync(TestContext.Current.CancellationToken); using var memStream = new MemoryStream(); - await downloadStream.CopyToAsync(memStream); + await downloadStream.CopyToAsync(memStream +#if NET + , TestContext.Current.CancellationToken +#endif + ); memStream.ToArray().Should().Equal(data); } @@ -46,6 +50,6 @@ public async Task TestUpload() .Respond(HttpStatusCode.NoContent); using var stream = new MemoryStream(data); - await _endpoint.UploadFromAsync(stream, mimeType: "mock/type"); + await _endpoint.UploadFromAsync(stream, mimeType: "mock/type", cancellationToken: TestContext.Current.CancellationToken); } -} \ No newline at end of file +} diff --git a/src/UnitTests/Endpoints/Raw/UploadEndpointTest.cs b/src/UnitTests/Endpoints/Raw/UploadEndpointTest.cs index 905386bc..182b6466 100644 --- a/src/UnitTests/Endpoints/Raw/UploadEndpointTest.cs +++ b/src/UnitTests/Endpoints/Raw/UploadEndpointTest.cs @@ -15,7 +15,7 @@ public async Task TestUploadRaw() .Respond(HttpStatusCode.NoContent); using var stream = new MemoryStream(data); - await endpoint.UploadFromAsync(stream, mimeType: "mock/type"); + await endpoint.UploadFromAsync(stream, mimeType: "mock/type", cancellationToken: TestContext.Current.CancellationToken); } [Fact] @@ -30,6 +30,6 @@ public async Task TestUploadForm() .Respond(HttpStatusCode.NoContent); using var stream = new MemoryStream(data); - await endpoint.UploadFromAsync(stream, mimeType: "mock/type", fileName: "file.dat"); + await endpoint.UploadFromAsync(stream, mimeType: "mock/type", fileName: "file.dat", cancellationToken: TestContext.Current.CancellationToken); } } \ No newline at end of file diff --git a/src/UnitTests/Endpoints/Rpc/ActionEndpointTest.cs b/src/UnitTests/Endpoints/Rpc/ActionEndpointTest.cs index 6fa2be25..e836c060 100644 --- a/src/UnitTests/Endpoints/Rpc/ActionEndpointTest.cs +++ b/src/UnitTests/Endpoints/Rpc/ActionEndpointTest.cs @@ -16,7 +16,7 @@ public async Task TestProbe() Mock.Expect(HttpMethod.Options, "http://localhost/endpoint") .Respond(_ => new StringContent("") {Headers = {Allow = {"POST"}}}); - await _endpoint.ProbeAsync(); + await _endpoint.ProbeAsync(TestContext.Current.CancellationToken); _endpoint.InvokeAllowed.Should().BeTrue(); } @@ -27,6 +27,6 @@ public async Task TestInvoke() Mock.Expect(HttpMethod.Post, "http://localhost/endpoint") .Respond(HttpStatusCode.Accepted); - await _endpoint.InvokeAsync(); + await _endpoint.InvokeAsync(TestContext.Current.CancellationToken); } } \ No newline at end of file diff --git a/src/UnitTests/Endpoints/Rpc/ConsumerEndpointTest.cs b/src/UnitTests/Endpoints/Rpc/ConsumerEndpointTest.cs index 332ac430..53c2b789 100644 --- a/src/UnitTests/Endpoints/Rpc/ConsumerEndpointTest.cs +++ b/src/UnitTests/Endpoints/Rpc/ConsumerEndpointTest.cs @@ -17,6 +17,6 @@ public async Task TestInvoke() .WithContent("""{"id":1,"name":"input"}""") .Respond(HttpStatusCode.Accepted); - await _endpoint.InvokeAsync(new MockEntity(1, "input")); + await _endpoint.InvokeAsync(new MockEntity(1, "input"), TestContext.Current.CancellationToken); } } diff --git a/src/UnitTests/Endpoints/Rpc/FunctionEndpointTest.cs b/src/UnitTests/Endpoints/Rpc/FunctionEndpointTest.cs index 3b427e17..3585491a 100644 --- a/src/UnitTests/Endpoints/Rpc/FunctionEndpointTest.cs +++ b/src/UnitTests/Endpoints/Rpc/FunctionEndpointTest.cs @@ -17,7 +17,7 @@ public async Task TestInvoke() .WithContent("""{"id":1,"name":"input"}""") .Respond(JsonMime, """{"id":2,"name":"result"}"""); - var result = await _endpoint.InvokeAsync(new MockEntity(1, "input")); + var result = await _endpoint.InvokeAsync(new MockEntity(1, "input"), TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(2, "result")); } } diff --git a/src/UnitTests/Endpoints/Rpc/ProducerEndpointTest.cs b/src/UnitTests/Endpoints/Rpc/ProducerEndpointTest.cs index a1791893..3181f3ae 100644 --- a/src/UnitTests/Endpoints/Rpc/ProducerEndpointTest.cs +++ b/src/UnitTests/Endpoints/Rpc/ProducerEndpointTest.cs @@ -16,7 +16,7 @@ public async Task TestInvoke() Mock.Expect(HttpMethod.Post, "http://localhost/endpoint") .Respond(JsonMime, """{"id":2,"name":"result"}"""); - var result = await _endpoint.InvokeAsync(); + var result = await _endpoint.InvokeAsync(TestContext.Current.CancellationToken); result.Should().Be(new MockEntity(2, "result")); } } diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index bb40ba99..e2f69e6d 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -4,6 +4,7 @@ TypedRest net48;net10.0 + Exe False False False @@ -28,7 +29,7 @@ - +