You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use MockFileSystem together with mocking interfaces? #750
If you use MockFileSystem you AFAIK cannot use the second way described in the Readme with mocking the interfaces via a framework, such as NSubstitute, in my case. So you can only use one thing and they are exclusively to each other, are not they?
Or is there a way to use these, together? I.e. mock the basic file data via MockFileSystem and then just substitute some interfaces, where you usually need to trigger an access error, for a directory e.g..
In my case the suggestedAllowedFileShare did not cause an error if I used it with MockDirectoryData(), so I think I need to us interface mocking here, unfortunately.
For this to work with NSubstitute, the MockFileSystem would have to return a Substitute.For<> each interface it creates, so that you can then use NSubstitute to further mock/restrict the interfaces.
Sorry for answering that late, I somehow missed the issue 🙈
I don't know exactly how NSubsitute works, but I guess you could somehow create mocks/stubs at the interface level and delegate some mocked method to a MockFileSystem instance? If the framework does not support it you could implement it via the Decorator pattern.
Oh of course, that could be possible. Thanks.
It's still easier than the inverse way (i.e. mock everything and then try to substitute only parts) as you still need to delegate each called function (or thankfully, maybe also bigger objects like FileSystem.File if you don't need to mock that), but yeah, it's possible like that!
Activity
fgreinacher commentedon Aug 26, 2021
Sorry for answering that late, I somehow missed the issue 🙈
I don't know exactly how NSubsitute works, but I guess you could somehow create mocks/stubs at the interface level and delegate some mocked method to a
MockFileSysteminstance? If the framework does not support it you could implement it via the Decorator pattern.Does that help?
rklec commentedon Aug 30, 2021
Oh of course, that could be possible. Thanks.
It's still easier than the inverse way (i.e. mock everything and then try to substitute only parts) as you still need to delegate each called function (or thankfully, maybe also bigger objects like
FileSystem.Fileif you don't need to mock that), but yeah, it's possible like that!