public void GivenAggregateWithCompositeId_WhenAppendedEvent_LiveAndInlineAggregationWorks()
    {
        var seatId     = new SeatId(Guid.NewGuid());
        var customerId = new CustomerId(Guid.NewGuid());

        var reservation = Reservation.CreateTentative(seatId, customerId);
        var @event      = reservation.DequeueUncommittedEvents().Single();

        //1. Create events
        EventStore.Append(reservation.AggregateId, @event);

        Session.SaveChanges();

        //2. Get live aggregation
        var issuesListFromLiveAggregation = EventStore.AggregateStream <Reservation>(reservation.AggregateId);

        //3. Get inline aggregation
        var issuesListFromInlineAggregation = Session.Load <Reservation>(reservation.AggregateId);

        //4. Get inline aggregation through linq
        var reservationId = reservation.Id;

        var issuesListFromInlineAggregationFromLinq = Session.Query <Reservation>().SingleOrDefault(r => r.Id.Value == reservationId.Value);
        var issuesListFromInlineAggregationFromLinqWithAggregateId = Session.Query <Reservation>().SingleOrDefault(r => r.AggregateId == reservationId.Value);

        issuesListFromLiveAggregation.Should().NotBeNull();
        issuesListFromInlineAggregation.Should().NotBeNull();
        issuesListFromInlineAggregationFromLinq.Should().NotBeNull();
        issuesListFromInlineAggregationFromLinqWithAggregateId.Should().NotBeNull();

        issuesListFromLiveAggregation !.AggregateId.Should().Be(reservationId.Value);
        issuesListFromLiveAggregation !.AggregateId.Should().Be(reservationId.Value);
        issuesListFromInlineAggregationFromLinq !.AggregateId.Should().Be(reservationId.Value);
        issuesListFromInlineAggregationFromLinqWithAggregateId !.AggregateId.Should().Be(reservationId.Value);
    }
Пример #2
0
 public override async ValueTask HandleEvent(NoneStateData stateData,
                                             TakeSeatEvent eventData,
                                             IEventContext eventContext)
 {
     var claptrapIdentity = eventContext.State.Identity;
     var seatId           = SeatId.FromSeatId(claptrapIdentity.Id);
     var trainActor       = _actorProxyFactory.GetClaptrap <ITrainGran>(seatId.TrainId.ToString());
     await trainActor.UpdateCountAsync(eventData.FromStationId, eventData.ToStationId);
 }
 public static Reservation CreateTentative(
     SeatId seatId,
     CustomerId customerId)
 {
     return(new Reservation(
                new ReservationId(Guid.NewGuid()),
                seatId,
                customerId,
                new ReservationNumber(Guid.NewGuid().ToString())
                ));
 }
    public void ChangeSeat(SeatId newSeatId)
    {
        if (Status != ReservationStatus.Tentative)
        {
            throw new InvalidOperationException($"Changing seat for the reservation in '{Status}' status is not allowed.");
        }

        var @event = new ReservationSeatChanged(Id, newSeatId);

        Enqueue(@event);
        Apply(@event);
    }
        public static SeatId FromSeatId(int seatId)
        {
            var seatNumber = seatId % 10000;
            var trainId    = seatId / 10000;
            var re         = new SeatId
            {
                SeatNumber = seatNumber,
                TrainId    = trainId
            };

            return(re);
        }
    private Reservation(
        ReservationId id,
        SeatId seatId,
        CustomerId customerId,
        ReservationNumber reservationNumber
        )
    {
        var @event = new TentativeReservationCreated(
            id,
            seatId,
            customerId,
            reservationNumber
            );

        Enqueue(@event);
        Apply(@event);
    }
Пример #7
0
 public override string ToString()
 {
     return("Id: " + Id + " Buy time: " + BuyTime.ToShortDateString() + "\n    Seat: " + Seat != null?Seat.ToString() : SeatId.ToString()
                + "\n    Seance: " + Seance != null?Seance.ToString() : SeanceId.ToString());
 }
 public SeatInViewingInitialized(SeatId idOfSeatToReserve)
     : base(Guid.NewGuid())
 {
     SeatId = idOfSeatToReserve;
 }
Пример #9
0
 public SeatReservedEvent(ViewingId viewingId, SeatId idOfSeatToReserve)
     : base(Guid.NewGuid())
 {
     ViewingId         = viewingId;
     IdOfSeatToReserve = idOfSeatToReserve;
 }
Пример #10
0
 public override string ToString()
 {
     return(SeatId.ToString());
 }