Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/UnitTests/CommandLine/Commands/Generic/ElementCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CancellationToken>())).ReturnsAsync(entity);

await ExecuteAsync();
}
Expand All @@ -21,7 +21,7 @@ public async Task TestSet()
var entity = new MockEntity(5, "test");

ConsoleMock.Setup(x => x.Read<MockEntity>()).Returns(entity);
EndpointMock.Setup(x => x.SetAsync(entity, default)).ReturnsAsync(entity);
EndpointMock.Setup(x => x.SetAsync(entity, It.IsAny<CancellationToken>())).ReturnsAsync(entity);
ConsoleMock.Setup(x => x.Write(entity));

await ExecuteAsync("set");
Expand All @@ -33,7 +33,7 @@ public async Task TestMerge()
var entity = new MockEntity(5, "test");

ConsoleMock.Setup(x => x.Read<MockEntity>()).Returns(entity);
EndpointMock.Setup(x => x.MergeAsync(entity, default)).ReturnsAsync(entity);
EndpointMock.Setup(x => x.MergeAsync(entity, It.IsAny<CancellationToken>())).ReturnsAsync(entity);
ConsoleMock.Setup(x => x.Write(entity));

await ExecuteAsync("merge");
Expand All @@ -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<CancellationToken>())).Returns(Task.CompletedTask);

await ExecuteAsync("delete");
}
}
}
4 changes: 2 additions & 2 deletions src/UnitTests/CommandLine/Commands/Rpc/ActionCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class ActionCommandTest : CommandTestBase<ActionCommand, IActionEndpoint>
[Fact]
public async Task TestInvoke()
{
EndpointMock.Setup(x => x.InvokeAsync(default)).Returns(Task.CompletedTask);
EndpointMock.Setup(x => x.InvokeAsync(It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

await ExecuteAsync();
}
}
}
4 changes: 2 additions & 2 deletions src/UnitTests/CommandLine/Commands/Rpc/ConsumerCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public async Task TestInvoke()
var input = new MockEntity(1, "a");

ConsoleMock.Setup(x => x.Read<MockEntity>()).Returns(input);
EndpointMock.Setup(x => x.InvokeAsync(input, default)).Returns(Task.CompletedTask);
EndpointMock.Setup(x => x.InvokeAsync(input, It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

await ExecuteAsync();
}
}
}
4 changes: 2 additions & 2 deletions src/UnitTests/CommandLine/Commands/Rpc/FunctionCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public async Task TestInvoke()
var output = new MockEntity(2, "b");

ConsoleMock.Setup(x => x.Read<MockEntity>()).Returns(input);
EndpointMock.Setup(x => x.InvokeAsync(input, default)).ReturnsAsync(output);
EndpointMock.Setup(x => x.InvokeAsync(input, It.IsAny<CancellationToken>())).ReturnsAsync(output);
ConsoleMock.Setup(x => x.Write(output));

await ExecuteAsync();
}
}
}
4 changes: 2 additions & 2 deletions src/UnitTests/CommandLine/Commands/Rpc/ProducerCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CancellationToken>()))
.Returns(Task.FromResult(output).AsITask());
ConsoleMock.Setup(x => x.Write(output));

await ExecuteAsync();
}
}
}
36 changes: 18 additions & 18 deletions src/UnitTests/Endpoints/Generic/CollectionEndpointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task TestGetByIdWithLinkHeaderRelative()
{"Link", "<children{?id}>; 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"));
Expand All @@ -46,7 +46,7 @@ public async Task TestGetByIdWithLinkHeaderAbsolute()
{"Link", "<http://localhost/children{?id}>; 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"));
Expand All @@ -68,7 +68,7 @@ public async Task TestGetByEntityWithLinkHeaderRelative()
{"Link", "<children/{id}>; 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"));
Expand All @@ -86,7 +86,7 @@ public async Task TestGetByEntityWithLinkHeaderAbsolute()
{"Link", "<http://localhost/children/{id}>; 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"));
Expand All @@ -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"));
}

Expand All @@ -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,
Expand All @@ -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"});
}
Expand All @@ -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"});
}
Expand All @@ -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"});
}
Expand All @@ -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)
{
Expand All @@ -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"));
}
Expand All @@ -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"));
}
Expand All @@ -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();
}

Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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);
}
}
Loading