コード例 #1
0
    public async Task should_increment_the_visit_counter_when_slot_is_booked()
    {
        var dayId         = Guid.NewGuid().ToString();
        var slotSchedule1 = new SlotScheduled(Guid.NewGuid(), dayId, _now, _tenMinutes);
        var slotSchedule2 = new SlotScheduled(Guid.NewGuid(), dayId, _now.AddMinutes(10), _tenMinutes);
        var slotBooked1   = new SlotBooked(dayId, slotSchedule1.SlotId, "patient 1");
        var slotBooked2   = new SlotBooked(dayId, slotSchedule2.SlotId, "patient 1");

        await Given(slotSchedule1, slotSchedule2, slotBooked1, slotBooked2);

        Then(2, await _repository.CountByPatientAndMonth("patient 1", _now.Month));
    }
コード例 #2
0
    public OverbookingProcessManager(IBookedSlotsRepository bookedSlotRepository, int bookingLimitedPerPatient,
                                     ICommandStore commandStore, Func <Guid> idGenerator)
    {
        When <SlotScheduled>(async(e, m) =>
        {
            await bookedSlotRepository.AddSlot(new BookedSlot(e.SlotId.ToString(), e.DayId, e.SlotStartTime.Month));
        });

        When <SlotBooked>(async(e, m) =>
        {
            await bookedSlotRepository.MarkSlotAsBooked(e.SlotId.ToString(), e.PatientId);

            var slot  = await bookedSlotRepository.GetSlot(e.SlotId.ToString());
            var count = await bookedSlotRepository.CountByPatientAndMonth(e.PatientId, slot.Month);

            if (count > bookingLimitedPerPatient)
            {
                await commandStore.Send(new CancelSlotBooking(e.DayId, e.SlotId, "overbooked"),
                                        new CommandMetadata(m.CorrelationId, new CausationId(idGenerator())));
            }
        });

        When <SlotBookingCancelled>(async(e, m) =>
        {
            await bookedSlotRepository.MarkSlotAsAvailable(e.SlotId.ToString());
        });
    }