diff --git a/build/Common.tests.props b/build/Common.tests.props
index 71b4578e..8a533a23 100644
--- a/build/Common.tests.props
+++ b/build/Common.tests.props
@@ -29,7 +29,7 @@
-
+ runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -46,7 +46,7 @@
[3.1.2][6.7.0][17.3.2]
- [4.18.2]
+ [5.0.0][2.4.3,3.0)[2.4.1,3.0)
diff --git a/test/OpenFeature.Contrib.Providers.Flagd.Test/FlagdProviderTest.cs b/test/OpenFeature.Contrib.Providers.Flagd.Test/FlagdProviderTest.cs
index e1115505..caf3de18 100644
--- a/test/OpenFeature.Contrib.Providers.Flagd.Test/FlagdProviderTest.cs
+++ b/test/OpenFeature.Contrib.Providers.Flagd.Test/FlagdProviderTest.cs
@@ -1,5 +1,4 @@
using Xunit;
-using Moq;
using OpenFeature.Flagd.Grpc;
using Grpc.Core;
using Google.Protobuf.WellKnownTypes;
@@ -9,6 +8,7 @@
using OpenFeature.Model;
using System.Threading;
using System;
+using NSubstitute;
namespace OpenFeature.Contrib.Providers.Flagd.Test
{
@@ -120,8 +120,10 @@ public void TestGetProviderWithConfig()
[Fact]
public void TestResolveBooleanValue()
{
- var resp = new ResolveBooleanResponse();
- resp.Value = true;
+ var resp = new ResolveBooleanResponse
+ {
+ Value = true
+ };
var grpcResp = new AsyncUnaryCall(
System.Threading.Tasks.Task.FromResult(resp),
@@ -130,13 +132,13 @@ public void TestResolveBooleanValue()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveBooleanAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var substituteGrpcClient = Substitute.For();
+ substituteGrpcClient
+ .ResolveBooleanAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(substituteGrpcClient, new FlagdConfig());
// resolve with default set to false to make sure we return what the grpc server gives us
var val = flagdProvider.ResolveBooleanValue("my-key", false, null);
@@ -147,8 +149,7 @@ public void TestResolveBooleanValue()
[Fact]
public void TestResolveStringValue()
{
- var resp = new ResolveStringResponse();
- resp.Value = "my-value";
+ var resp = new ResolveStringResponse { Value = "my-value" };
var grpcResp = new AsyncUnaryCall(
System.Threading.Tasks.Task.FromResult(resp),
@@ -157,13 +158,13 @@ public void TestResolveStringValue()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveStringAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var subGrpcClient = Substitute.For();
+
+ subGrpcClient.ResolveStringAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(subGrpcClient, new FlagdConfig());
var val = flagdProvider.ResolveStringValue("my-key", "", null);
@@ -173,8 +174,10 @@ public void TestResolveStringValue()
[Fact]
public void TestResolveIntegerValue()
{
- var resp = new ResolveIntResponse();
- resp.Value = 10;
+ var resp = new ResolveIntResponse
+ {
+ Value = 10
+ };
var grpcResp = new AsyncUnaryCall(
System.Threading.Tasks.Task.FromResult(resp),
@@ -183,13 +186,11 @@ public void TestResolveIntegerValue()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveIntAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var subGrpcClient = Substitute.For();
+ subGrpcClient.ResolveIntAsync(Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(subGrpcClient, new FlagdConfig());
var val = flagdProvider.ResolveIntegerValue("my-key", 0, null);
@@ -199,8 +200,10 @@ public void TestResolveIntegerValue()
[Fact]
public void TestResolveDoubleValue()
{
- var resp = new ResolveFloatResponse();
- resp.Value = 10.0;
+ var resp = new ResolveFloatResponse
+ {
+ Value = 10.0
+ };
var grpcResp = new AsyncUnaryCall(
System.Threading.Tasks.Task.FromResult(resp),
@@ -209,13 +212,11 @@ public void TestResolveDoubleValue()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveFloatAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveFloatAsync(Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(mockGrpcClient, new FlagdConfig());
var val = flagdProvider.ResolveDoubleValue("my-key", 0.0, null);
@@ -240,13 +241,11 @@ public void TestResolveStructureValue()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveObjectAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveObjectAsync(Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(mockGrpcClient, new FlagdConfig());
var val = flagdProvider.ResolveStructureValue("my-key", null, null);
@@ -265,13 +264,11 @@ public void TestResolveFlagNotFound()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveBooleanAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
- .Returns(grpcResp);
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveBooleanAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None).Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(mockGrpcClient, new FlagdConfig());
// make sure the correct exception is thrown
Assert.ThrowsAsync(async () =>
@@ -301,13 +298,12 @@ public void TestResolveGrpcHostUnavailable()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveBooleanAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveBooleanAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(mockGrpcClient, new FlagdConfig());
// make sure the correct exception is thrown
Assert.ThrowsAsync(async () =>
@@ -337,13 +333,12 @@ public void TestResolveTypeMismatch()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveBooleanAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveBooleanAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(mockGrpcClient, new FlagdConfig());
// make sure the correct exception is thrown
Assert.ThrowsAsync(async () =>
@@ -373,13 +368,12 @@ public void TestResolveUnknownError()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveBooleanAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveBooleanAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var flagdProvider = new FlagdProvider(mockGrpcClient.Object, new FlagdConfig());
+ var flagdProvider = new FlagdProvider(mockGrpcClient, new FlagdConfig());
// make sure the correct exception is thrown
Assert.ThrowsAsync(async () =>
@@ -411,13 +405,12 @@ public void TestCache()
() => new Grpc.Core.Metadata(),
() => { });
- var mockGrpcClient = new Mock();
- mockGrpcClient
- .Setup(m => m.ResolveBooleanAsync(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ var mockGrpcClient = Substitute.For();
+ mockGrpcClient.ResolveBooleanAsync(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcResp);
- var asyncStreamReader = new Mock>();
+ var asyncStreamReader = Substitute.For>();
var l = new List
{
@@ -431,8 +424,8 @@ public void TestCache()
// create an autoResetEvent which we will wait for in our test verification
var _autoResetEvent = new AutoResetEvent(false);
- asyncStreamReader.Setup(a => a.MoveNext(It.IsAny())).ReturnsAsync(() => enumerator.MoveNext());
- asyncStreamReader.Setup(a => a.Current).Returns(() =>
+ asyncStreamReader.MoveNext(Arg.Any()).Returns(enumerator.MoveNext());
+ asyncStreamReader.Current.Returns(_ =>
{
// set the autoResetEvent since this path should be the last one that's reached in the background task
_autoResetEvent.Set();
@@ -440,7 +433,7 @@ public void TestCache()
});
var grpcEventStreamResp = new AsyncServerStreamingCall(
- asyncStreamReader.Object,
+ asyncStreamReader,
null,
null,
null,
@@ -448,37 +441,37 @@ public void TestCache()
null
);
- mockGrpcClient
- .Setup(m => m.EventStream(
- It.IsAny(), null, null, System.Threading.CancellationToken.None))
+ mockGrpcClient.EventStream(
+ Arg.Any(), null, null, System.Threading.CancellationToken.None)
.Returns(grpcEventStreamResp);
- var mockCache = new Mock>();
- mockCache.Setup(c => c.TryGet(It.Is(s => s == "my-key"))).Returns(() => null);
- mockCache.Setup(c => c.Add(It.Is(s => s == "my-key"), It.IsAny