public void SearchController_Delete_Throws_On_Null_Or_Empty_UniqueuKey()
        {
            //Arrange

            //Act, Assert
            var searchDoc = new SearchDocument()
            {
                UniqueKey = null, PortalId = 0, SearchTypeId = 1
            };

            Assert.Throws <ArgumentException>(() => _internalSearchController.DeleteSearchDocument(searchDoc));
        }
        /// <summary>
        /// Deletes all deleted items from the system that are added to deletions table.
        /// </summary>
        internal void DeleteRemovedObjects()
        {
            int      deletedCount = 0;
            DateTime cutoffTime   = SchedulerItem.StartDate.ToUniversalTime();
            IInternalSearchController searchController = InternalSearchController.Instance;
            DataProvider dataProvider = DataProvider.Instance();

            using (System.Data.IDataReader reader = dataProvider.GetSearchDeletedItems(cutoffTime))
            {
                while (reader.Read())
                {
                    // Note: we saved this in the DB as SearchDocumentToDelete but retrieve as the descendant SearchDocument class
                    SearchDocument document = JsonConvert.DeserializeObject <SearchDocument>(reader["document"] as string);
                    searchController.DeleteSearchDocument(document);
                    deletedCount += 1;
                }
                reader.Close();
            }
            AddIdexingResults("Deleted Objects", deletedCount);
            dataProvider.DeleteProcessedSearchDeletedItems(cutoffTime);
        }
Exemple #3
0
        public void SearchController_Add_Then_Delete_ModuleDefinition_WorksAsExpected()
        {
            //Arrange
            const int totalDocs = 10;
            var       now       = DateTime.UtcNow;

            //Act
            for (var i = 1; i <= totalDocs; i++)
            {
                var doc = new SearchDocument
                {
                    ModuleDefId     = i,
                    ModuleId        = 100,
                    SearchTypeId    = ModuleSearchTypeId,
                    PortalId        = PortalId0,
                    UniqueKey       = Guid.NewGuid().ToString(),
                    ModifiedTimeUtc = now,
                };

                _internalSearchController.AddSearchDocument(doc);
            }

            //Assert
            var stats = GetSearchStatistics();

            Assert.AreEqual(totalDocs, stats.TotalActiveDocuments);

            //Act - delete last item
            var searchDoc = new SearchDocument {
                ModuleDefId = totalDocs
            };

            _internalSearchController.DeleteSearchDocument(searchDoc);

            //Assert
            stats = GetSearchStatistics();
            Assert.AreEqual(totalDocs - 1, stats.TotalActiveDocuments);
            Assert.AreEqual(1, stats.TotalDeletedDocuments);

            //Act - delete first item
            searchDoc = new SearchDocument {
                ModuleDefId = 1
            };
            _internalSearchController.DeleteSearchDocument(searchDoc);

            //Assert
            stats = GetSearchStatistics();
            Assert.AreEqual(totalDocs - 2, stats.TotalActiveDocuments);
            Assert.AreEqual(2, stats.TotalDeletedDocuments);
        }