Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the refactoring I'm currently using. I overrode the <code>ToString()</code> method of CSVMaterial and added a more useful assert message. So I think this helps with code readability and maintainability. It also makes the unit test trustworthy (due to the helpful diagnostic message).</p> <p>And Jon, thanks for the thought about a logical unit of work. My refactored code does about the same thing as the previous iteration. Both still test one logical thing. Also, I'll have to look into the MoreLINQ stuff. If it's in your C# InDepth 2nd edition book, I'll come across it as I bought the MEAP version from Manning. Thanks for your help.</p> <pre><code>public void LoadCSVBillOfMaterials_WithCorrectCSVFile_ReturnsListOfCSVBillOfMaterialsThatMatchesInput() { //arrange object(s) var filePath = "Path Does Not Matter Because of Mole in File object"; string[] csvDataCorrectlyFormatted = { "1000, 1, Alt 1, , TBD, 1, 10.0, Notes, , Description, 2.50, ,A", "1001, 1, Alt 2, , TBD, 1, 10.0, Notes, , Description, 2.50, ,A" }; var materialsExpected = new List&lt;CSVMaterial&gt;(); materialsExpected.Add(new CSVMaterial("1001", 1, "Alt 1", "TBD", 1m, 10.0m, "Notes", "Description", 2.50m,"A")); materialsExpected.Add(new CSVMaterial("1001", 1, "Alt 2", "TBD", 1m, 10.0m, "Notes", "Description", 2.50m,"A")); //by-pass actually hitting the file system and use in-memory representation of CSV file MFile.ReadAllLinesString = s =&gt; csvDataCorrectlyFormatted; //act on object(s) var materialsActual = modCSVImport.LoadCSVBillOfMaterials(filePath); //assert something happended //Setup message for failed asserts var assertMessage = new StringBuilder(); assertMessage.AppendLine("Actual Materials:"); materialsActual.ForEach((m) =&gt; assertMessage.AppendLine(m.ToString())); assertMessage.AppendLine("Expected Materials:"); materialsExpected.ForEach((m) =&gt; assertMessage.AppendLine(m.ToString())); Assert.That(materialsActual, Is.EquivalentTo(materialsExpected),assertMessage.ToString()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload