Exemple #1
0
        public async Task GetArtifactVersions_ArtifactNoDraftsOrPublishedVersion_Success()
        {
            // Arrange
            int  artifactId    = 1;
            int  limit         = 1;
            int  offset        = 1;
            int? userId        = 1;
            bool asc           = false;
            int  sessionUserId = 1;
            var  cxn           = new SqlConnectionWrapperMock();
            var  repository    = new SqlArtifactVersionsRepository(cxn.Object);

            cxn.SetupQueryAsync("DoesArtifactHavePublishedOrDraftVersion", new Dictionary <string, object> {
                { "artifactId", artifactId }
            }, new List <bool> {
                true
            });
            // Act
            var actual = await repository.GetArtifactVersions(artifactId, limit, offset, userId, asc, sessionUserId, true);

            // Assert
            cxn.Verify();
            Assert.AreEqual(actual.ArtifactId, 1);
            Assert.AreEqual(actual.ArtifactHistoryVersions.ToList().Count(), 0);
        }
Exemple #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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
0
 public async Task GetArtifactVersions_UserIdOutOfRange_ArgumentOutOfBoundsException()
 {
     // Arrange
     int  artifactId    = 1;
     int  limit         = 1;
     int  offset        = 0;
     int? userId        = -1;
     bool asc           = false;
     int  sessionUserId = 1;
     var  cxn           = new SqlConnectionWrapperMock();
     var  repository    = new SqlArtifactVersionsRepository(cxn.Object);
     // Act
     await repository.GetArtifactVersions(artifactId, limit, offset, userId, asc, sessionUserId, true);
 }
Exemple #6
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);
        }
Exemple #7
0
        private SqlArtifactVersionsRepository CreateSqlRepositoryMock(int userId, int artifactId, int baselineId,
                                                                      int revisionId, ItemInfo itemInfo, ISet <int> baselineArtifacts)
        {
            SqlConnectionWrapperMock   connectionWrapperMock  = new SqlConnectionWrapperMock();
            Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>();

            artifactRepositoryMock
            .Setup(m => m.GetArtifactBasicDetails(artifactId, userId, null))
            .ReturnsAsync(new ArtifactBasicDetails
            {
                ItemId     = artifactId,
                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 }
            });

            _itemInfoRepositoryMock.Setup(iir => iir.GetRevisionId(
                                              artifactId, userId, null, baselineId))
            .ReturnsAsync(revisionId);

            artifactPermissionsRepositoryMock.Setup(apr => apr.GetItemInfo(
                                                        artifactId, userId, false, revisionId))
            .ReturnsAsync(itemInfo);

            _itemInfoRepositoryMock.Setup(apr => apr.GetBaselineArtifacts(
                                              baselineId, userId, true, int.MaxValue))
            .ReturnsAsync(baselineArtifacts);

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

            return(artifactVersionsRepository);
        }
Exemple #8
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);
        }
Exemple #9
0
        public async Task GetArtifactVersions_Should_Not_Return_Draft_Version_When_includeDrafts_Is_False()
        {
            // Arrange
            int  artifactId    = 1;
            int  limit         = 2;
            int  offset        = 0;
            int? userId        = 1;
            bool asc           = true;
            int  sessionUserId = 1;
            bool includeDrafts = false;

            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlArtifactVersionsRepository(cxn.Object);

            var artifactVersionParams = new Dictionary <string, object>
            {
                { "artifactId", artifactId },
                { "lim", limit },
                { "offset", offset },
                { "userId", userId.Value },
                { "ascd", asc }
            };

            cxn.SetupQueryAsync("DoesArtifactHavePublishedOrDraftVersion", new Dictionary <string, object> {
                { "artifactId", artifactId }
            }, new List <bool> {
                true
            });

            cxn.SetupQueryAsync("IsArtifactDeleted", new Dictionary <string, object> {
                { "artifactId", artifactId }
            }, new List <bool> {
                false
            });

            var testResult = new[] { new ArtifactHistoryVersion {
                                         VersionId = 1, UserId = 1, Timestamp = new DateTime()
                                     } };

            cxn.SetupQueryAsync("GetArtifactVersions", artifactVersionParams, testResult);

            var userIdsTable = SqlConnectionWrapper.ToDataTable(new List <int> {
                sessionUserId
            });

            cxn.SetupQueryAsync("GetUserInfos", new Dictionary <string, object> {
                { "userIds", userIdsTable }
            }, new List <UserInfo> {
                new UserInfo {
                    UserId = 1, DisplayName = "David", ImageId = 1
                }
            });

            // Act
            var actual = await repository.GetArtifactVersions(artifactId, limit, offset, userId, asc, sessionUserId, includeDrafts);

            // Assert
            cxn.Verify();
            Assert.AreEqual(actual.ArtifactId, 1);
            Assert.AreEqual(actual.ArtifactHistoryVersions.Count(), 1);
            Assert.AreEqual(actual.ArtifactHistoryVersions.ToList()[0].VersionId, 1);
        }
Exemple #10
0
        public async Task GetArtifactVersions_WithDraftsAscending_Success()
        {
            // Arrange
            int  artifactId    = 1;
            int  limit         = 2;
            int  offset        = 0;
            int? userId        = 1;
            bool asc           = true;
            int  sessionUserId = 1;
            var  cxn           = new SqlConnectionWrapperMock();
            var  repository    = new SqlArtifactVersionsRepository(cxn.Object);
            var  prm           = new Dictionary <string, object>
            {
                { "artifactId", artifactId },
                { "lim", limit },
                { "offset", offset },
                { "userId", userId.Value },
                { "ascd", asc }
            };

            cxn.SetupQueryAsync("DoesArtifactHavePublishedOrDraftVersion", new Dictionary <string, object> {
                { "artifactId", artifactId }
            }, new List <bool> {
                true
            });
            cxn.SetupQueryAsync("IsArtifactDeleted", new Dictionary <string, object> {
                { "artifactId", artifactId }
            }, new List <bool> {
                false
            });
            var testResult = new ArtifactHistoryVersion[] { new ArtifactHistoryVersion {
                                                                VersionId = 1, UserId = 1, Timestamp = new DateTime()
                                                            } };

            cxn.SetupQueryAsync("GetArtifactVersions", prm, testResult);
            var artifactIdsTable = SqlConnectionWrapper.ToDataTable(new List <int> {
                artifactId
            }, "Int32Collection", "Int32Value");
            var prm2 = new Dictionary <string, object> {
                { "userId", sessionUserId }, { "artifactIds", artifactIdsTable }
            };

            cxn.SetupQueryAsync("GetArtifactsWithDraft", prm2, new int[] { artifactId });

            var userIdsTable = SqlConnectionWrapper.ToDataTable(new List <int> {
                sessionUserId
            }, "Int32Collection", "Int32Value");

            cxn.SetupQueryAsync("GetUserInfos", new Dictionary <string, object> {
                { "userIds", userIdsTable }
            }, new List <UserInfo> {
                new UserInfo {
                    UserId = 1, DisplayName = "David", ImageId = 1
                }
            });

            // Act
            var actual = await repository.GetArtifactVersions(artifactId, limit, offset, userId, asc, sessionUserId, true);

            // Assert
            cxn.Verify();
            Assert.AreEqual(actual.ArtifactId, 1);
            Assert.AreEqual(actual.ArtifactHistoryVersions.ToList().Count(), 2);
            Assert.AreEqual(actual.ArtifactHistoryVersions.ToList()[1].VersionId, int.MaxValue);
            Assert.AreEqual(actual.ArtifactHistoryVersions.ToList()[0].VersionId, 1);
        }