Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Injection and testing

By: a guest on Sep 30th, 2011  |  syntax: VB.NET  |  size: 1.44 KB  |  views: 77  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <TestClass()> _
  2. Public Class FamilyMapperTest
  3.     ' Because we need to alter the dates in the repositories from time to time, we can't use injection here
  4.     ' How can this be improved?
  5.     Dim myCountryRepository As ICountryRepository = MemoryKernel.Instance.Get(Of ICountryRepository)()
  6.     Dim myLocalisationAndUnopsProjectRepository As MemoryLocalisationAndUnopsProjectRepository = MemoryKernel.Instance.Get(Of MemoryLocalisationAndUnopsProjectRepository)()
  7.     Dim myMemoryCategoryRepository As MemoryCategoryRepository = MemoryKernel.Instance.Get(Of MemoryCategoryRepository)()
  8.  
  9.     Dim myCountryMapper As CountryMapper = New CountryMapper(myCountryRepository)
  10.     Dim myLocalisationMapper As LocalisationMapper = New LocalisationMapper(myLocalisationAndUnopsProjectRepository, myLocalisationAndUnopsProjectRepository)
  11.     Dim myCategoryMapper As CategoryMapper = New CategoryMapper(myMemoryCategoryRepository)
  12.     Dim myFamilyMapper As FamilyMapper = New FamilyMapper(myCountryMapper, myLocalisationMapper, myCategoryMapper)
  13.        
  14.         ' This entire block could be replaced by
  15.         ' Dim myFamilyMapper As FamilyMapper = MemoryKernel.Get(Of FamilyMapper)
  16.        
  17.             <TestMethod()> _
  18.     Public Sub GetCategoryStartDate_CategoryStartDateAndContractStartDate_ContractStartDateIsOldestDate()
  19.         ' Set a property on myMemoryCategoryRepository
  20.                 ' Assert the outcome of myFamilyMapper based on the property I just set in the repository
  21.     End Sub
  22. end Class      
  23.