public async Task ProcessMessageAsync_BodyContextIsNull_Nack()
        {
            var receivedMessage = new TaskOfferCreatedEventBuilder().Build().ToMessage();

            await _processor.ProcessMessageAsync(receivedMessage, CancellationToken.None);

            Mock.Get(receivedMessage).Verify(m => m.Nack(), Times.Once);
        }
        public async Task ProcessMessageAsync_SavesUserAction_ObjectType()
        {
            var taskOfferCreatedEvent = new TaskOfferCreatedEventBuilder().WithContext().WithTaskOfferEntityDto().Build();

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Equal(ObjectType.TaskOffer, SavedUserAction.ObjectType);
        }
        public async Task ProcessMessageAsync_FilledBody_Ack()
        {
            var receivedMessage = new TaskOfferCreatedEventBuilder()
                                  .WithContext(new EventContextBuilder().WithWebContext())
                                  .WithTaskOfferEntityDto()
                                  .Build().ToMessage();

            await _processor.ProcessMessageAsync(receivedMessage, CancellationToken.None);

            Mock.Get(receivedMessage).Verify(m => m.Ack(), Times.Once);
        }
        public async Task ProcessMessageAsync_SavesUserActionWithoutObjectGuid_ObjectGuidIsNull()
        {
            var taskOfferCreatedEvent = new TaskOfferCreatedEventBuilder()
                                        .WithTaskOfferEntityDto()
                                        .WithContext()
                                        .Build();

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Null(SavedUserAction.ObjectGuid);
        }
        public async Task ProcessMessageAsync_SavesUserAction_UserId()
        {
            var taskOfferCreatedEvent = new TaskOfferCreatedEventBuilder()
                                        .WithTaskOfferEntityDto(new TaskOfferEntityDtoBuilder().WithCreatorId(7))
                                        .WithContext()
                                        .Build();

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Equal(taskOfferCreatedEvent.TaskOffer.CreatorId, SavedUserAction.UserId);
        }
        public async Task ProcessMessageAsync_IosClient_DoesNotCallUserActionManager()
        {
            var message = new TaskOfferCreatedEventBuilder()
                          .WithContext(new EventContextBuilder().WithWebContext().WithClientType(ClientType.iPhoneApplication))
                          .Build()
                          .ToMessage();

            await _processor.ProcessMessageAsync(message, CancellationToken.None);

            UserActionManagerMock.Verify(m => m.SaveUserActionAsync(It.IsAny <UserAction>()), Times.Never);
            Mock.Get(message).Verify(m => m.Ack(), Times.Once);
        }
        public async Task ProcessMessageAsync_SavesUserAction_ActionDate()
        {
            var taskOfferCreatedEvent = new TaskOfferCreatedEventBuilder()
                                        .WithTaskOfferEntityDto()
                                        .WithContext(new EventContextBuilder()
                                                     .WithTimeStamp(new DateTime(2011, 11, 11, 11, 11, 11)))
                                        .Build();

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Equal(taskOfferCreatedEvent.Context.Timestamp, SavedUserAction.ActionDateTimeUtc);
        }
        public async Task ProcessMessageAsync_WebClient_SavesUserAction()
        {
            var message = new TaskOfferCreatedEventBuilder()
                          .WithContext(new EventContextBuilder().WithWebContext().WithClientType(ClientType.DesktopBrowser))
                          .WithTaskOfferEntityDto()
                          .Build()
                          .ToMessage();

            await _processor.ProcessMessageAsync(message, CancellationToken.None);

            UserActionManagerMock.Verify(m => m.SaveUserActionAsync(It.IsAny <UserAction>()), Times.Once);
            Mock.Get(message).Verify(m => m.Ack(), Times.Once);
        }
        public async Task ProcessMessageAsync_SavesUserAction_InitiatorType()
        {
            const InitiatorType initiatorType = InitiatorType.Moderator;
            var taskOfferCreatedEvent         = new TaskOfferCreatedEventBuilder()
                                                .WithTaskOfferEntityDto()
                                                .WithContext(new EventContextBuilder()
                                                             .WithInitiator(new OperationInitiatorBuilder()
                                                                            .WithInitiatorType(initiatorType)))
                                                .Build();

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Equal(initiatorType, SavedUserAction.InitiatorType);
        }
        public async Task ProcessMessageAsync_SavesUserAction_LingeringHash()
        {
            const long lingeringHash = 42;

            var taskOfferCreatedEvent = new TaskOfferCreatedEventBuilder()
                                        .WithTaskOfferEntityDto()
                                        .WithContext(new EventContextBuilder()
                                                     .WithWebContext(new WebContextBuilder()
                                                                     .WithLingeringAttributionDataHash(lingeringHash)))
                                        .Build();

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Equal(lingeringHash, SavedUserAction.LingeringHash);
        }
        public async Task ProcessMessageAsync_SavesUserAction_ChannelAttributesHash()
        {
            const long expectedChannelAttributesId = 42;

            var taskOfferCreatedEvent = new TaskOfferCreatedEventBuilder()
                                        .WithTaskOfferEntityDto()
                                        .WithContext(new EventContextBuilder()
                                                     .WithWebContext(new WebContextBuilder()
                                                                     .WithAttributionDataHash(423)))
                                        .Build();

            SetupChannelAttributesManagerMock(taskOfferCreatedEvent.Context.WebContext.AttributionDataHash, expectedChannelAttributesId);

            await _processor.ProcessMessageAsync(taskOfferCreatedEvent.ToMessage(), CancellationToken.None);

            Assert.Equal(expectedChannelAttributesId, SavedUserAction.ChannelAttributesId);
        }