Пример #1
0
        public async Task GetContentArtifactIdsAsync_AddDraftsIsTrue_ReturnsCorrectResult()
        {
            // Arrange
            var queryParameters = new Dictionary <string, object>
            {
                { "@userId", _userId },
                { "@collectionId", _collectionId },
                { "@addDrafts", true }
            };
            var expectedResult = new List <int> {
                2, 3, 4, 5
            };

            _cxn.SetupQueryAsync(
                SqlCollectionsRepository.GetArtifactIdsInCollectionQuery,
                queryParameters,
                expectedResult,
                commandType: CommandType.Text);

            // Act
            var actualResult = await _repository.GetContentArtifactIdsAsync(_collectionId, _userId);

            // Assert
            CollectionAssert.AreEquivalent(expectedResult, actualResult.ToList());
        }
        public async Task GetDiscussions_CommentReturned_NoCommentReturned()
        {
            // Arrange
            int itemId      = 1;
            int projectId   = 1;
            var discussions = new List <Discussion>();
            var reviews     = new List <ThreadReviewTrace>()
            {
                new ThreadReviewTrace()
                {
                    ThreadId = 1, ReviewId = 1
                }
            };
            var returnResult = new Tuple <IEnumerable <Discussion>, IEnumerable <ThreadReviewTrace> >(discussions, reviews);

            _cxn.SetupQueryMultipleAsync("GetItemDiscussions", new Dictionary <string, object> {
                { "ItemId", itemId }
            }, returnResult);
            _cxn.SetupQueryAsync("GetItemDiscussionStates", new Dictionary <string, object> {
                { "ItemId", itemId }
            }, new List <DiscussionState>());

            // Act
            var result = (await _discussionsRepository.GetDiscussions(itemId, projectId)).ToList();

            // Assert
            Assert.AreEqual(0, result.Count);
        }
Пример #3
0
        public async Task GetCurrentState_StoredProcedureReturnsNull_ReturnsFailureResult()
        {
            // Arrange
            var permissionsRepository = CreatePermissionsRepositoryMock(new[] { 1 }, 1, RolePermissions.Edit | RolePermissions.Read);
            var artifactIdsTable      = SqlConnectionWrapper.ToDataTable(new[] { 1 }, "Int32Collection", "Int32Value");

            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlWorkflowRepository(cxn.Object, permissionsRepository.Object);

            cxn.SetupQueryAsync("GetArtifactBasicDetails",
                                new Dictionary <string, object>
            {
                { "userId", 1 },
                { "itemId", 1 }
            },
                                new List <ArtifactBasicDetails> {
                new ArtifactBasicDetails {
                    PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor
                }
            });
            cxn.SetupQueryAsync("GetWorkflowStatesForArtifacts",
                                new Dictionary <string, object>
            {
                { "userId", 1 },
                { "artifactIds", artifactIdsTable },
                { "revisionId", 2147483647 },
                { "addDrafts", true }
            },
                                new List <SqlWorkFlowState>());

            // Act
            var result = (await repository.GetStateForArtifactAsync(1, 1, int.MaxValue, true));

            Assert.IsTrue(result == null, "Workflow State is not null");
        }
Пример #4
0
        public async Task ChangeStateForArtifactAsync_WithEditPermissions_SuccessfullyReturnsState()
        {
            // Arrange
            int userId         = 1;
            int workflowId     = 4;
            int artifactId     = 1;
            int desiredStateId = 6;

            var permissionsRepository = CreatePermissionsRepositoryMock(new[] { artifactId }, userId, RolePermissions.Edit);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlWorkflowRepository(cxn.Object, permissionsRepository.Object);

            var stateChangeParam = new WorkflowStateChangeParameterEx
            {
                ToStateId = desiredStateId
            };
            var expected = new WorkflowState
            {
                Id         = desiredStateId,
                Name       = "Ready",
                WorkflowId = workflowId
            };

            cxn.SetupQueryAsync("GetArtifactBasicDetails",
                                new Dictionary <string, object>
            {
                { "userId", userId },
                { "itemId", artifactId }
            },
                                new List <ArtifactBasicDetails> {
                new ArtifactBasicDetails {
                    PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor
                }
            });
            cxn.SetupQueryAsync("ChangeStateForArtifact",
                                new Dictionary <string, object>
            {
                { "userId", userId },
                { "artifactId", artifactId },
                { "desiredStateId", desiredStateId },
                { "result", null }
            },
                                new List <SqlWorkFlowState>
            {
                new SqlWorkFlowState()
                {
                    WorkflowId        = workflowId,
                    WorkflowStateId   = desiredStateId,
                    WorkflowStateName = "Ready",
                    Result            = 0
                }
            });
            // Act
            var result = (await repository.ChangeStateForArtifactAsync(userId, artifactId, stateChangeParam));

            // Assert
            Assert.AreEqual(workflowId, result.WorkflowId);
            Assert.AreEqual(desiredStateId, result.Id);
        }
