Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockFileSystem.AddFilesFromEmbeddedNamespace() method throws ArgumentNullException #921

Open
ristogod opened this issue Dec 7, 2022 · 2 comments
Labels
area: testinghelpers Issues that address the testing helpers state: waiting for feedback Issues that are waiting for feedback type: bug Issues that describe misbehaving functionality

Comments

@ristogod
Copy link

ristogod commented Dec 7, 2022

Given a project named "Test" with a "Files" folder within it, and within that folder there are 5 files included as embeddedResources, when I call the given code, it always throw an exception:

System.ArgumentException: 'Value cannot be null. (Parameter 'key')'

   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at System.IO.Abstractions.TestingHelpers.MockFileSystem.DirectoryExistsWithoutFixingPath(String path)
   at System.IO.Abstractions.TestingHelpers.MockFileSystem.AddFile(String path, MockFileData mockFile)
   at System.IO.Abstractions.TestingHelpers.MockFileSystem.AddFilesFromEmbeddedNamespace(String path, Assembly resourceAssembly, String embeddedRresourcePath)

This is how I'm calling the code

MockFileSystem fileSystem = new();
fileSystem.AddFilesFromEmbeddedNamespace(@"\\Test.Files", typeof(MyClass).Assembly, "Test.Files" );
@vbreuss
Copy link
Member

vbreuss commented Dec 13, 2022

@ristogod :
This is really strange, as there is a test, that seems to describe exactly your scenario with two files inserted as embedded resources:

        [Test]
        public void MockFileSystem_AddFilesFromEmbeddedResource_ShouldAddAllTheFiles()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.AddFilesFromEmbeddedNamespace(XFS.Path(@"C:\"), Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles");

            Assert.Contains(XFS.Path(@"C:\TestFile.txt"), fileSystem.AllFiles.ToList());
            Assert.Contains(XFS.Path(@"C:\SecondTestFile.txt"), fileSystem.AllFiles.ToList());
        }

image

I couldn't reproduce your problem from the description alone. Could you provide an example project to reproduce the behaviour, or check if you can adapt the test case so that it fails?

@fgreinacher
Copy link
Contributor

I couldn't reproduce your problem from the description alone. Could you provide an example project to reproduce the behaviour, or check if you can adapt the test case so that it fails?

@ristogod Could you please help us reproduce this?

@fgreinacher fgreinacher added type: bug Issues that describe misbehaving functionality state: waiting for feedback Issues that are waiting for feedback area: testinghelpers Issues that address the testing helpers labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: waiting for feedback Issues that are waiting for feedback type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

3 participants