Exemplo n.º 1
0
        private async Task HandleScreeningAdded(
            Envelope <ScreeningAdded> envelope,
            CancellationToken cancellationToken)
        {
            ScreeningAdded domainEvent = envelope.Message;

            Movie movie = await _movieRepository.FindMovie(domainEvent.MovieId);

            Guid    theaterId = domainEvent.TheaterId;
            Theater theater   = await _theaterReader.FindTheater(theaterId);

            movie.Screenings.Add(new Screening
            {
                Id          = domainEvent.ScreeningId,
                TheaterId   = theaterId,
                TheaterName = theater.Name,
                Seats       = new List <Seat>(
                    from r in Enumerable.Range(0, domainEvent.SeatRowCount)
                    from c in Enumerable.Range(0, domainEvent.SeatColumnCount)
                    select new Seat
                {
                    Row        = r,
                    Column     = c,
                    IsReserved = false,
                }),
                ScreeningTime = domainEvent.ScreeningTime,
                DefaultFee    = domainEvent.DefaultFee,
                ChildrenFee   = domainEvent.ChildrenFee,
                CreatedAt     = domainEvent.RaisedAt,
            });

            await _movieRepository.UpdateMovie(movie);
        }
Exemplo n.º 2
0
 private void Handle(ScreeningAdded domainEvent)
 {
     _screenings.Add(Screening.Create(
                         domainEvent.ScreeningId,
                         domainEvent.TheaterId,
                         domainEvent.SeatRowCount,
                         domainEvent.SeatColumnCount,
                         domainEvent.ScreeningTime,
                         domainEvent.DefaultFee,
                         domainEvent.ChildrenFee));
 }
        public async Task ScreeningAdded_event_handler_add_screening_entity_correctly(
            MovieCreated movieCreated,
            Theater theater,
            InMemoryMovieRepository movieRepositoryDouble,
            InMemoryTheaterRepository theaterReaderStub,
            IFixture builder)
        {
            // Arrange
            theaterReaderStub.Data[theater.Id] = theater;

            var sut = new MovieReadModelGenerator(
                movieRepositoryDouble, theaterReaderStub);

            await sut.Handle(new Envelope(movieCreated));

            Guid movieId = movieCreated.MovieId;

            ScreeningAdded domainEvent = builder
                                         .Build <ScreeningAdded>()
                                         .With(x => x.SourceId, movieId)
                                         .With(x => x.TheaterId, theater.Id)
                                         .With(x => x.SeatRowCount, theater.SeatRowCount)
                                         .With(x => x.SeatColumnCount, theater.SeatColumnCount)
                                         .Create();

            // Act
            await sut.Handle(new Envelope(domainEvent));

            // Assert
            Movie actual = movieRepositoryDouble.Data[movieId];

            actual.Screenings
            .Should().Contain(s => s.Id == domainEvent.ScreeningId).Which
            .Should().BeEquivalentTo(new
            {
                Id = domainEvent.ScreeningId,
                domainEvent.TheaterId,
                TheaterName = theater.Name,
                Seats       =
                    from r in Enumerable.Range(0, theater.SeatRowCount)
                    from c in Enumerable.Range(0, theater.SeatColumnCount)
                    select new Seat
                {
                    Row        = r,
                    Column     = c,
                    IsReserved = false,
                },
                domainEvent.ScreeningTime,
                domainEvent.DefaultFee,
                domainEvent.ChildrenFee,
                CreatedAt = domainEvent.RaisedAt,
            });
        }