Exemple #1
0
        public async Task ProcessCreatedArtifacts_SendsMultipleMessages_WhenMultipleEmailNotificationTriggersExistForArtifact()
        {
            // Arrange
            _workflowRepoMock.Setup(t => t.GetWorkflowMessageArtifactInfoAsync(_userId, It.IsAny <IEnumerable <int> >(), _revisionId, It.IsAny <IDbTransaction>())).ReturnsAsync(_workflowMessageArtifactInfos);
            var workflowTriggersContainer = new WorkflowTriggersContainer();

            _workflowRepoMock.Setup(t => t.GetWorkflowEventTriggersForNewArtifactEvent(_userId, It.IsAny <IEnumerable <int> >(), _revisionId, true)).ReturnsAsync(workflowTriggersContainer);

            var workflowEventTriggers = new List <WorkflowEventTrigger>();

            for (int i = 0; i < 7; i++)
            {
                workflowEventTriggers.Add(
                    new WorkflowEventTrigger
                {
                    Name      = $"Email Notification Trigger {i}",
                    Condition = new WorkflowEventCondition(),
                    Action    = new EmailNotificationAction()
                });
            }
            workflowTriggersContainer.AsynchronousTriggers.AddRange(workflowEventTriggers);

            // Act
            var result = await CreatedArtifactsNotificationHandler.ProcessCreatedArtifacts(_tenant, _message, _artifactsPublishedRepositoryMock.Object, _serviceLogRepositoryMock.Object, _wfMessagingMock.Object);

            // Assert
            Assert.IsTrue(result, "Multiple messages were sent successfully");
            _wfMessagingMock.Verify(m => m.SendMessageAsync(It.IsAny <string>(), It.IsAny <IWorkflowMessage>()), Times.Exactly(workflowEventTriggers.Count));
        }
Exemple #2
0
        public async Task ProcessCreatedArtifacts_SendsSingleMessage_WhenSingleGenerateChildrenTriggerExistsForArtifact()
        {
            // Arrange
            _workflowRepoMock.Setup(t => t.GetWorkflowMessageArtifactInfoAsync(_userId,
                                                                               It.IsAny <IEnumerable <int> >(),
                                                                               _revisionId,
                                                                               It.IsAny <IDbTransaction>())).ReturnsAsync(_workflowMessageArtifactInfos);
            var workflowTriggersContainer = new WorkflowTriggersContainer();

            workflowTriggersContainer.AsynchronousTriggers.Add(new WorkflowEventTrigger
            {
                Name      = "Trigger One",
                Condition = new WorkflowEventCondition(),
                Action    = new GenerateChildrenAction
                {
                    ArtifactTypeId = ItemTypeId,
                    ChildCount     = 3
                }
            });
            _workflowRepoMock.Setup(t => t.GetWorkflowEventTriggersForNewArtifactEvent(_userId,
                                                                                       It.IsAny <IEnumerable <int> >(),
                                                                                       _revisionId, true)).ReturnsAsync(workflowTriggersContainer);

            // Act
            var result = await CreatedArtifactsNotificationHandler.ProcessCreatedArtifacts(_tenant,
                                                                                           _message,
                                                                                           _artifactsPublishedRepositoryMock.Object,
                                                                                           _serviceLogRepositoryMock.Object,
                                                                                           _wfMessagingMock.Object);

            // Assert
            Assert.IsTrue(result, "One message was sent successfully");
            _wfMessagingMock.Verify(m => m.SendMessageAsync(It.IsAny <string>(), It.IsAny <IWorkflowMessage>()), Times.Exactly(1));
        }
Exemple #3
0
        public async Task ProcessCreatedArtifacts_MessageIsNull_ReturnsFalse()
        {
            // Act
            var result = await CreatedArtifactsNotificationHandler.ProcessCreatedArtifacts(_tenant,
                                                                                           null,
                                                                                           _artifactsPublishedRepositoryMock.Object,
                                                                                           _serviceLogRepositoryMock.Object,
                                                                                           _wfMessagingMock.Object);

            // Assert
            Assert.IsFalse(result, "Message should not be processed successfully");
        }
Exemple #4
0
        public async Task ProcessCreatedArtifacts_NoCreatedArtifacts_ReturnsFalse()
        {
            var message = new ArtifactsPublishedMessage
            {
                RevisionId = _revisionId,
                UserId     = _userId,
                UserName   = "******",
                Artifacts  = new List <PublishedArtifactInformation>()
            };
            // Act
            var result = await CreatedArtifactsNotificationHandler.ProcessCreatedArtifacts(_tenant,
                                                                                           message,
                                                                                           _artifactsPublishedRepositoryMock.Object,
                                                                                           _serviceLogRepositoryMock.Object,
                                                                                           _wfMessagingMock.Object);

            // Assert
            Assert.IsFalse(result, "Message should not be processed successfully");
        }
Exemple #5
0
        public async Task ProcessCreatedArtifacts_OnlySynchronousTriggersForArtifact_ReturnsFalseAndSendsNoMessages()
        {
            // Arrange
            _workflowRepoMock.Setup(t => t.GetWorkflowMessageArtifactInfoAsync(_userId, It.IsAny <IEnumerable <int> >(), _revisionId, It.IsAny <IDbTransaction>())).ReturnsAsync(_workflowMessageArtifactInfos);
            var workflowTriggersContainer = new WorkflowTriggersContainer();

            workflowTriggersContainer.SynchronousTriggers.Add(
                new WorkflowEventTrigger
            {
                Name      = "Property Change Trigger",
                Condition = new WorkflowEventCondition(),
                Action    = new PropertyChangeAction()
            });
            _workflowRepoMock.Setup(t => t.GetWorkflowEventTriggersForNewArtifactEvent(_userId, It.IsAny <IEnumerable <int> >(), _revisionId, true)).ReturnsAsync(workflowTriggersContainer);

            // Act
            var result = await CreatedArtifactsNotificationHandler.ProcessCreatedArtifacts(_tenant, _message, _artifactsPublishedRepositoryMock.Object, _serviceLogRepositoryMock.Object, _wfMessagingMock.Object);

            // Assert
            Assert.IsFalse(result, "No messages should be sent for synchronous triggers");
            _wfMessagingMock.Verify(m => m.SendMessageAsync(It.IsAny <string>(), It.IsAny <IWorkflowMessage>()), Times.Exactly(0));
        }