public async Task <Unit> Handle(UpdatePresenceOnBarbecue request, CancellationToken cancellationToken) { var presence = _presences.GetAll() .Include(o => o.Barbecue) .FirstOrDefault(o => o.ParticipantId == request.ParticipantId && o.BarbecueId == request.BarbecueId); if (presence == null) { _notifications.AddNotification(AppConsts.PresenceNotFound); return(Unit.Value); } presence.Barbecue.UpdateDate = DateTime.Now; var oldValue = presence.Value; presence.Value = request.Value; await _presences.Commit(); await _mediator.Publish(PresenceUpdated.Notify(request.BarbecueId, oldValue, presence.Value, request.Paid)); return(Unit.Value); }
public void Should_UpdateBarbecueValues_When_PresenceIsUpdated() { var id = Guid.NewGuid(); var participantId = Guid.NewGuid(); var barbecue = new Barbecue { Id = id, Presences = new List <Presence> { new Presence { ParticipantId = participantId } } }; _context.Setup(o => o.GetAll()).Returns(new AsyncEnumerable <Barbecue>(new List <Barbecue> { barbecue })); _context.Setup(o => o.Commit()); _handler.Handle(PresenceUpdated.Notify(Guid.Empty, 10, 20, true), default).GetAwaiter().GetResult(); Mock.VerifyAll(); }