Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove FluentAssertions #361

Merged
merged 10 commits into from
Feb 10, 2025
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dotnet test test/OpenFeature.Tests/
To be able to run the e2e tests, first we need to initialize the submodule and copy the test files:

```bash
git submodule update --init --recursive && cp test-harness/features/evaluation.feature test/OpenFeature.E2ETests/Features/
git submodule update --init --recursive && cp spec/specification/assets/gherkin/evaluation.feature test/OpenFeature.E2ETests/Features/
```

Now you can run the tests using:
Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="FluentAssertions" Version="7.1.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="9.1.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -44,7 +43,7 @@ public async Task EnsureInitializedAsync_ShouldLogAndSetProvider_WhenProviderExi
await _systemUnderTest.EnsureInitializedAsync().ConfigureAwait(true);

// Assert
Api.Instance.GetProvider().Should().BeSameAs(featureProvider);
Assert.Equal(featureProvider, Api.Instance.GetProvider());
}

[Fact]
Expand All @@ -58,7 +57,7 @@ public async Task EnsureInitializedAsync_ShouldThrowException_WhenProviderDoesNo

// Assert
var exception = await Assert.ThrowsAsync<InvalidOperationException>(act).ConfigureAwait(true);
exception.Should().NotBeNull();
exception.Message.Should().NotBeNullOrWhiteSpace();
Assert.NotNull(exception);
Assert.False(string.IsNullOrWhiteSpace(exception.Message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenFeature.Model;
Expand Down Expand Up @@ -28,12 +27,11 @@ public void AddContext_Delegate_ShouldAddServiceToCollection(bool useServiceProv
_systemUnderTest.AddContext((_, _) => { });

// Assert
featureBuilder.Should().BeSameAs(_systemUnderTest, "The method should return the same builder instance.");
_systemUnderTest.IsContextConfigured.Should().BeTrue("The context should be configured.");
_services.Should().ContainSingle(serviceDescriptor =>
Assert.Equal(_systemUnderTest, featureBuilder);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.True(_systemUnderTest.IsContextConfigured, "The context should be configured.");
Assert.Single(_services, serviceDescriptor =>
serviceDescriptor.ServiceType == typeof(EvaluationContext) &&
serviceDescriptor.Lifetime == ServiceLifetime.Transient,
"A transient service of type EvaluationContext should be added.");
serviceDescriptor.Lifetime == ServiceLifetime.Transient);
}

[Theory]
Expand All @@ -54,9 +52,9 @@ public void AddContext_Delegate_ShouldCorrectlyHandles(bool useServiceProviderDe
var context = serviceProvider.GetService<EvaluationContext>();

// Assert
_systemUnderTest.IsContextConfigured.Should().BeTrue("The context should be configured.");
context.Should().NotBeNull("The EvaluationContext should be resolvable.");
delegateCalled.Should().BeTrue("The delegate should be invoked.");
Assert.True(_systemUnderTest.IsContextConfigured, "The context should be configured.");
Assert.NotNull(context);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.True(delegateCalled, "The delegate should be invoked.");
}

#if NET8_0_OR_GREATER
Expand All @@ -80,15 +78,14 @@ public void AddProvider_ShouldAddProviderToCollection(int providerRegistrationTy
};

// Assert
_systemUnderTest.IsContextConfigured.Should().BeFalse("The context should not be configured.");
_systemUnderTest.HasDefaultProvider.Should().Be(expectsDefaultProvider, "The default provider flag should be set correctly.");
_systemUnderTest.IsPolicyConfigured.Should().BeFalse("The policy should not be configured.");
_systemUnderTest.DomainBoundProviderRegistrationCount.Should().Be(expectsDomainBoundProvider, "The domain-bound provider count should be correct.");
featureBuilder.Should().BeSameAs(_systemUnderTest, "The method should return the same builder instance.");
_services.Should().ContainSingle(serviceDescriptor =>
Assert.False(_systemUnderTest.IsContextConfigured, "The context should not be configured.");
Assert.Equal(expectsDefaultProvider, _systemUnderTest.HasDefaultProvider);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.False(_systemUnderTest.IsPolicyConfigured, "The policy should not be configured.");
Assert.Equal(expectsDomainBoundProvider, _systemUnderTest.DomainBoundProviderRegistrationCount);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(_systemUnderTest, featureBuilder);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.Single(_services, serviceDescriptor =>
serviceDescriptor.ServiceType == typeof(FeatureProvider) &&
serviceDescriptor.Lifetime == ServiceLifetime.Transient,
"A singleton service of type FeatureProvider should be added.");
serviceDescriptor.Lifetime == ServiceLifetime.Transient);
}

class TestOptions : OpenFeatureOptions { }
Expand Down Expand Up @@ -124,8 +121,8 @@ public void AddProvider_ShouldResolveCorrectProvider(int providerRegistrationTyp
};

// Assert
provider.Should().NotBeNull("The FeatureProvider should be resolvable.");
provider.Should().BeOfType<NoOpFeatureProvider>("The resolved provider should be of type DefaultFeatureProvider.");
Assert.NotNull(provider);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.IsType<NoOpFeatureProvider>(provider);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
}

