Esempio n. 1
0
        public async Task GetVersionControlArtifactInfoAsync_AuthorizationException_EmptyPermissions()
        {
            // Arrange
            int userId = 1, itemId = 11, artifactId = 10;

            SqlConnectionWrapperMock   connectionWrapperMock = new SqlConnectionWrapperMock();
            Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>();

            artifactRepositoryMock
            .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null))
            .ReturnsAsync(new ArtifactBasicDetails
            {
                ItemId     = itemId,
                ArtifactId = artifactId
            });

            Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>();

            artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions(
                                                        It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(new Dictionary <int, RolePermissions> {
            });

            SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository(
                connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object);

            // Act
            await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId);
        }
Esempio n. 2
0
        public async Task GetVersionControlArtifactInfoAsync_SubArtifactIdNotNull()
        {
            // Arrange
            int userId = 1, itemId = 11, artifactId = 10;

            SqlConnectionWrapperMock   connectionWrapperMock = new SqlConnectionWrapperMock();
            Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>();

            artifactRepositoryMock
            .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null))
            .ReturnsAsync(new ArtifactBasicDetails
            {
                ItemId     = itemId,
                ArtifactId = artifactId
            });

            Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>();

            artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions(
                                                        It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(new Dictionary <int, RolePermissions> {
                { artifactId, RolePermissions.Read }
            });

            SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository(
                connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object);

            // Act
            VersionControlArtifactInfo artifactInfo = (await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId));

            // Assert
            connectionWrapperMock.Verify();
            Assert.IsNotNull(artifactInfo.SubArtifactId);
        }
Esempio n. 3
0
        public async Task GetVersionControlArtifactInfoAsync_ResourceNotFoundException()
        {
            // Arrange
            int userId = 1, itemId = 11;

            SqlConnectionWrapperMock connectionWrapperMock = new SqlConnectionWrapperMock();

            Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>();

            artifactRepositoryMock
            .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null))
            .ReturnsAsync((ArtifactBasicDetails)null);

            Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>();

            artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions(
                                                        It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync((Dictionary <int, RolePermissions>)null);

            SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository(
                connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object);

            // Act
            await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId);
        }
Esempio n. 4
0
        public async Task GetVersionControlArtifactInfoAsync_LatestDeleted()
        {
            // Arrange
            int userId = 1, itemId = 11, artifactId = 10, lockedByUserId = 2, latestDeletedByUserId = 3;

            SqlConnectionWrapperMock   connectionWrapperMock = new SqlConnectionWrapperMock();
            Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>();

            artifactRepositoryMock
            .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null))
            .ReturnsAsync(new ArtifactBasicDetails
            {
                ItemId                = itemId,
                ArtifactId            = artifactId,
                DraftDeleted          = false,
                LatestDeleted         = true,
                UserId                = userId,
                LockedByUserId        = lockedByUserId,
                LatestDeletedByUserId = latestDeletedByUserId
            });

            Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>();

            artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions(
                                                        It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(new Dictionary <int, RolePermissions> {
                { artifactId, RolePermissions.Read }
            });

            SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository(
                connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object);

            // Act
            VersionControlArtifactInfo artifactInfo = (await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId));

            // Assert
            connectionWrapperMock.Verify();
            Assert.IsNotNull(artifactInfo.DeletedByUser);
            Assert.IsNotNull(artifactInfo.DeletedByUser.Id);
            Assert.IsTrue(artifactInfo.DeletedByUser.Id.Value == latestDeletedByUserId);
        }
Esempio n. 5
0
        public async Task GetVersionControlArtifactInfoAsync_NoChangesLockedBySomeoneElse()
        {
            // Arrange
            int userId = 1, itemId = 11, artifactId = 10, lockedByUserId = 2;

            SqlConnectionWrapperMock   connectionWrapperMock = new SqlConnectionWrapperMock();
            Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>();

            artifactRepositoryMock
            .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null))
            .ReturnsAsync(new ArtifactBasicDetails
            {
                ItemId                = itemId,
                ArtifactId            = artifactId,
                HasDraftRelationships = false,
                UserId                = userId,
                LockedByUserId        = lockedByUserId,
            });

            Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>();

            artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions(
                                                        It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(new Dictionary <int, RolePermissions> {
                { artifactId, RolePermissions.Read }
            });

            SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository(
                connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object);

            // Act
            VersionControlArtifactInfo artifactInfo = (await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId));

            // Assert
            connectionWrapperMock.Verify();
            Assert.IsFalse(artifactInfo.HasChanges);
        }