I'm writing some unit tests against an API that, basically, takes some populated objects and outputs a byte[] which can then be output as an Excel file (that's what the application does with it, but may be irrelevant.)
I wanted to write a test to verify that, given some of those populated objects I'm receiving an expected byte[] array, so my approach was to use a previously-output Excel file, and load it at test time to compare to what should be output by the code. I do this by reading it via File.ReadAllBytes() to get a byte[] array, and compare that with the byte[] array generated within the app.
I understand the issue with binary reproducibility in .NET, but I'm not sure if that applies in this situation. Can anyone provide any insight as to why the byte arrays don't match? My guess is that reading the file from disk presents some differences in the binary data, or perhaps using the GetString() method changes the data somehow at runtime.
My code is below:
// The data generated by the app
var data = reportGenerator.GenerateReport(timeFrame, date);
// The expected data
var compareData = File.ReadAllBytes(@"Deployment\TestData.xls");
// Get string representation of the data for comparison
var dataString = Encoding.ASCII.GetString(data);
var compareDataString = Encoding.ASCII.GetString(compareData);
// Compare, Fails
Assert.AreEqual(dataString, compareDataString);
The data almost matches, but it's not quite identical. When looking at the strings in Beyond Compare, they're probably 99.9% identical with a few small differences.
Aucun commentaire:
Enregistrer un commentaire