[Theory]
Expand Down Expand Up @@ -172,11 +169,11 @@ public void AddProvider_VerifiesDefaultAndDomainBoundProvidersBasedOnConfigurati
};

// Assert
_systemUnderTest.IsContextConfigured.Should().BeFalse("The context should not be configured.");
_systemUnderTest.HasDefaultProvider.Should().Be(expectsDefaultProvider, "The default provider flag should be set correctly.");
_systemUnderTest.IsPolicyConfigured.Should().BeFalse("The policy should not be configured.");
_systemUnderTest.DomainBoundProviderRegistrationCount.Should().Be(expectsDomainBoundProvider, "The domain-bound provider count should be correct.");
featureBuilder.Should().BeSameAs(_systemUnderTest, "The method should return the same builder instance.");
Assert.False(_systemUnderTest.IsContextConfigured, "The context should not be configured.");
Assert.Equal(expectsDefaultProvider, _systemUnderTest.HasDefaultProvider);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.False(_systemUnderTest.IsPolicyConfigured, "The policy should not be configured.");
Assert.Equal(expectsDomainBoundProvider, _systemUnderTest.DomainBoundProviderRegistrationCount);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(_systemUnderTest, featureBuilder);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
}

[Theory]
Expand Down Expand Up @@ -240,8 +237,8 @@ public void AddProvider_ConfiguresPolicyNameAcrossMultipleProviderSetups(int pro
serviceProvider.GetRequiredKeyedService<FeatureProvider>(name);

// Assert
featureBuilder.IsPolicyConfigured.Should().BeTrue("The policy should be configured.");
provider.Should().NotBeNull("The FeatureProvider should be resolvable.");
provider.Should().BeOfType<NoOpFeatureProvider>("The resolved provider should be of type DefaultFeatureProvider.");
Assert.True(featureBuilder.IsPolicyConfigured, "The policy should be configured.");
Assert.NotNull(provider);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.IsType<NoOpFeatureProvider>(provider);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Xunit;
Expand All @@ -22,9 +21,9 @@ public void AddOpenFeature_ShouldRegisterApiInstanceAndLifecycleManagerAsSinglet
// Act
_systemUnderTest.AddOpenFeature(_configureAction);

_systemUnderTest.Should().ContainSingle(s => s.ServiceType == typeof(Api) && s.Lifetime == ServiceLifetime.Singleton);
_systemUnderTest.Should().ContainSingle(s => s.ServiceType == typeof(IFeatureLifecycleManager) && s.Lifetime == ServiceLifetime.Singleton);
_systemUnderTest.Should().ContainSingle(s => s.ServiceType == typeof(IFeatureClient) && s.Lifetime == ServiceLifetime.Scoped);
Assert.Single(_systemUnderTest, s => s.ServiceType == typeof(Api) && s.Lifetime == ServiceLifetime.Singleton);
Assert.Single(_systemUnderTest, s => s.ServiceType == typeof(IFeatureLifecycleManager) && s.Lifetime == ServiceLifetime.Singleton);
Assert.Single(_systemUnderTest, s => s.ServiceType == typeof(IFeatureClient) && s.Lifetime == ServiceLifetime.Scoped);
}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion test/OpenFeature.E2ETests/OpenFeature.E2ETests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="SpecFlow" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" />
<PackageReference Include="SpecFlow.xUnit" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Net.Http.Json;
using System.Text.Json;
using FluentAssertions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
Expand Down Expand Up @@ -54,10 +53,10 @@ public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string us
var responseContent = await response.Content.ReadFromJsonAsync<FeatureFlagResponse<bool>>().ConfigureAwait(true); ;