Пример #5
0
        public async Task GetTransitionsAsync_WithEditPermissions_SuccessfullyReads()
        {
            // Arrange
            var permissionsRepository = CreatePermissionsRepositoryMock(new[] { 1 }, 1, RolePermissions.Edit);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlWorkflowRepository(cxn.Object, permissionsRepository.Object);

            cxn.SetupQueryAsync("GetArtifactBasicDetails",
                                new Dictionary <string, object>
            {
                { "userId", 1 },
                { "itemId", 1 }
            },
                                new List <ArtifactBasicDetails> {
                new ArtifactBasicDetails {
                    PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor
                }
            });
            cxn.SetupQueryAsync("GetTransitionsForState",
                                new Dictionary <string, object>
            {
                { "workflowId", 1 },
                { "stateId", 1 },
                { "userId", 1 }
            },
                                new List <SqlWorkflowTransition>
            {
                new SqlWorkflowTransition
                {
                    WorkflowEventId   = 1,
                    ToStateId         = 2,
                    ToStateName       = "A",
                    FromStateId       = 1,
                    WorkflowEventName = "TA"
                },
                new SqlWorkflowTransition
                {
                    WorkflowEventId   = 2,
                    ToStateId         = 3,
                    ToStateName       = "B",
                    FromStateId       = 1,
                    WorkflowEventName = "TB"
                },
                new SqlWorkflowTransition
                {
                    WorkflowEventId   = 3,
                    ToStateId         = 4,
                    ToStateName       = "C",
                    FromStateId       = 1,
                    WorkflowEventName = "TC"
                }
            });
            // Act
            var result = (await repository.GetTransitionsAsync(1, 1, 1, 1));

            Assert.IsTrue(result.Count == 3, "Transitions could not be retrieved");
        }
Пример #6
0
        public async Task GetTransitionForAssociatedStatesAsync_WithEditPermissions_SuccessfullyReturnsTransition()
        {
            // Arrange
            var       permissionsRepository = CreatePermissionsRepositoryMock(new[] { 1 }, 1, RolePermissions.Edit);
            var       cxn          = new SqlConnectionWrapperMock();
            var       repository   = new SqlWorkflowRepository(cxn.Object, permissionsRepository.Object);
            int       userId       = 1;
            int       workflowId   = 4;
            int       fromStateId  = 5;
            int       toStateId    = 6;
            const int transitionId = 1;

            var expected = new SqlWorkflowTransition
            {
                WorkflowEventId   = transitionId,
                ToStateId         = toStateId,
                ToStateName       = "New",
                FromStateId       = fromStateId,
                FromStateName     = "Ready",
                WorkflowEventName = "New To Redy",
                WorkflowId        = workflowId
            };

            cxn.SetupQueryAsync("GetArtifactBasicDetails",
                                new Dictionary <string, object>
            {
                { "userId", userId },
                { "itemId", 1 }
            },
                                new List <ArtifactBasicDetails> {
                new ArtifactBasicDetails {
                    PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor
                }
            });
            cxn.SetupQueryAsync("GetTransitionAssociatedWithStates",
                                new Dictionary <string, object>
            {
                { "workflowId", workflowId },
                { "fromStateId", fromStateId },
                { "toStateId", toStateId },
                { "userId", userId }
            },
                                new List <SqlWorkflowTransition>
            {
                expected
            });
            // Act
            var result = (await repository.GetTransitionForAssociatedStatesAsync(userId, 1, workflowId, fromStateId, toStateId, transitionId));

            // Assert
            Assert.AreEqual(workflowId, result.WorkflowId);
            Assert.AreEqual(fromStateId, result.FromState.Id);
            Assert.AreEqual(toStateId, result.ToState.Id);
            Assert.AreEqual(transitionId, result.Id);
        }
        public async Task GetArtifactsWithPropertyValuesAsync_AllParametersAreValid_Success()
        {
            // Arrange
            _cxn.SetupQueryAsync("GetPropertyValuesForArtifacts", It.IsAny <Dictionary <string, object> >(), _expectedCollectionArtifacts);

            // Act
            var actualResult = await _collectionRepository.GetArtifactsWithPropertyValuesAsync(UserId, new List <int> {
                1, 2, 3
            });

            // assert
            Assert.IsNotNull(actualResult);
            Assert.AreEqual(_expectedCollectionArtifacts.Count, actualResult.Count);
        }
