d4c97726d086f00b7bbd3ecaf2f21f5f320c4761.svn-base 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package mock
  2. import (
  3. shipping "github.com/longjoy/micro-go-course/section19/cargo/model"
  4. )
  5. // CargoRepository is a mock cargo repository.
  6. type CargoRepository struct {
  7. StoreFn func(c *shipping.Cargo) error
  8. StoreInvoked bool
  9. FindFn func(id shipping.TrackingID) (*shipping.Cargo, error)
  10. FindInvoked bool
  11. FindAllFn func() []*shipping.Cargo
  12. FindAllInvoked bool
  13. }
  14. // Store calls the StoreFn.
  15. func (r *CargoRepository) Store(c *shipping.Cargo) error {
  16. r.StoreInvoked = true
  17. return r.StoreFn(c)
  18. }
  19. // Find calls the FindFn.
  20. func (r *CargoRepository) Find(id shipping.TrackingID) (*shipping.Cargo, error) {
  21. r.FindInvoked = true
  22. return r.FindFn(id)
  23. }
  24. // FindAll calls the FindAllFn.
  25. func (r *CargoRepository) FindAll() []*shipping.Cargo {
  26. r.FindAllInvoked = true
  27. return r.FindAllFn()
  28. }
  29. // LocationRepository is a mock location repository.
  30. type LocationRepository struct {
  31. FindFn func(shipping.UNLocode) (*shipping.Location, error)
  32. FindInvoked bool
  33. FindAllFn func() []*shipping.Location
  34. FindAllInvoked bool
  35. }
  36. // Find calls the FindFn.
  37. func (r *LocationRepository) Find(locode shipping.UNLocode) (*shipping.Location, error) {
  38. r.FindInvoked = true
  39. return r.FindFn(locode)
  40. }
  41. // FindAll calls the FindAllFn.
  42. func (r *LocationRepository) FindAll() []*shipping.Location {
  43. r.FindAllInvoked = true
  44. return r.FindAllFn()
  45. }
  46. // VoyageRepository is a mock voyage repository.
  47. type VoyageRepository struct {
  48. FindFn func(shipping.VoyageNumber) (*shipping.Voyage, error)
  49. FindInvoked bool
  50. }
  51. // Find calls the FindFn.
  52. func (r *VoyageRepository) Find(number shipping.VoyageNumber) (*shipping.Voyage, error) {
  53. r.FindInvoked = true
  54. return r.FindFn(number)
  55. }
  56. // HandlingEventRepository is a mock handling events repository.
  57. type HandlingEventRepository struct {
  58. StoreFn func(shipping.HandlingEvent)
  59. StoreInvoked bool
  60. QueryHandlingHistoryFn func(shipping.TrackingID) shipping.HandlingHistory
  61. QueryHandlingHistoryInvoked bool
  62. }
  63. // Store calls the StoreFn.
  64. func (r *HandlingEventRepository) Store(e shipping.HandlingEvent) {
  65. r.StoreInvoked = true
  66. r.StoreFn(e)
  67. }
  68. // QueryHandlingHistory calls the QueryHandlingHistoryFn.
  69. func (r *HandlingEventRepository) QueryHandlingHistory(id shipping.TrackingID) shipping.HandlingHistory {
  70. r.QueryHandlingHistoryInvoked = true
  71. return r.QueryHandlingHistoryFn(id)
  72. }
  73. // RoutingService provides a mock routing service.
  74. type RoutingService struct {
  75. FetchRoutesFn func(shipping.RouteSpecification) []shipping.Itinerary
  76. FetchRoutesInvoked bool
  77. }
  78. // FetchRoutesForSpecification calls the FetchRoutesFn.
  79. func (s *RoutingService) FetchRoutesForSpecification(rs shipping.RouteSpecification) []shipping.Itinerary {
  80. s.FetchRoutesInvoked = true
  81. return s.FetchRoutesFn(rs)
  82. }