public static AttendantsProjection RSVPDeclined(this AttendantsProjection projection, AttendantsReadModel readModel, Guid memberId)
 {
     projection.Project(readModel, new Events.RSVPDeclined {
         MemberId = memberId, DeclinedAt = DateTime.UtcNow
     });
     return(projection);
 }
        public static void GivenPublishedMeetup(Action <AttendantsProjection, AttendantsReadModel> when, Action <AttendantsReadModel> then)
        {
            var projection = new AttendantsProjection();
            var readModel  = new AttendantsReadModel();

            projection.Project(
                readModel,
                new Events.MeetupCreated {
                Title = "EventSourcing a tope"
            },
                new Events.NumberOfSeatsUpdated {
                NumberOfSeats = 2
            },
                new Events.MeetupPublished {
            });

            when(projection, readModel);
            then(readModel);
        }
Example #3
0
        public async Task Project(object @event)
        {
            try
            {
                var projection = new AttendantsProjection();
                var id = (Guid)((dynamic)@event).Id;
                var collection = _getDb().GetCollection<AttendantsReadModel>("attendants");

                var state = await collection.Find<AttendantsReadModel>(meetup => meetup.Id == id).FirstOrDefaultAsync();
                var newState = projection.Project(state ?? new AttendantsReadModel(), @event);

                _logger.LogDebug($"Projecting event {@event} with id {id}, state {JsonConvert.SerializeObject(state)} and new state {JsonConvert.SerializeObject(newState)}");
                await collection.ReplaceOneAsync(doc => doc.Id == id, newState, new UpdateOptions
                {
                    IsUpsert = true
                });
            }
            catch (Exception ex)
            {

                _logger.LogError($"Error {ex.Message}");
            }
        }