Пример #8
0
        private static IItemSearchRepository CreateFullTextSearchRepository <T>(
            FullTextSearchCriteria searchCriteria,
            ICollection <T> queryResult,
            ICollection <int?> queryResult2 = null)
        {
            var connectionWrapper = new SqlConnectionWrapperMock();

            connectionWrapper.SetupQueryAsync("SearchFullText",
                                              new Dictionary <string, object>
            {
                { "predefineds", SqlItemSearchRepository.Predefineds },
                { "page", Page },
                { "pageSize", PageSize },
                { "maxItems", MaxItems },
            },
                                              queryResult);
            connectionWrapper.SetupQueryMultipleAsync("SearchFullTextMetaData",
                                                      new Dictionary <string, object>
            {
                { "predefineds", SqlItemSearchRepository.Predefineds },
            },
                                                      new Tuple <IEnumerable <T>, IEnumerable <int?> >(queryResult, queryResult2));
            if (searchCriteria.ItemTypeIds != null)
            {
                connectionWrapper.SetupQueryAsync("SearchFullTextByItemTypes",
                                                  new Dictionary <string, object>
                {
                    { "predefineds", SqlItemSearchRepository.Predefineds },
                    { "page", Page },
                    { "pageSize", PageSize },
                    { "maxItems", MaxItems },
                    { "itemTypeIds", SqlConnectionWrapper.ToDataTable(searchCriteria.ItemTypeIds) }
                },
                                                  queryResult);
                connectionWrapper.SetupQueryMultipleAsync("SearchFullTextByItemTypesMetaData",
                                                          new Dictionary <string, object>
                {
                    { "predefineds", SqlItemSearchRepository.Predefineds },
                    { "itemTypeIds", SqlConnectionWrapper.ToDataTable(searchCriteria.ItemTypeIds) }
                },
                                                          new Tuple <IEnumerable <T>, IEnumerable <int?> >(queryResult, queryResult2));
            }

            var configuration = new Mock <ISearchConfiguration>();

            configuration.Setup(c => c.MaxItems).Returns(MaxItems.ToStringInvariant());
            configuration.Setup(c => c.MaxSearchableValueStringSize).Returns(MaxSearchableValueStringSize.ToStringInvariant());

            return(new SqlItemSearchRepository(connectionWrapper.Object, configuration.Object));
        }
        public async Task GetProjectGroupsAsync_ProjectNotFound_NotFoundError()
        {
            // Arrange
            var cxn         = new SqlConnectionWrapperMock();
            var repository  = new SqlGroupRepository(cxn.Object);
            var projectId   = 1;
            var tabularData = new TabularData
            {
                Pagination = new Pagination {
                    Limit = 10, Offset = 0
                },
                Sorting = new Sorting {
                    Order = SortOrder.Asc, Sort = "name"
                }
            };
            int errorCode = 50016; // there are no project for this projectId

            Group[] projectGroups = { };

            cxn.SetupQueryAsync("GetAvailableGroupsForProject",
                                new Dictionary <string, object> {
                { "projectId", projectId }
            },
                                projectGroups,
                                new Dictionary <string, object> {
                { "ErrorCode", errorCode }
            });

            // Act
            await repository.GetProjectGroupsAsync(projectId, tabularData);
        }
Пример #10
0
        public async Task HeadFile_QueryReturnsEmpty_ReturnsNull()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid       = new Guid("88888888888888888888888888888888");

            File[] result = { };
            cxn.SetupQueryAsync(
                "[FileStore].ReadFileHead",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                result);

            // Act
            File file = await repository.GetFileHead(guid);

            // Assert
            cxn.Verify();
            Assert.IsNull(file);
        }