// Assert
response.IsSuccessStatusCode.Should().BeTrue("Expected HTTP status code 200 OK.");
responseContent.Should().NotBeNull("Expected response content to be non-null.");
responseContent!.FeatureName.Should().Be(FeatureA, "Expected feature name to be 'feature-a'.");
responseContent.FeatureValue.Should().Be(expectedResult, "Expected feature value to match the expected result.");
Assert.True(response.IsSuccessStatusCode, "Expected HTTP status code 200 OK.");
Assert.NotNull(responseContent);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(FeatureA, responseContent!.FeatureName);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(expectedResult, responseContent.FeatureValue);
kylejuliandev marked this conversation as resolved.
Show resolved Hide resolved
}

private static async Task<TestServer> CreateServerAsync(Action<IServiceCollection>? configureServices = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="NSubstitute" />
</ItemGroup>

Expand Down
11 changes: 6 additions & 5 deletions test/OpenFeature.Tests/FeatureProviderExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using FluentAssertions;
using OpenFeature.Constant;
using OpenFeature.Error;
using OpenFeature.Extension;
Expand All @@ -18,7 +17,8 @@ public class FeatureProviderExceptionTests
public void FeatureProviderException_Should_Resolve_Description(ErrorType errorType, string errorDescription)
{
var ex = new FeatureProviderException(errorType);
ex.ErrorType.GetDescription().Should().Be(errorDescription);

Assert.Equal(errorDescription, ex.ErrorType.GetDescription());
}

[Theory]
Expand All @@ -27,9 +27,10 @@ public void FeatureProviderException_Should_Resolve_Description(ErrorType errorT
public void FeatureProviderException_Should_Allow_Custom_ErrorCode_Messages(ErrorType errorCode, string message)
{
var ex = new FeatureProviderException(errorCode, message, new ArgumentOutOfRangeException("flag"));
ex.ErrorType.Should().Be(errorCode);
ex.Message.Should().Be(message);
ex.InnerException.Should().BeOfType<ArgumentOutOfRangeException>();

Assert.Equal(errorCode, ex.ErrorType);
Assert.Equal(message, ex.Message);
Assert.IsType<ArgumentOutOfRangeException>(ex.InnerException);
}

private enum TestEnum
Expand Down
46 changes: 20 additions & 26 deletions test/OpenFeature.Tests/FeatureProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using AutoFixture;
using FluentAssertions;
using NSubstitute;
using OpenFeature.Constant;
using OpenFeature.Model;
Expand All @@ -19,7 +18,7 @@ public void Provider_Must_Have_Metadata()
{
var provider = new TestProvider();

provider.GetMetadata().Name.Should().Be(TestProvider.DefaultName);
Assert.Equal(TestProvider.DefaultName, provider.GetMetadata().Name);
}

[Fact]
Expand All @@ -44,28 +43,23 @@ public async Task Provider_Must_Resolve_Flag_Values()

var boolResolutionDetails = new ResolutionDetails<bool>(flagName, defaultBoolValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
(await provider.ResolveBooleanValueAsync(flagName, defaultBoolValue)).Should()
.BeEquivalentTo(boolResolutionDetails);
Assert.Equivalent(boolResolutionDetails, await provider.ResolveBooleanValueAsync(flagName, defaultBoolValue));

var integerResolutionDetails = new ResolutionDetails<int>(flagName, defaultIntegerValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
(await provider.ResolveIntegerValueAsync(flagName, defaultIntegerValue)).Should()
.BeEquivalentTo(integerResolutionDetails);
Assert.Equivalent(integerResolutionDetails, await provider.ResolveIntegerValueAsync(flagName, defaultIntegerValue));

var doubleResolutionDetails = new ResolutionDetails<double>(flagName, defaultDoubleValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
(await provider.ResolveDoubleValueAsync(flagName, defaultDoubleValue)).Should()
.BeEquivalentTo(doubleResolutionDetails);
Assert.Equivalent(doubleResolutionDetails, await provider.ResolveDoubleValueAsync(flagName, defaultDoubleValue));

var stringResolutionDetails = new ResolutionDetails<string>(flagName, defaultStringValue, ErrorType.None,
NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
(await provider.ResolveStringValueAsync(flagName, defaultStringValue)).Should()
.BeEquivalentTo(stringResolutionDetails);
Assert.Equivalent(stringResolutionDetails, await provider.ResolveStringValueAsync(flagName, defaultStringValue));

var structureResolutionDetails = new ResolutionDetails<Value>(flagName, defaultStructureValue,
ErrorType.None, NoOpProvider.ReasonNoOp, NoOpProvider.Variant);
(await provider.ResolveStructureValueAsync(flagName, defaultStructureValue)).Should()
.BeEquivalentTo(structureResolutionDetails);
Assert.Equivalent(structureResolutionDetails, await provider.ResolveStructureValueAsync(flagName, defaultStructureValue));
}

[Fact]
Expand Down Expand Up @@ -113,32 +107,32 @@ public async Task Provider_Must_ErrorType()
NoOpProvider.ReasonNoOp, NoOpProvider.Variant));

var boolRes = await providerMock.ResolveBooleanValueAsync(flagName, defaultBoolValue);
boolRes.ErrorType.Should().Be(ErrorType.General);
boolRes.ErrorMessage.Should().Be(testMessage);
Assert.Equal(ErrorType.General, boolRes.ErrorType);
Assert.Equal(testMessage, boolRes.ErrorMessage);

var intRes = await providerMock.ResolveIntegerValueAsync(flagName, defaultIntegerValue);
intRes.ErrorType.Should().Be(ErrorType.ParseError);
intRes.ErrorMessage.Should().Be(testMessage);
Assert.Equal(ErrorType.ParseError, intRes.ErrorType);
Assert.Equal(testMessage, intRes.ErrorMessage);

var doubleRes = await providerMock.ResolveDoubleValueAsync(flagName, defaultDoubleValue);
doubleRes.ErrorType.Should().Be(ErrorType.InvalidContext);
doubleRes.ErrorMessage.Should().Be(testMessage);
Assert.Equal(ErrorType.InvalidContext, doubleRes.ErrorType);
Assert.Equal(testMessage, doubleRes.ErrorMessage);

var stringRes = await providerMock.ResolveStringValueAsync(flagName, defaultStringValue);
stringRes.ErrorType.Should().Be(ErrorType.TypeMismatch);
stringRes.ErrorMessage.Should().Be(testMessage);
Assert.Equal(ErrorType.TypeMismatch, stringRes.ErrorType);
Assert.Equal(testMessage, stringRes.ErrorMessage);

var structRes1 = await providerMock.ResolveStructureValueAsync(flagName, defaultStructureValue);
structRes1.ErrorType.Should().Be(ErrorType.FlagNotFound);
structRes1.ErrorMessage.Should().Be(testMessage);
Assert.Equal(ErrorType.FlagNotFound, structRes1.ErrorType);
Assert.Equal(testMessage, structRes1.ErrorMessage);

var structRes2 = await providerMock.ResolveStructureValueAsync(flagName2, defaultStructureValue);
structRes2.ErrorType.Should().Be(ErrorType.ProviderNotReady);
structRes2.ErrorMessage.Should().Be(testMessage);
Assert.Equal(ErrorType.ProviderNotReady, structRes2.ErrorType);
Assert.Equal(testMessage, structRes2.ErrorMessage);

var boolRes2 = await providerMock.ResolveBooleanValueAsync(flagName2, defaultBoolValue);
boolRes2.ErrorType.Should().Be(ErrorType.TargetingKeyMissing);
boolRes2.ErrorMessage.Should().BeNull();
Assert.Equal(ErrorType.TargetingKeyMissing, boolRes2.ErrorType);
Assert.Null(boolRes2.ErrorMessage);
}
}
}
1 change: 0 additions & 1 deletion test/OpenFeature.Tests/OpenFeature.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
Expand Down
Loading