コード例 #1
0
        public async Task HandleAction_ArtifactIdIsInvalid_ReturnsFalse()
        {
            // Arrange
            var actionHelper = new GenerateDescendantsActionHelper();

            _generateActionsRepositoryMock.Setup(t => t.IsProjectMaxArtifactBoundaryReached(ProjectId)).ReturnsAsync(false);

            // Act
            var result = await actionHelper.HandleAction(new TenantInformation
            {
                TenantId = Guid.NewGuid().ToString(),
                BlueprintConnectionString = "BlueprintConnectionString"
            },
                                                         new GenerateDescendantsMessage
            {
                UserId                = UserId,
                ProjectId             = ProjectId,
                RevisionId            = RevisionId,
                DesiredArtifactTypeId = DesiredArtifactTypeId,
                UserName              = UserName
            },
                                                         _generateActionsRepositoryMock.Object);

            // Assert
            Assert.IsFalse(result, "Action should have failed for invalid message");
            _jobsRepoMock.Verify(t => t.AddJobMessage(It.IsAny <JobType>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
コード例 #2
0
        public async Task HandleAction_NullTenant_ReturnsFalse()
        {
            var actionHelper = new GenerateDescendantsActionHelper();
            var result       = await actionHelper.HandleAction(null, new GenerateDescendantsMessage(), null);

            Assert.IsFalse(result, "Action should have failed for null tenant");
            _jobsRepoMock.Verify(t => t.AddJobMessage(It.IsAny <JobType>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
コード例 #3
0
        public async Task HandleAction_CreatesJob_ReturnsTrue()
        {
            // Arrange
            var actionHelper = new GenerateDescendantsActionHelper();

            _generateActionsRepositoryMock.Setup(t => t.IsProjectMaxArtifactBoundaryReached(ProjectId)).ReturnsAsync(false);
            _itemTypeRepoMock.Setup(
                t => t.GetCustomItemTypeForProvidedStandardItemTypeIdInProject(ProjectId, DesiredArtifactTypeId))
            .ReturnsAsync(new SqlItemType
            {
                ProjectId  = ProjectId,
                ItemTypeId = DesiredArtifactTypeId,
                Name       = "Test"
            });
            var sqlUser = new SqlUser
            {
                UserId = UserId,
                Login  = UserName
            };

            _generateActionsRepositoryMock.Setup(m => m.GetUser(It.IsAny <int>())).ReturnsAsync(sqlUser);
            _userRepoMock.Setup(t => t.GetExistingUsersByIdsAsync(It.IsAny <IEnumerable <int> >())).
            ReturnsAsync(new List <SqlUser>
            {
                sqlUser
            });

            _jobsRepoMock.Setup(t => t.AddJobMessage(JobType.GenerateDescendants,
                                                     false,
                                                     It.IsAny <string>(),
                                                     It.IsAny <string>(),
                                                     It.IsAny <int?>(),
                                                     It.IsAny <string>(),
                                                     UserId,
                                                     UserName,
                                                     It.IsAny <string>())).ReturnsAsync(2);

            // Act
            var result = await actionHelper.HandleAction(new TenantInformation
            {
                TenantId = Guid.NewGuid().ToString(),
                BlueprintConnectionString = "BlueprintConnectionString"
            },
                                                         new GenerateDescendantsMessage
            {
                ArtifactId            = ArtifactId,
                UserId                = UserId,
                RevisionId            = RevisionId,
                ProjectId             = ProjectId,
                DesiredArtifactTypeId = DesiredArtifactTypeId,
                UserName              = UserName
            },
                                                         _generateActionsRepositoryMock.Object);

            // Assert
            Assert.IsTrue(result, "Action should have succeeded");
            _jobsRepoMock.Verify(t => t.AddJobMessage(JobType.GenerateDescendants, It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
コード例 #4
0
        public async Task HandleAction_WhenAncestorInfiniteLoopExists_ReturnsFalse()
        {
            // arrange
            const int duplicateId            = 11;
            var       ancestorsWithDuplicate = new[]
            {
                duplicateId,
                12,
                13,
                14,
                duplicateId
            };
            var generateDescendantsMessage = new GenerateDescendantsMessage
            {
                AncestorArtifactTypeIds = ancestorsWithDuplicate,
                ArtifactId            = ArtifactId,
                BaseHostUri           = "uri",
                ChildCount            = 1,
                DesiredArtifactTypeId = DesiredArtifactTypeId,
                ProjectId             = ProjectId,
                ProjectName           = "project",
                RevisionId            = RevisionId,
                TypePredefined        = 1,
                UserId   = UserId,
                UserName = UserName
            };

            _generateActionsRepositoryMock.Setup(m => m.IsProjectMaxArtifactBoundaryReached(It.IsAny <int>())).ReturnsAsync(false);
            var tenantInformation = new TenantInformation();
            var actionHelper      = new GenerateDescendantsActionHelper();

            // act
            var result = await actionHelper.HandleAction(tenantInformation, generateDescendantsMessage, _generateActionsRepositoryMock.Object);

            // assert
            Assert.IsFalse(result, "Children should not have been generated.");
            _jobsRepoMock.Verify(t => t.AddJobMessage(It.IsAny <JobType>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }