Skip to content

Commit 3faaab2

Browse files
committed
Add test showing exception when nullable parameter is called with null argument
1 parent 4d5a68a commit 3faaab2

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

source/Halibut.TestUtils.CompatBinary.Base/DelegateCountingService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public int Increment()
1616
return countingService.Increment();
1717
}
1818

19+
public int Increment(int? number)
20+
{
21+
return countingService.Increment(number);
22+
}
23+
1924
public int GetCurrentValue()
2025
{
2126
return countingService.GetCurrentValue();

source/Halibut.TestUtils.Contracts/CountingService.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ public class CountingService : ICountingService
88
int count;
99
public int Increment()
1010
{
11-
return Interlocked.Increment(ref count);
11+
return Increment(1);
12+
}
13+
14+
public int Increment(int? number)
15+
{
16+
var increment = number ?? 1;
17+
var counter = 0;
18+
19+
for (var i = 0; i < increment; i++)
20+
{
21+
counter = Interlocked.Increment(ref count);
22+
}
23+
24+
return counter;
1225
}
1326

1427
public int GetCurrentValue()
@@ -26,6 +39,12 @@ public async Task<int> IncrementAsync(CancellationToken cancellationToken)
2639
return service.Increment();
2740
}
2841

42+
public async Task<int> IncrementAsync(int? number, CancellationToken cancellationToken)
43+
{
44+
await Task.CompletedTask;
45+
return service.Increment(number);
46+
}
47+
2948
public async Task<int> GetCurrentValueAsync(CancellationToken cancellationToken)
3049
{
3150
await Task.CompletedTask;

source/Halibut.TestUtils.Contracts/ICountingService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ namespace Halibut.TestUtils.Contracts
66
public interface ICountingService
77
{
88
public int Increment();
9+
public int Increment(int? number);
910
public int GetCurrentValue();
1011
}
1112

1213
public interface IAsyncCountingService
1314
{
1415
public Task<int> IncrementAsync(CancellationToken cancellationToken);
16+
public Task<int> IncrementAsync(int? number, CancellationToken cancellationToken);
1517
public Task<int> GetCurrentValueAsync(CancellationToken cancellationToken);
1618
}
1719
}

source/Halibut.Tests/ServiceModel/ServiceInvokerFixture.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ public async Task AsyncInvokeWithNoParamsOnAsyncService()
5353
response.Result.Should().Be(1);
5454
}
5555

56+
[Test]
57+
public async Task AsyncInvokeWithNullableParamsOnAsyncService()
58+
{
59+
var serviceFactory = new ServiceFactoryBuilder()
60+
.WithConventionVerificationDisabled()
61+
.WithService<ICountingService, IAsyncCountingService>(() => new AsyncCountingService())
62+
.Build();
63+
64+
var sut = new ServiceInvoker(serviceFactory);
65+
var request = new RequestMessage()
66+
{
67+
ServiceName = nameof(ICountingService),
68+
MethodName = nameof(ICountingService.Increment),
69+
Params = new object[] { null! },
70+
};
71+
72+
var response = await sut.InvokeAsync(request);
73+
response.Result.Should().Be(1);
74+
}
75+
5676
[Test]
5777
public async Task AsyncInvokeWithNoParams_AsyncServiceMissingSuffix()
5878
{

0 commit comments

Comments
 (0)