C
C#2y ago
Jameston

❔ Unit Testing for OpenXML

I am having trouble writing a unit test for a piece of code at work that deals with OpenXML. Outline of the program is that the function takes in a SpreadsheetDocument object, reads it, and extracts all of the cell values into a dictionary containing a list of values (example: { "Values" : [ "Element0", "Element1", "Etc." ] }). I return this created dict. I've tried to figure out how to write unit tests for this, but I am really struggling to do so. Can anyone give me some pointers? Thanks.
2 Replies
Becquerel
Becquerel2y ago
what kind of tests would be useful for you? not everything lends itself well to unit-testing what difficulties have you had so far? is it conceptualising the kind of tests to write, or actually implementing them? you could make a test like this:
var expectedResult = new Dictionary<string, string> { ... fill with 'correct' values... };

var input = new SpreadsheetDocument(); // however you instantiate this

var actualResult = yourService.DoStuff(input);

actualResult.Should().BeEquivalentTo(expectedResult); // this syntax comes from the library FluentAssertions
var expectedResult = new Dictionary<string, string> { ... fill with 'correct' values... };

var input = new SpreadsheetDocument(); // however you instantiate this

var actualResult = yourService.DoStuff(input);

actualResult.Should().BeEquivalentTo(expectedResult); // this syntax comes from the library FluentAssertions
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server