public void CreateLinkEventRequest_TurnBack_CreatesRecord()
        {
            var sut = GetService();

            var req = new CreateLinkEventRequest()
            {
                Key           = _link.Key,
                LinkEventType = LinkEventType.TurnBack
            };

            sut.Post(req);

            Assert.IsTrue(_db.Exists <LinkEvent>(m => m.SessionId == SessionId && m.LinkEventType == req.LinkEventType));
        }
        public void CreateLinkEventRequest_TurnBack_IncrementsTotal()
        {
            var sut = GetService();

            var req = new CreateLinkEventRequest()
            {
                Key           = _link.Key,
                LinkEventType = LinkEventType.TurnBack
            };

            sut.Post(req);

            _link = _db.SingleById <Link>(_link.Id);

            Assert.AreEqual(1, _link.TotalTurnBacks);
        }
Esempio n. 3
0
        public object Post(CreateLinkEventRequest request)
        {
            var link = _linkRepo.GetByKey(request.Key);

            if (link == null)
            {
                throw HttpError.NotFound($"Link with key '{request.Key}' not found.");
            }

            UnitOfWork(() =>
            {
                var c       = request.ConvertTo <LinkEvent>();
                c.LinkId    = link.Id;
                c.CreatedAt = DateTime.UtcNow;
                c.SessionId = Session.Id;
                _linkRepo.CreateLinkEvent(c);

                _domainEventBus.Handle(new LinkEventCreatedEvent(c));
            });

            return(_linkRepo.GetLinkResponse(link.Id));
        }