3

I am trying to use ValueTuples (current NuGet package ), and while most things I need it for have been seamless an issue has come up when trying to Unit Test certain scenarios related to inheritance. I have made a simple Interface/Implementation test that anyone can repeat which also fails for virtual/override examples.

First create a simple console project and a simple unit test and link the two. Then create a Fakes (Microsoft.QualityToole.Testing.Fakes) object for the main project. Create the following classes.

public interface IModelClass
{
    (string val1, int val2) Run();
}

public class ModelClass : IModelClass
{
    public (string val1, int val2) Run()
    {
        throw new NotImplementedException();
    }
}

This can be proven without the need for implementing the interface as it is the interface itself that fails to compile when building the fakes.

Building the solution yields this error:

  • Severity: Error
  • Code: CS8141
  • Description: The tuple element names in the signature of method 'StubIModelClass.IModelClass.Run()' must match the tuple element names of interface method 'IModelClass.Run()' (including on the return type).

The error stems from the f.cs file in the fakes build directory as it implements the Run() method stub as:

svt::System.ValueTuple<string, int> vt::ValueTuple.IModelClass.Run()

Where the return signature does not match that of the named ValueTuple on the interface. If we remove the naming and just have (string, int) everywhere it all builds, but you are then limited with simple Tuples and Item1, Item2, ... This seems to defeat the purpose of ValueTuple.

After much searching I end up here, asking if anyone has been able to get inheritance with ValueTuple working on UnitTests and if not, what solution have you resorted to other than

  1. Removing the unit tests
  2. Converting the TupleValue to a class
  3. Using simple Tuples

I would like to avoid these if possible.

J. C.
  • 31
  • 1

0 Answers0