-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_room_test.go
47 lines (40 loc) · 1.94 KB
/
book_room_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cqrs_booking_test
import (
"github.com/stretchr/testify/assert"
"kata/cqrs_booking/room_command"
"kata/cqrs_booking/room_query"
"kata/cqrs_booking/room_read_registry"
"kata/cqrs_booking/room_write_registry"
"kata/cqrs_booking/utils"
)
type bookRoomFeature struct {
roomQueryService *room_query.RoomQueryService
roomCommandService *room_command.RoomCommandService
}
func (b *bookRoomFeature) GivenRoom(room string) error {
inMemoryRoomReadRegistry := room_read_registry.NewInMemoryRoomReadRegistry()
inMemoryRoomReadRegistry.AddRoom(room)
b.roomQueryService = room_query.NewRoomQueryService(inMemoryRoomReadRegistry)
w := room_write_registry.NewInMemoryRoomWriteRegistry()
b.roomCommandService = room_command.NewRoomCommandService(w, inMemoryRoomReadRegistry)
return nil
}
func (b *bookRoomFeature) RoomIsFree(room, arrivalDateString, departureDateString string) error {
arrivalDate := utils.DateFor(arrivalDateString)
departureDate := utils.DateFor(departureDateString)
freeRooms := b.roomQueryService.FreeRooms(arrivalDate, departureDate)
return assertExpectedAndActual(assert.Contains, freeRooms, room_read_registry.NewRoom(room), "Expected free rooms not contain room %s", room)
}
func (b *bookRoomFeature) BookRoom(client, room, arrivalDateString, departureDateString string) error {
arrivalDate := utils.DateFor(arrivalDateString)
departureDate := utils.DateFor(departureDateString)
booking := room_write_registry.NewBooking(client, room, arrivalDate, departureDate)
b.roomCommandService.BookRoom(booking)
return nil
}
func (b *bookRoomFeature) RoomIsNotFree(room, arrivalDateString, departureDateString string) error {
arrivalDate := utils.DateFor(arrivalDateString)
departureDate := utils.DateFor(departureDateString)
freeRooms := b.roomQueryService.FreeRooms(arrivalDate, departureDate)
return assertExpectedAndActual(assert.NotContains, freeRooms, room_read_registry.NewRoom(room), "Expected free rooms not contain room %s", room)
}