Example #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);
        }
Example #2
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);
 }
Example #3
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);
        }
Example #4
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);
        }