title: Unit Testing - Am I doing it right?
body: <p>Basically I have been programing for a little while and after finishing my last project can fully understand how much easier it would have been if I'd have done TDD. I guess I'm still not doing it strictly as I am still writing code then writing a test for it, I don't quite get how the test becomes before the code if you don't know what structures and how your storing data etc... but anyway...</p>
  
  <p>Kind of hard to explain but basically lets say for example I have a Fruit objects with properties like id, color and cost. (All stored in textfile ignore completely any database logic etc)</p>
  
  <pre><code>    FruitID FruitName   FruitColor  FruitCost
      1         Apple       Red         1.2
      2         Apple       Green       1.4
      3         Apple       HalfHalf    1.5
  </code></pre>
  
  <p>This is all just for example. But lets say I have this is a collection of <code>Fruit</code> (it's a <code>List&lt;Fruit&gt;</code>) objects in this structure. And my logic will say to reorder the fruitids in the collection if a fruit is deleted (this is just how the solution needs to be).</p>
  
  <p>E.g. if 1 is deleted, object 2 takes fruit id 1, object 3 takes fruit id2.</p>
  
  <p>Now I want to test the code ive written which does the reordering, etc.</p>
  
  <p>How can I set this up to do the test?</p>
  
  <hr>
  
  <p>Here is where I've got so far. Basically I have fruitManager class with all the methods, like deletefruit, etc. It has the list usually but Ive changed hte method to test it so that it accepts a list, and the info on the fruit to delete, then returns the list. </p>
  
  <p><strong>Unit-testing wise:</strong> Am I basically doing this the right way, or have I got the wrong idea? and then I test deleting different valued objects / datasets to ensure method is working properly.</p>
  
  <hr>
  
  <pre><code>[Test]
  public void DeleteFruit()
  {
      var fruitList = CreateFruitList();
      var fm = new FruitManager();
  
      var resultList = fm.DeleteFruitTest("Apple", 2, fruitList);
  
      //Assert that fruitobject with x properties is not in list ? how
  }
  
  private static List&lt;Fruit&gt; CreateFruitList()
  {
      //Build test data
      var f01 = new Fruit {Name = "Apple",Id = 1, etc...};
      var f02 = new Fruit {Name = "Apple",Id = 2, etc...};
      var f03 = new Fruit {Name = "Apple",Id = 3, etc...};
  
      var fruitList = new List&lt;Fruit&gt; {f01, f02, f03};
      return fruitList;
  }
  </code></pre>