I'm getting a 'test case source cannot be found' error in the following code. I'm trying to parametrize an integration test with a bunch of example files located in the repository.
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using NUnit.Framework;
using System;
using System.Collections;
using System.IO;
namespace IntegrationTests
{
[TestFixture]
public class IntegrationTestA
{
[TestCaseSource(nameof(InputFilesGenerator))]
public void TestA(string inputFile)
{
Main(inputFile);
}
}
public class InputFilesGenerator : IEnumerable
{
public IEnumerator GetEnumerator()
{
var matcher = new Matcher();
matcher.AddInclude("**/*.lcd");
string workingDirectory = Environment.CurrentDirectory;
var rootDirectory = Directory.GetParent(workingDirectory).Parent.Parent.Parent.Parent;
var searchDirectories = rootDirectory.GetDirectories("samples");
if (searchDirectories.Length != 1) { throw new Exception("Unexpected number of samples directories"); }
var samplesDirectory = searchDirectories[0];
var patternMatch = matcher.Execute(new DirectoryInfoWrapper(samplesDirectory));
foreach (var file in patternMatch.Files)
{
yield return file.Path.;
}
}
}
}
This code is modelled after the example given in the NUnit docs here
I've tried yield return new object[] { file.Path };
to no avail.
I've also tried replacing the entire enumerator code with
for(int i =0; i < 10; i++)
{
yield return i.ToString();
}
which didn't help, so my issue isn't there.
You have this, which is using the name of the class:
[TestCaseSource(nameof(InputFilesGenerator))]
It should be this, which uses the type:
[TestCaseSource(typeof(InputFilesGenerator))]