DeleteDocuments() public method

public DeleteDocuments ( System.Guid ids ) : void
ids System.Guid
return void
コード例 #1
0
        public void Should_Delete_DocumentFromindex()
        {
            var document1 = new HtmlDocument();
            document1.DocumentNode.AppendChild(HtmlNode.CreateNode("<title>Deleted document title</title>"));
            document1.DocumentNode.AppendChild(HtmlNode.CreateNode("<body>text which will be deleted</body>"));

            var page1 = new PageData { AbsolutePath = "/test-delete-1", Content = document1, Id = Guid.NewGuid(), IsPublished = true };
            var page2 = new PageData { AbsolutePath = "/test-delete-2", Content = document1, Id = Guid.NewGuid(), IsPublished = true };
            var page3 = new PageData { AbsolutePath = "/test-delete-3", Content = document1, Id = Guid.NewGuid(), IsPublished = true };

            var service = new DefaultIndexerService(Container.Resolve<ICmsConfiguration>(), Container.Resolve<IRepository>(),
                Container.Resolve<ISecurityService>(), Container.Resolve<IAccessControlService>());

            if (service.OpenWriter())
            {
                service.AddHtmlDocument(page1);
                service.AddHtmlDocument(page2);
                service.AddHtmlDocument(page3);
                service.CloseWriter();
            }

            // Search result should return 3 objects
            var results = service.Search(new SearchRequest("deleted"));

            Assert.IsNotNull(results.Items);
            Assert.AreEqual(results.Items.Count, 3, "Should return 3 items.");

            // Delete 2 objects
            if (service.OpenWriter())
            {
                service.DeleteDocuments(new[] { page1.Id, page2.Id });
                service.CloseWriter();
            }

            // Search result should return 1 object
            results = service.Search(new SearchRequest("deleted"));

            Assert.IsNotNull(results.Items);
            Assert.AreEqual(results.Items.Count, 1, "Should return one item.");
            Assert.AreEqual(results.Items[0].Link, page3.AbsolutePath);
        }