Advertisement
Guest User

Injection and testing

a guest
Sep 30th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.44 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement