Пример #1
0
        public WorkItemCreatedHandlerTests()
        {
            _workItemAuditService = Substitute.For <IWorkItemAuditService>();
            _logger      = Substitute.For <ILoggerAdapter <WorkItemCreatedHandler> >();
            _userService = Substitute.For <IUserService>();
            _bus         = Substitute.For <IBus>();
            _context     = Substitute.For <ConsumeContext <WorkItemCreated> >();


            _userService.GetById(1).Returns(UserDto);
            _userService.GetById(2).Returns <UserDto>(value => null);

            _workItemAuditService.WICreated(1, Arg.Any <WorkItemHistoryDto>()).Returns(WorkItemAuditDto);
            _workItemAuditService.WICreated(2, ValidNewWorkItem).Returns(WorkItemAuditDto);

            _handler = new WorkItemCreatedHandler(_workItemAuditService, _logger, _userService, _bus);
        }
Пример #2
0
        public async Task Consume(ConsumeContext <WorkItemCreated> context)
        {
            try
            {
                if (context.Message?.NewWorkItem == null)
                {
                    throw new ArgumentNullException("Work item is not provided");
                }

                var workItem = context.Message.NewWorkItem;

                var userData = await _userService.GetById(workItem.AssigneeId);

                if (userData == null)
                {
                    throw new ArgumentNullException("Assignee not found");
                }

                await _bus.Publish(new EmailSend
                {
                    To      = userData.Email,
                    Subject = "New work item assignee",
                    Body    = $"You are the new assignee for the work item # {context.Message.WorkItemId}"
                });

                _logger.Information($"Bus published EmailSend contract with email: {userData.Email}. WorkItemId: {context.Message.WorkItemId}");

                var createdEntity = await _workItemAuditService.WICreated(context.Message.WorkItemId, context.Message.NewWorkItem);

                _logger.Information($"Successfully logged work item creation. WorkItemAuditId: {createdEntity.Id}");
            }
            catch (Exception exception)
            {
                _logger.Error(exception.Message);
                return;
            }
        }