Пример #11
0
        public async Task GetEffectiveUserLicenseAsync_QueryReturnsLicenseType_ReturnsFirst()
        {
            // Arrange
            var cxn         = new SqlConnectionWrapperMock();
            var repository  = new SqlUserRepository(cxn.Object, cxn.Object);
            var userId      = 1;
            var userIds     = new[] { userId };
            var userIdTable = SqlConnectionWrapper.ToDataTable(userIds);
            var result      = new List <UserLicense> {
                new UserLicense {
                    UserId = userId, LicenseType = 3
                }
            };

            cxn.SetupQueryAsync("GetEffectiveUserLicense", new Dictionary <string, object> {
                { "UserIds", userIdTable }
            }, result);

            // Act
            var licenseType = await repository.GetEffectiveUserLicenseAsync(userId);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.First().LicenseType, licenseType);
        }
Пример #12
0
        public async Task DeleteUsersAsync_UsersToDeleteDoNotExists_QueryReturnEmptyCollection()
        {
            // arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlUserRepository(cxn.Object, cxn.Object);

            int[] userIds        = { };
            var   operationScope = new OperationScope
            {
                Ids       = userIds,
                SelectAll = false
            };

            var userIdTable   = SqlConnectionWrapper.ToDataTable(operationScope.Ids);
            var returntResult = new List <int>();

            cxn.SetupQueryAsync("DeleteUsers",
                                new Dictionary <string, object>
            {
                { "UserIds", userIdTable },
                { "Search", "" },
                { "SessionUserId", 0 },
                { "SelectAll", operationScope.SelectAll }
            },
                                returntResult);

            // act
            var result = await repository.DeleteUsersAsync(operationScope, string.Empty, 0, null);

            // assert
            cxn.Verify();
            Assert.AreEqual(result.Count, returntResult.Count);
        }
Пример #13
0
        public async Task ValidadeUserPasswordForHistoryAsync_Invalid_False()
        {
            // Arrange
            var          cxn             = new SqlConnectionWrapperMock();
            var          repository      = new SqlUserRepository(cxn.Object, cxn.Object);
            const int    userId          = 99;
            var          userSalt        = new Guid();
            const string newPassword     = "******";
            var          passwordHystory = new List <SqlUserRepository.HashedPassword>
            {
                new SqlUserRepository.HashedPassword {
                    Password = HashingUtilities.GenerateSaltedHash(newPassword, userSalt), UserSALT = userSalt
                }
            };

            cxn.SetupQueryAsync(
                "GetLastUserPasswords",
                new Dictionary <string, object>
            {
                { "@userId", userId }
            },
                passwordHystory);

            // Act
            var result = await repository.ValidateUserPasswordForHistoryAsync(userId, newPassword);

            // Assert
            cxn.Verify();
            Assert.AreEqual(false, result);
        }
Пример #14
0
        public async Task ValidadeUserPasswordForHistoryAsync_Valid_True()
        {
            // Arrange
            var          cxn             = new SqlConnectionWrapperMock();
            var          repository      = new SqlUserRepository(cxn.Object, cxn.Object);
            const int    userId          = 99;
            const string newPassword     = "******";
            var          passwordHystory = new List <SqlUserRepository.HashedPassword>
            {
                new SqlUserRepository.HashedPassword {
                    Password = "******", UserSALT = new Guid()
                }
            };

            cxn.SetupQueryAsync(
                "GetLastUserPasswords",
                new Dictionary <string, object>
            {
                { "@userId", userId }
            },
                passwordHystory);

            // Act
            var result = await repository.ValidateUserPasswordForHistoryAsync(userId, newPassword);

            // Assert
            cxn.Verify();
            Assert.AreEqual(true, result);
        }
Пример #15
0
        public async Task GetLicenseTransactionUserInfoAsync_QueryReturnsUsers_ReturnsUsers()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlUserRepository(cxn.Object, cxn.Object);

            int[] userIds     = { 1, 2, 3 };
            var   userIdTable = SqlConnectionWrapper.ToDataTable(userIds);

            LicenseTransactionUser[] result =
            {
                new LicenseTransactionUser {
                    Id = 1, Login = "******", Department = "Dept"
                },
                new LicenseTransactionUser {
                    Id = 2, Login = "******", Department = null
                },
                new LicenseTransactionUser {
                    Id = 3, Login = "******", Department = "Another Dept"
                }
            };
            cxn.SetupQueryAsync("GetLicenseTransactionUser", new Dictionary <string, object> {
                { "UserIds", userIdTable }
            }, result);

            // Act
            IEnumerable <LicenseTransactionUser> users = await repository.GetLicenseTransactionUserInfoAsync(userIds);

            // Assert
            cxn.Verify();
            CollectionAssert.AreEquivalent(result, users.ToList());
        }
