Exemplo n.º 1
0
        public async Task FullTextMetaData_WithoutItemTypesThrowsSqlException_SqlExceptionReThrown()
        {
            // Arrange
            var searchCriteria = new FullTextSearchCriteria
            {
                Query      = "test",
                ProjectIds = new[] { 1 }
            };

            var sqlException         = SqlExceptionCreator.NewSqlException(-2146232060);
            var itemSearchRepository = CreateFullTextSearchRepositoryWithException <MetaDataSearchResult>(sqlException);

            SqlException thrownException = null;

            // Act
            try
            {
                await itemSearchRepository.FullTextMetaData(UserId, searchCriteria);
            }
            catch (SqlException exception)
            {
                thrownException = exception;
            }

            // Assert
            Assert.IsNotNull(thrownException, "sqlException != null");
            Assert.IsTrue(thrownException.ErrorCode == -2146232060, "Timeout exception should occur");
        }
        public async Task SearchName_WithSqlException_SqlExceptionOccurs()
        {
            // Arrange
            const int userId         = 1;
            var       searchCriteria = new SearchCriteria {
                Query = "test"
            };
            const int    resultCount             = 1;
            const string separatorString         = "/";
            Exception    expectedException       = SqlExceptionCreator.NewSqlException(-4);
            var          projectSearchRepository = CreateRepositoryWithExceptionExpectation <ProjectSearchResult>(expectedException);
            SqlException sqlException            = null;

            // Act
            try
            {
                await projectSearchRepository.SearchName(userId, searchCriteria, resultCount, separatorString);
            }
            catch (SqlException exception)
            {
                sqlException = exception;
            }

            // Assert
            Assert.IsNotNull(sqlException, "sqlException != null");
            Assert.IsTrue(sqlException.Number == -4, "exception should occur");
        }
Exemplo n.º 3
0
        public async Task SearchName_WithPredefinedTypeIdsWithSqlException_SqlExceptionOccurs()
        {
            // Arrange
            var searchCriteria = new ItemNameSearchCriteria
            {
                Query             = "test",
                ProjectIds        = new[] { 1 },
                PredefinedTypeIds = new[] { 4104 }
            };

            var permissionsDictionary = new Dictionary <int, RolePermissions> {
                { 0, RolePermissions.Read }
            };
            var mockArtifactPermissionsRepository = new Mock <IArtifactPermissionsRepository>();

            mockArtifactPermissionsRepository.Setup(r => r.GetArtifactPermissions(new List <int> {
                0
            }, UserId, false, int.MaxValue, true, null)).ReturnsAsync(permissionsDictionary);

            Exception sqlException = SqlExceptionCreator.NewSqlException(-4);

            var itemSearchRepository = CreateItemNameRepositoryWithExceptionExpectation <ItemNameSearchResult>(mockArtifactPermissionsRepository.Object, null, sqlException);

            SqlException actualSqlException = null;

            // Act
            try
            {
                await itemSearchRepository.SearchName(UserId, searchCriteria, StartOffset, PageSize);
            }
            catch (SqlException exception)
            {
                actualSqlException = exception;
            }

            // Assert
            Assert.IsNotNull(actualSqlException, "sqlException != null");
            Assert.IsTrue(actualSqlException.Number == -4, "Timeout exception should occur");
        }