public static void Handle(Func <IEventPublisher> bus, CreateMovie msg) { // Todo: Validation var @event = new MovieCreated(Guid.NewGuid(), msg.Title, msg.ReleaseDate, msg.Genre, msg.Price); bus().Publish(@event); }
private static MovieDto MapFromEvent(MovieCreated e) { return new MovieDto { Id = e.Id, Title = e.Title, ReleaseDate = e.ReleaseDate, Genre = e.Genre, Price = e.Price }; }
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, }); }
public async Task MovieCreated_event_handler_creates_read_model_entity_correctly( MovieCreated domainEvent, InMemoryMovieRepository repositorySpy) { var sut = new MovieReadModelGenerator( repositorySpy, Mock.Of <ITheaterReader>()); await sut.Handle(new Envelope(domainEvent)); IDictionary <Guid, Movie> data = repositorySpy.Data; data.Should().ContainKey(domainEvent.MovieId); data[domainEvent.MovieId].Should().BeEquivalentTo(new { domainEvent.Title, CreatedAt = domainEvent.RaisedAt, ETag = default(string), }); }
public void ApplyEvent(MovieCreated @event) { Id = @event.AggregateRootId; Title = @event.Title; }
private void Handle(MovieCreated domainEvent) { Title = domainEvent.Title; }
public static void Handle(Func <IMovieRepository> repository, MovieCreated msg) { repository().Insert(msg); }
private void Apply(MovieCreated moviedCreated) { MovieId = moviedCreated.MovieId; Title = moviedCreated.Title; AvaliableSeats = moviedCreated.Seats; }
public Movie(string movieId, string title, int seats) { var movieCreated = new MovieCreated(movieId, title, seats); ApplyChange(movieCreated); }
public void Insert(MovieCreated e) { _movies.Add(MapFromEvent(e)); }