Ejemplo n.º 1
0
        public async Task Handle(PaymentUpdated notification, CancellationToken cancellationToken)
        {
            var bbq = await _context.GetAll()
                      .FirstOrDefaultAsync(o => o.Id == notification.BarbecueId);

            if (bbq == null)
            {
                _notifications.AddNotification(AppConsts.BarbecueNotFound);
                return;
            }

            bbq.TotalRaised += notification.Paid ? notification.Value : -notification.Value;
            await _context.Commit();
        }
        public async Task <Unit> Handle(UpdatePayment 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;
            presence.Paid = request.Paid;
            await _presences.Commit();

            await _mediator.Publish(PaymentUpdated.Notify(request.BarbecueId, presence.Value, request.Paid));


            return(Unit.Value);
        }
        public void Should_UpdateBarbecueValues_When_PaymentIsUpdated()
        {
            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(PaymentUpdated.Notify(Guid.Empty, 20, true), default).GetAwaiter().GetResult();
            Mock.VerifyAll();
        }
Ejemplo n.º 4
0
 public void When(PaymentUpdated paymentUpdated)
 {
 }