0

Need to write the test case for the following code using moq and xunit. return null is not covered in code coverage

public static StreamReader GetStream(System.Reflection.Assembly assembly, string name)
    {
        foreach (string resName in assembly.GetManifestResourceNames())
        {
            if (resName.EndsWith(name))
            {
                return new System.IO.StreamReader(assembly.GetManifestResourceStream(resName));
            }
        }
        return null;
    }
Taufik Shaikh
  • 259
  • 1
  • 3
  • 9
  • 2
    It looks like you'll just need to create a mock Assembly and set up GetManifestResourceNames, returning strings, and GetManifestResourceStream returning a stream. What exactly are you having trouble with? – Rup May 30 '18 at 10:46
  • 2
    Or you could just consider an integration test without Mocks - build a dummy assembly with various embedded Resources, and then ensure that the `StreamReader` matches your expectation for a variety of `name`s. Just to point out the obvious - `.EndsWith("")` will return the first resource in the assembly. – StuartLC May 30 '18 at 10:48

0 Answers0