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());
        });
    }
Exemplo n.º 2
0
    public OverbookingProcessManagerTest()
    {
        _esStore        = new EsEventStore(GetEventStoreClient(), "test");
        _esCommandStore = new EsCommandStore(_esStore, null !, null !, null !);

        var mongoClient = new MongoClient("mongodb://localhost");

        _repository = new MongoDbBookedSlotRepository(mongoClient.GetDatabase(Guid.NewGuid().ToString()));
    }