Пример #16
0
        public async Task GetLicenseTransactions_QueryReturnsValue_ReturnsValue()
        {
            // Arrange
            DateTime  startTime    = new DateTime(2000, 1, 1);
            const int consumerType = 2;
            var       cxn          = new SqlConnectionWrapperMock();
            var       repository   = new SqlLicensesRepository(cxn.Object);
            var       transactions = new[]
            {
                new LicenseTransaction {
                    LicenseActivityId = 1, UserId = 1, LicenseType = 1, TransactionType = 1, ActionType = 1, ConsumerType = 2
                },
                new LicenseTransaction {
                    LicenseActivityId = 2, UserId = 2, LicenseType = 3, TransactionType = 1, ActionType = 1, ConsumerType = 2
                },
                new LicenseTransaction {
                    LicenseActivityId = 3, UserId = 1, LicenseType = 1, TransactionType = 2, ActionType = 2, ConsumerType = 2
                },
            };

            cxn.SetupQueryAsync("[AdminStore].GetLicenseTransactions", new Dictionary <string, object> {
                { "StartTime", startTime }, { "ConsumerType", consumerType }
            }, transactions);

            // Act
            IEnumerable <LicenseTransaction> result = await repository.GetLicenseTransactions(startTime, consumerType);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result, transactions);
        }
Пример #17
0
        public async Task GetActiveLicenses_QueryReturnsValue_ReturnsValue()
        {
            // Arrange
            DateTime  now = new DateTime(2000, 1, 1);
            const int licenseLockTimeMinutes = 1440;
            var       cxn        = new SqlConnectionWrapperMock();
            var       repository = new SqlLicensesRepository(cxn.Object);
            var       licenses   = new[]
            {
                new LicenseInfo {
                    LicenseLevel = 1, Count = 1
                },
                new LicenseInfo {
                    LicenseLevel = 3, Count = 2
                }
            };

            cxn.SetupQueryAsync("[AdminStore].GetActiveLicenses", new Dictionary <string, object> {
                { "Now", now }, { "LicenseLockTimeMinutes", licenseLockTimeMinutes }
            }, licenses);

            // Act
            IEnumerable <LicenseInfo> result = await repository.GetActiveLicenses(now, 1440);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result, licenses);
        }
Пример #18
0
        public async Task GetHeadFile_QueryReturnsFile_ReturnsFirst()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid       = new Guid("99999999999999999999999999999999");

            File[] result = { new File {
                                  FileName = "name", FileType = "type"
                              } };
            cxn.SetupQueryAsync(
                "[FileStore].ReadFileHead",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                result);

            // Act
            File file = await repository.GetFileHead(guid);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.First(), file);
        }
        public async Task BeginSession_QueryReturnsNewSessionOnly_ReturnsNewSessionAndNull()
        {
            // Arrange
            var    cxn          = new SqlConnectionWrapperMock();
            var    repository   = new SqlSessionsRepository(cxn.Object);
            int    userId       = 123;
            string userName     = "******";
            int    licenseLevel = 3;
            Guid   newSessionId = new Guid("12345678901234567890123456789012");

            Session[] result = { new Session {
                                     SessionId = newSessionId
                                 } };
            cxn.SetupQueryAsync(
                "[AdminStore].BeginSession",
                new Dictionary <string, object> {
                { "UserId", userId }, { "UserName", userName }, { "LicenseLevel", licenseLevel }, { "IsSso", true }, { "LicenseLockTimeMinutes", WebApiConfig.LicenseHoldTime }, { "OldSessionId", null }
            },
                result,
                new Dictionary <string, object> {
                { "OldSessionId", null }
            });

            // Act
            Guid?   resultId = null;
            Session session  = await repository.BeginSession(userId, userName, licenseLevel, true, id => resultId = id);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result[0], session);
            Assert.IsNull(resultId);
        }
        public async Task GetSettings_QueryReturnsResults_ReturnsResults()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlConfigRepository(cxn.Object);

            ConfigSetting[] result =
            {
                new ConfigSetting {
                    Group = "group", IsRestricted = false, Key = "key", Value = "value"
                },
                new ConfigSetting {
                    Group = "group", IsRestricted = true, Key = "key2", Value = "value2"
                }
            };
            cxn.SetupQueryAsync(
                "[AdminStore].GetConfigSettings",
                new Dictionary <string, object> {
                { "AllowRestricted", true }
            },
                result);

            // Act
            IEnumerable <ConfigSetting> settings = await repository.GetSettings(true);

            // Assert
            cxn.Verify();
            CollectionAssert.AreEquivalent(result, settings.ToList());
        }
        public async Task SelectSessions_SessionExistss_ReturnsAll()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            int ps         = 100;
            int pn         = 1;

            Session[] result =
            {
                new Session {
                    SessionId = new Guid("12345678901234567890123456789012")
                },
                new Session {
                    SessionId = new Guid("11111111111111111111111111111111")
                }
            };
            cxn.SetupQueryAsync("[AdminStore].SelectSessions", new Dictionary <string, object> {
                { "ps", ps }, { "pn", pn }
            }, result);

            // Act
            IEnumerable <Session> sessions = await repository.SelectSessions(ps, pn);

            // Assert
            cxn.Verify();
            CollectionAssert.AreEquivalent(result, sessions.ToList());
        }
