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

Mock XmlReader/StringReader and XslCompiledTransform[.Load] #751

Closed
rklec opened this issue Aug 24, 2021 · 3 comments
Closed

Mock XmlReader/StringReader and XslCompiledTransform[.Load] #751

rklec opened this issue Aug 24, 2021 · 3 comments
Labels
area: core Issues that address the core abstractions & the wrappers state: won't do Issues that won't be addressed. Reasons differ and will be provided as comments. type: enhancement Issues that propose new functionality

Comments

@rklec
Copy link

rklec commented Aug 24, 2021

Is your feature request related to a problem? Please describe.
I want to mock XSL transformation, implemented via XslCompiledTransform.

var xmlTransformer = new XslCompiledTransform();

xmlTransformer.Load(xslPath);
xmlTransformer.Transform(xmlFilePath, null, output);

So there are two use cases:

  • mock the XSL
  • mock the XML

Describe the solution you'd like
Let me mock XslCompiledTransform and read the file mock as usual...

Describe alternatives you've considered
The XML can quite easily be read from a stream, however, this needs a mock of XmlReader, which we cannot do with this lib here.

Also loading the XSL from a string requires this or at least both need StringReader and a way more complicated implementation.

All in all the above code can be re-written as such to make it work with the mock, however, this is really complicated/complicates the code just for macking it testable - in contrast to the short and understandable code snippet shown above:

var xmlTransformer = new XslCompiledTransform();

await using var openReadXml = FileSystem.File.OpenRead(xmlFilePath);
await using var openReadXsl = FileSystem.File.OpenRead(xslPath);

var xmlReaderSettings = new XmlReaderSettings
{
    Async = true,
    CloseInput = true
};

using var xmlReader = XmlReader.Create(openReadXml, xmlReaderSettings);
using var xslReader = XmlReader.Create(openReadXsl, xmlReaderSettings);
xmlTransformer.Load(xslReader);
xmlTransformer.Transform(xmlReader, null, output);

xmlReader.Close();
xslReader.Close();

Additional context
I am open to any other way for other implementations/changes in how I can mock the XML/XSL transformation/reading properly.

@rklec rklec added state: needs discussion Issues that need further discussion type: enhancement Issues that propose new functionality labels Aug 24, 2021
@fgreinacher
Copy link
Contributor

Thanks for your contribution!

As mentioned e.g. in #748 (comment) I want to keep this library focused on System.IO.

However I guess this could be something for https://github.com/System-IO-Abstractions/System.IO.Abstractions.Extensions which is currently being set up. What do you think @gigi81?

@fgreinacher fgreinacher added the area: core Issues that address the core abstractions & the wrappers label Aug 26, 2021
@fgreinacher fgreinacher added state: won't do Issues that won't be addressed. Reasons differ and will be provided as comments. and removed state: needs discussion Issues that need further discussion labels Oct 29, 2021
@fgreinacher
Copy link
Contributor

Closing this. As mentioned above please consider suggesting it to the extensions.

@rklec
Copy link
Author

rklec commented Nov 22, 2021

Okay, suggested there in TestableIO/System.IO.Abstractions.Extensions#11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues that address the core abstractions & the wrappers state: won't do Issues that won't be addressed. Reasons differ and will be provided as comments. type: enhancement Issues that propose new functionality
Projects
None yet
Development

No branches or pull requests

2 participants