So I'm facing something of a face off between the perfectionist vs the agile efficiency engineer in me.
I've got an Azure Function which will be using the Open XML SDK to perform some rudimentary functions - for example it adds comments into a Word document.
For simplicity I've wrapped up and modularised all my Open XML SDK code into a separate internal API so I can call methods like:
WordDocuments.AddComment(documentStream, "I'm looking for this text", "Author", "This is my comment");
I have extensive unit test coverage across the majority of the project so far, from individual internal function-level unit tests, right up to post-deployment end-to-end integration testing of the Azure Function endpoints.
However, I'm facing a bit of a quandary facing this particular one.
An obvious set of test steps might be:
- Submit a document (via a Memory Stream)
- Call the "AddComment" function
- Assert that the comment has been added to the updated stream
// ARRANGE
var fileName = $@"{Directory.GetCurrentDirectory()}\Documents\Word.docx";
var bytes = File.ReadAllBytes(fileName);
using (var stream = new MemoryStream())
{
stream.Write(bytes, 0, bytes.Length);
// ACT
WordDocuments.AddComment(stream,
"the text we are looking for"
"Martin Hatch", // author of the comment
"MH", // initials for the author
"the comment text");
}
// ASSERT
Assert.IsTrue(WordDocuments.GetComments(stream).Any(c => c.Author == "Martin Hatch" && c.Text == "the comment text"));
}
However - this leaves me in a bit of a pickle. I can't "assert" that the comment has been added without using the Open XML SDK itself.
Now - it seems utterly pointless to write a whole bunch of separate Open XML SDK code, when I've already wrapped it all up in my "WordDocuments" API class.
However - should I be using my own API to assert actions, which are using that very same API??
This feels like a bit of an internal loop/testing fail.
So I suppose the real question would be:
How do you test code, when the assertion requires the exact same code that you are testing?
EDIT - I've actually updated the main title now as I feel it makes more sense
Original Title: "How would you go about testing code using the Open XML SDK?"