Пример #22
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);
        }
Пример #23
0
        private static IItemSearchRepository CreateItemNameRepository <T>(
            ItemNameSearchCriteria searchCriteria,
            ICollection <T> queryResult,
            IArtifactPermissionsRepository artifactPermissionsRepository,
            IArtifactRepository artifactRepository)
        {
            var connectionWrapper = new SqlConnectionWrapperMock();
            var parameters        = new Dictionary <string, object>
            {
                { "userId", UserId },
                { "query", searchCriteria.Query },
                { "projectIds", SqlConnectionWrapper.ToDataTable(searchCriteria.ProjectIds) },
                { "maxSearchableValueStringSize", MaxSearchableValueStringSize },
                { "startOffset", StartOffset },
                { "pageSize", PageSize },
                { "excludedPredefineds", SqlConnectionWrapper.ToDataTable(SqlItemSearchRepository.GetExcludedPredefineds(searchCriteria)) }
            };

            if (searchCriteria.PredefinedTypeIds != null)
            {
                parameters.Add("predefinedTypeIds", SqlConnectionWrapper.ToDataTable(searchCriteria.PredefinedTypeIds));
            }

            connectionWrapper.SetupQueryAsync(
                "SearchItemNameByItemTypes",
                parameters,
                queryResult);

            var configuration = new Mock <ISearchConfiguration>();

            configuration.Setup(c => c.MaxItems).Returns(MaxItems.ToStringInvariant());
            configuration.Setup(c => c.MaxSearchableValueStringSize).Returns(MaxSearchableValueStringSize.ToStringInvariant());

            return(new SqlItemSearchRepository(connectionWrapper.Object, configuration.Object, artifactPermissionsRepository, artifactRepository));
        }
Пример #24
0
        public async Task GetAttachmentsAndDocumentReferences_SubArtifactDontAddDrafts_ResultsReturned()
        {
            // Arrange
            int  artifactId    = 1;
            int  userId        = 1;
            int? subArtifactId = 2;
            bool addDrafts     = false;

            var cxn = new SqlConnectionWrapperMock();

            cxn.SetupQueryAsync("GetItemAttachments", new Dictionary <string, object> {
                { "itemId", subArtifactId }, { "userId", userId }, { "addDrafts", addDrafts }
            }, new List <Attachment> {
                new Attachment {
                    FileName = "Test File Name", FileGuid = new System.Guid()
                }
            });
            cxn.SetupQueryAsync("GetDocumentReferenceArtifacts", new Dictionary <string, object> {
                { "itemId", subArtifactId }, { "userId", userId }, { "addDrafts", addDrafts }
            }, new List <DocumentReference> {
                new DocumentReference {
                    UserId = userId, ArtifactId = artifactId
                }
            });
            cxn.SetupQueryAsync("GetDocumentArtifactInfos", new Dictionary <string, object> {
                { "artifactIds", SqlConnectionWrapper.ToDataTable(new List <int> {
                        artifactId
                    }, "Int32Collection", "Int32Value") }, { "userId", userId }, { "addDrafts", addDrafts }
            }, new List <LinkedArtifactInfo> {
                new LinkedArtifactInfo {
                    ArtifactId = artifactId, ArtifactName = "Test Document Name"
                }
            });
            var repository = new SqlAttachmentsRepository(cxn.Object, mockUserRepository);

            // Act
            var result = await repository.GetAttachmentsAndDocumentReferences(artifactId, userId, null, subArtifactId, addDrafts);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.ArtifactId, 1);
            Assert.AreEqual(result.SubartifactId, subArtifactId);
            Assert.AreEqual(result.Attachments.Count, 1);
            Assert.AreEqual(result.DocumentReferences.Count, 1);
        }
