Skip to content

Commit edd4994

Browse files
committed
Refactor: Replace direct EventCallbackFactory usage with EventCallback.Factory in debouncer tests
1 parent eac882d commit edd4994

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

tests/Tests.CodeOfChaos.Extensions.AspNetCore/EventCallbacks/EventCallbackDebouncerGenericTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ namespace Tests.CodeOfChaos.Extensions.AspNetCore.EventCallbacks;
88
// Code
99
// ---------------------------------------------------------------------------------------------------------------------
1010
public class EventCallbackDebouncerGenericTests {
11-
private readonly EventCallbackFactory _factory = new();
1211

1312
[Test]
1413
public async Task GenericDebouncer_ShouldPassValueToCallback() {
1514
// Arrange
1615
string? receivedValue = null;
17-
EventCallback<string> callback = _factory.Create<string>(this, callback: value => {
16+
EventCallback<string> callback = EventCallback.Factory.Create<string>(this, callback: value => {
1817
receivedValue = value;
1918
return Task.CompletedTask;
2019
});
@@ -32,7 +31,7 @@ public async Task GenericDebouncer_ShouldPassValueToCallback() {
3231
public async Task GenericDebouncer_DefaultValue_ShouldWork() {
3332
// Arrange
3433
string receivedValue = "initial";
35-
EventCallback<string> callback = _factory.Create<string>(this, callback: value => {
34+
EventCallback<string> callback = EventCallback.Factory.Create<string>(this, callback: value => {
3635
receivedValue = value;
3736
return Task.CompletedTask;
3837
});
@@ -50,7 +49,7 @@ public async Task GenericDebouncer_DefaultValue_ShouldWork() {
5049
public async Task GenericDebouncer_MultipleValues_ShouldUseLastValue() {
5150
// Arrange
5251
string? receivedValue = null;
53-
EventCallback<string> callback = _factory.Create<string>(this, callback: value => {
52+
EventCallback<string> callback = EventCallback.Factory.Create<string>(this, callback: value => {
5453
receivedValue = value;
5554
return Task.CompletedTask;
5655
});
@@ -70,7 +69,7 @@ public async Task GenericDebouncer_MultipleValues_ShouldUseLastValue() {
7069
public async Task GenericDebouncer_ConcurrentValues_ShouldBeThreadSafe() {
7170
// Arrange
7271
var receivedValues = new List<string>();
73-
EventCallback<string> callback = _factory.Create<string>(this, callback: value => {
72+
EventCallback<string> callback = EventCallback.Factory.Create<string>(this, callback: value => {
7473
receivedValues.Add(value);
7574
return Task.CompletedTask;
7675
});
@@ -91,21 +90,22 @@ public async Task GenericDebouncer_ConcurrentValues_ShouldBeThreadSafe() {
9190
[Test]
9291
public async Task GenericDebouncer_AfterDispose_ShouldThrowObjectDisposedException() {
9392
// Arrange
94-
EventCallback<string> callback = _factory.Create<string>(this, callback: _ => Task.CompletedTask);
93+
EventCallback<string> callback = EventCallback.Factory.Create<string>(this, callback: _ => Task.CompletedTask);
9594
var debouncer = new EventCallbackDebouncer<string>(callback);
9695

9796
// Act
9897
await debouncer.DisposeAsync();
9998

10099
// Assert
101100
await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
102-
await debouncer.InvokeDebouncedAsync("test"));
101+
await debouncer.InvokeDebouncedAsync("test")
102+
);
103103
}
104104

105105
[Test]
106106
public async Task GenericDebouncer_MultipleDispose_ShouldBeIdempotent() {
107107
// Arrange
108-
EventCallback<string> callback = _factory.Create<string>(this, callback: _ => Task.CompletedTask);
108+
EventCallback<string> callback = EventCallback.Factory.Create<string>(this, callback: _ => Task.CompletedTask);
109109
var debouncer = new EventCallbackDebouncer<string>(callback);
110110

111111
// Act & Assert

tests/Tests.CodeOfChaos.Extensions.AspNetCore/EventCallbacks/EventCallbackDebouncerTests.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ namespace Tests.CodeOfChaos.Extensions.AspNetCore.EventCallbacks;
88
// Code
99
// ---------------------------------------------------------------------------------------------------------------------
1010
public class EventCallbackDebouncerTests {
11-
private readonly EventCallbackFactory _factory = new();
1211

1312
[Test]
1413
public async Task DefaultDebounceMs_ShouldBe100() {
1514
// Arrange
1615
int callCount = 0;
17-
EventCallback callback = _factory.Create(this, callback: () => {
16+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => {
1817
callCount++;
1918
return Task.CompletedTask;
2019
});
@@ -32,7 +31,7 @@ public async Task DefaultDebounceMs_ShouldBe100() {
3231
public async Task CustomDebounceMs_ShouldRespectSpecifiedTime() {
3332
// Arrange
3433
int callCount = 0;
35-
EventCallback callback = _factory.Create(this, callback: () => {
34+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => {
3635
callCount++;
3736
return Task.CompletedTask;
3837
});
@@ -56,7 +55,7 @@ public async Task CustomDebounceMs_ShouldRespectSpecifiedTime() {
5655
public async Task MultipleInvocations_ShouldDebounce() {
5756
// Arrange
5857
int callCount = 0;
59-
EventCallback callback = _factory.Create(this, callback: () => {
58+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => {
6059
callCount++;
6160
return Task.CompletedTask;
6261
});
@@ -76,7 +75,7 @@ public async Task MultipleInvocations_ShouldDebounce() {
7675
public async Task ConcurrentInvocations_ShouldBeThreadSafe() {
7776
// Arrange
7877
int callCount = 0;
79-
EventCallback callback = _factory.Create(this, callback: () => {
78+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => {
8079
callCount++;
8180
return Task.CompletedTask;
8281
});
@@ -97,7 +96,7 @@ public async Task ConcurrentInvocations_ShouldBeThreadSafe() {
9796
[Test]
9897
public async Task AfterDispose_ShouldThrowObjectDisposedException() {
9998
// Arrange
100-
EventCallback callback = _factory.Create(this, callback: () => Task.CompletedTask);
99+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => Task.CompletedTask);
101100
var debouncer = new EventCallbackDebouncer(callback);
102101

103102
// Act
@@ -111,7 +110,7 @@ await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
111110
[Test]
112111
public async Task MultipleDispose_ShouldBeIdempotent() {
113112
// Arrange
114-
EventCallback callback = _factory.Create(this, callback: () => Task.CompletedTask);
113+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => Task.CompletedTask);
115114
var debouncer = new EventCallbackDebouncer(callback);
116115

117116
// Act & Assert
@@ -123,15 +122,15 @@ public async Task MultipleDispose_ShouldBeIdempotent() {
123122
public async Task InvocationDuringDebounce_ShouldCancelPrevious() {
124123
// Arrange
125124
var executionTimes = new List<DateTime>();
126-
EventCallback callback = _factory.Create(this, callback: () => {
125+
EventCallback callback = EventCallback.Factory.Create(this, callback: () => {
127126
executionTimes.Add(DateTime.UtcNow);
128127
return Task.CompletedTask;
129128
});
130129

131130
// Act
132131
await using var debouncer = new EventCallbackDebouncer(callback);
133132
await debouncer.InvokeDebouncedAsync();
134-
await Task.Delay(50); // Wait half the debounced time
133+
await Task.Delay(50);// Wait half the debounced time
135134
await debouncer.InvokeDebouncedAsync();
136135
await Task.Delay(150);
137136

0 commit comments

Comments
 (0)