SwissLife-OSS / snapshooter

Snapshooter is a snapshot testing tool for .NET Core and .NET Framework
https://swisslife-oss.github.io/snapshooter/
MIT License
299 stars 29 forks source link

MS Test data driven tests fail if data param contains null #178

Open aaronpowell opened 1 year ago

aaronpowell commented 1 year ago

Describe the bug If the DataRowAttribute has a null parameters in it, Snapshooter will error trying to generate the snapshot name.

To Reproduce Create a MS Test like so:

[DataTestMethod]
[DataRow("str", null)]
public void TestWithNull(string str, string? nullableStr) {
  var data = new { str, nullableStr };
  Snapshoot.Match(data);
}

This results in the following error:

  Message: 
Test method Cli.Tests.InitTests.EnsureCorrectConfigGenerationWithDifferentAuthenticationProviders threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.

  Stack Trace: 
<>c.<GetMethodSnapshotName>b__6_0(Object d)
SelectArrayIterator`2.MoveNext()
String.Join(String separator, IEnumerable`1 values)
MSTestSnapshotFullNameReader.GetMethodSnapshotName(MethodBase method)
MSTestSnapshotFullNameReader.ReadSnapshotFullName()
SnapshotFullNameResolver.ResolveSnapshotFullName(String snapshotName, String snapshotNameExtension)
Snapshooter.ResolveSnapshotFullName(String snapshotName, SnapshotNameExtension snapshotNameExtension)
Snapshot.FullName()
Snapshot.Match(Object currentResult, Func`2 matchOptions)
Snapshot.Match[T](T currentResult, Func`2 matchOptions)

Expected behavior Test to pass.

Desktop (please complete the following information):