Пример #25
0
        private static IJobsRepository CreateJobsRepository(params DJobMessage[] jobMessages)
        {
            var connection = new SqlConnectionWrapperMock();

            connection.SetupQueryAsync("GetJobMessage", new Dictionary <string, object>(), jobMessages);
            var artifactsMock   = new Mock <IArtifactRepository>();
            var permissionsMock = new Mock <IArtifactPermissionsRepository>();
            var usersMock       = new Mock <IUsersRepository>();

            var jobsRepository = new JobsRepository(connection.Object, artifactsMock.Object, permissionsMock.Object, usersMock.Object);

            return(jobsRepository);
        }
Пример #26
0
        public async Task GetProjectGroupsAsync_GroupsFound_NoErrors()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlGroupRepository(cxn.Object);
            var projectId  = 100;
            int errorCode  = 0;

            Group[] projectGroups =
            {
                new Group()
                {
                    Name = "Group1"
                },
                new Group()
                {
                    Name = "Group2"
                },
                new Group()
                {
                    Name = "Group3"
                }
            };

            var tabularData = new TabularData
            {
                Pagination = new Pagination {
                    Limit = 10, Offset = 0
                },
                Sorting = new Sorting {
                    Order = SortOrder.Asc, Sort = "name"
                }
            };

            cxn.SetupQueryAsync("GetAvailableGroupsForProject",
                                new Dictionary <string, object> {
                { "projectId", projectId }
            },
                                projectGroups,
                                new Dictionary <string, object> {
                { "ErrorCode", errorCode }
            });

            // Act
            await repository.GetProjectGroupsAsync(projectId, tabularData, SortingHelper.SortProjectGroups);

            // Assert
            cxn.Verify();
        }
        public async Task GetInstanceSettingsAsync_QueryReturnsEmpty_ThrowsException()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);

            InstanceSettings[] result = { };
            cxn.SetupQueryAsync("GetInstanceSettings", null, result);

            // Act
            await repository.GetInstanceSettingsAsync();

            // Assert
            cxn.Verify();
        }
        public async Task GetFederatedAuthentication_QueryReturnsEmpty_ReturnsNull()
        {
            // Arrange
            var     cxn        = new SqlConnectionWrapperMock();
            var     repository = new SqlSettingsRepository(cxn.Object);
            dynamic result     = new dynamic[] { };

            cxn.SetupQueryAsync("GetFederatedAuthentications", null, result);

            // Act
            var settings = await repository.GetFederatedAuthenticationSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.AreEqual(null, settings);
        }
Пример #29
0
        public async Task GetStandardArtifactTypes_AllRequirementsAreSatisfied_SuccessResult()
        {
            // Arrange
            var artifacts = new List <StandardArtifactType> {
                new StandardArtifactType {
                    Id = 1, Name = "CustomActor"
                }
            };

            cxn.SetupQueryAsync("GetStandardArtifactTypes", It.IsAny <Dictionary <string, object> >(), artifacts);

            // Act
            var standardArtifacts = await repository.GetStandardArtifactTypes(StandardArtifactTypes.All);

            // Assert
            Assert.IsNotNull(standardArtifacts);
            Assert.AreEqual(standardArtifacts.Count(), 1);
        }
        public async Task GetInstanceSettingsAsync_QueryReturnsSettings_ReturnsFirst()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);

            InstanceSettings[] result = { new InstanceSettings {
                                              UseDefaultConnection = true
                                          } };
            cxn.SetupQueryAsync("GetInstanceSettings", null, result);

            // Act
            InstanceSettings settings = await repository.GetInstanceSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.First(), settings);
        }