-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for CreateSliceProxy & CreateProtobufClient (#3835)
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
tests/IceRpc.Protobuf.Tests/ServiceProviderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
namespace IceRpc.Protobuf.Tests; | ||
|
||
[Parallelizable(scope: ParallelScope.All)] | ||
public partial class ServiceProviderExtensionsTests | ||
{ | ||
[Test] | ||
public void Create_protobuf_client_with_no_params() | ||
{ | ||
var serviceCollection = | ||
new ServiceCollection() | ||
.AddSingleton(InvalidInvoker.Instance) | ||
.AddSingleton<IMyOperations>(provider => provider.CreateProtobufClient<MyOperationsClient>()); | ||
|
||
var provider = serviceCollection.BuildServiceProvider(validateScopes: true); | ||
|
||
var client = (IProtobufClient?)provider.GetService<IMyOperations>(); | ||
Assert.That(client, Is.Not.Null); | ||
Assert.That(client.Invoker, Is.EqualTo(InvalidInvoker.Instance)); | ||
Assert.That(client.ServiceAddress.Path, Is.EqualTo(MyOperationsClient.DefaultServicePath)); | ||
Assert.That(client.EncodeOptions, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void Create_protobuf_client_without_invoker_fails() | ||
{ | ||
var serviceCollection = | ||
new ServiceCollection() | ||
.AddSingleton<IMyOperations>(provider => provider.CreateProtobufClient<MyOperationsClient>()); | ||
|
||
var provider = serviceCollection.BuildServiceProvider(validateScopes: true); | ||
Assert.That(() => provider.GetService<IMyOperations>(), Throws.InvalidOperationException); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/IceRpc.Slice.Tests/ServiceProviderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
namespace IceRpc.Slice.Tests; | ||
|
||
[Parallelizable(scope: ParallelScope.All)] | ||
public partial class ServiceProviderExtensionsTests | ||
{ | ||
[Test] | ||
public void Create_slice_proxy_with_no_params() | ||
{ | ||
var serviceCollection = | ||
new ServiceCollection() | ||
.AddSingleton(InvalidInvoker.Instance) | ||
.AddSingleton<IMyOperationsA>(provider => provider.CreateSliceProxy<MyOperationsAProxy>()); | ||
|
||
var provider = serviceCollection.BuildServiceProvider(validateScopes: true); | ||
|
||
var proxy = (IProxy?)provider.GetService<IMyOperationsA>(); | ||
Assert.That(proxy, Is.Not.Null); | ||
Assert.That(proxy.Invoker, Is.EqualTo(InvalidInvoker.Instance)); | ||
Assert.That(proxy.ServiceAddress.Path, Is.EqualTo(MyOperationsAProxy.DefaultServicePath)); | ||
Assert.That(proxy.EncodeOptions, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void Create_slice_proxy_without_invoker_fails() | ||
{ | ||
var serviceCollection = | ||
new ServiceCollection() | ||
.AddSingleton<IMyOperationsA>(provider => provider.CreateSliceProxy<MyOperationsAProxy>()); | ||
|
||
var provider = serviceCollection.BuildServiceProvider(validateScopes: true); | ||
Assert.That(() => provider.GetService<IMyOperationsA>(), Throws.InvalidOperationException); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters