I added the nuget FluentAssertions 6.7.0 in a test project using .NET Framework 4.6.1. I run tests from Rider 2022.1.1.
I'm new to this nuget and I read the intro and searched for issues (none found). I come from the Should family and trying to upgrade.
I cannot build with basic assertions. Here is the initial code:
using FluentAssertions;
using Moq;
using System;
using Xunit;
public class MyTestClass
{
[Fact]
public void GetProvider_ByRemoteName_Works()
{
// input
var desiredRemoteName = "Remote2";
// prepare
var context = Context.New(); // mocks and stubs
// execute
var result = context.SomeService.GetProvider(desiredRemoteName);
// verify
result.Should().NotBeNull(); // error line
result.Should().BeOfType<MyProviderClient>(); // error line
}
The build errors are:
error CS0012: The type 'DataTable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
error CS0012: The type 'DataColumn' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
...
error CS0012: The type 'DataRow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I don't understand why I should reference this "System.Data" assembly. That does not seem legit. If I do reference it:
MyTestClass.cs: [CS0121] The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should(TDataRow)' and 'DataSetAssertionExtensions.Should(TDataSet)'
Also, removing the error lines and using
line provide a valid build and test run.
Also, the IDE editor indicates:
The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should(TDataRow)' and 'DataSetAssertionExtensions.Should(TDataSet)'
Also, using Xunit's assertions works:
// verify
Assert.NotNull(result);
Assert.IsType<MyProviderClient>(result);
Following up on your comments, let's consider this updated code:
// execute
object result = context.SomeService.GetProvider(desiredRemoteName);
// verify
result.Should().BeAssignableTo<IMyInterface>()
.And.BeOfType<SomeImplementation>()
.Which
.Configuration
.Should() // error line
.NotBeNull();
The same error occurs on the latest .Should()
call.
MyTestClass.cs: [CS0121] The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should(TDataRow)' and 'DataSetAssertionExtensions.Should(TDataSet)'
Is it considered "normal" with FluentAssertions to do .BeOfType<>().Which
everywhere? I feel something is wrong on my side or in the way the lib works.