public void TestUpdateHeadwordsWithImages() { var unitOfWorkProvider = CreateMockUnitOfWorkProvider(); var resourceRepository = new MockResourceRepository(unitOfWorkProvider); var headwordDataList = new List <BookHeadwordData> { new BookHeadwordData { XmlEntryId = "null", DefaultHeadword = "aaa", SortOrder = "aaa-s", Headword = "aaa1", Image = "img1.jpg" }, new BookHeadwordData { XmlEntryId = "null", DefaultHeadword = "aaa", SortOrder = "aaa-s", Headword = "aaa2", Image = "img2.jpg" }, }; var pageDataList = new List <BookPageData> { new BookPageData { Position = 1, Text = "page1", XmlId = "id-1" }, new BookPageData { Position = 2, Text = "page2", XmlId = "id-2", Image = "img1.jpg" }, new BookPageData { Position = 3, Text = "page3", XmlId = "id-3", Image = "img2.jpg" }, new BookPageData { Position = 4, Text = "page4", XmlId = "id-4", Image = "img3.jpg" }, }; var bookData = new BookData { BookHeadwords = headwordDataList, Pages = pageDataList }; var dbPages = pageDataList.Select(x => new PageResource { Name = x.Text, Position = x.Position, Resource = new Resource { Name = x.Text } }).ToList(); var subtask = new UpdateHeadwordsSubtask(resourceRepository); subtask.UpdateHeadwords(41, MockResourceRepository.HeadwordBookVersionId, 2, bookData, dbPages); var createdHeadwordItems = resourceRepository.CreatedObjects.OfType <HeadwordItem>().ToList(); Assert.AreEqual(2, createdHeadwordItems.Count); var hw1 = createdHeadwordItems.First(x => x.Headword == "aaa1"); var hw2 = createdHeadwordItems.First(x => x.Headword == "aaa2"); Assert.AreEqual("page2", hw1.ResourcePage.Name); Assert.AreEqual("page3", hw2.ResourcePage.Name); }
protected override void ExecuteWorkImplementation() { m_projectId = m_nullableProjectId ?? throw new InvalidOperationException("Required ProjectId wasn't set in ResourceSessionDirector"); // Updating Project data is not required, because data has been already updated m_importedResourceVersionIds = new List <long>(); m_bookVersionId = new UpdateBookVersionSubtask(m_resourceRepository).UpdateBookVersion(m_projectId, m_userId, m_bookData); var updateEditionNoteSubtask = new UpdateEditionNoteSubtask(m_resourceRepository); var editionNoteVersionId = updateEditionNoteSubtask.UpdateEditionNote(m_projectId, m_bookVersionId, m_userId, m_bookData); if (editionNoteVersionId != null) { m_importedResourceVersionIds.Add(editionNoteVersionId.Value); } //TODO update: transformations new UpdateAuthorsSubtask(m_projectRepository, m_personRepository).UpdateAuthors(m_projectId, m_bookData); new UpdateResponsiblePersonSubtask(m_projectRepository, m_personRepository).UpdateResponsiblePersonList(m_projectId, m_bookData); var updateMetadataSubtask = new UpdateMetadataSubtask(m_metadataRepository); updateMetadataSubtask.UpdateMetadata(m_projectId, m_userId, m_bookData); // Categories are not updated from import (XMD doesn't contain detailed categorization) //new UpdateCategoriesSubtask(m_categoryRepository).UpdateCategoryList(m_projectId, m_bookData); new UpdateLiteraryKindsSubtask(m_catalogValueRepository, m_metadataRepository).UpdateLiteraryKinds(m_projectId, m_bookData); new UpdateLiteraryGenresSubtask(m_catalogValueRepository, m_metadataRepository).UpdateLiteraryGenres(m_projectId, m_bookData); new UpdateLiteraryOriginalsSubtask(m_catalogValueRepository, m_metadataRepository).UpdateLiteraryOriginals(m_projectId, m_bookData); new UpdateKeywordsSubtask(m_projectRepository, m_catalogValueRepository).UpdateKeywords(m_projectId, m_bookData); var updateTermsSubtask = new UpdateTermsSubtask(m_resourceRepository); updateTermsSubtask.UpdateTerms(m_projectId, m_bookData); var updatePagesSubtask = new UpdatePagesSubtask(m_resourceRepository); updatePagesSubtask.UpdatePages(m_projectId, m_bookVersionId, m_userId, m_bookData, updateTermsSubtask.ResultTermCache); m_importedResourceVersionIds.AddRange(updatePagesSubtask.ImportedResourceVersionIds); var updateChaptersSubtask = new UpdateChaptersSubtask(m_resourceRepository); updateChaptersSubtask.UpdateChapters(m_projectId, m_userId, m_bookData, updatePagesSubtask.ResultPageResourceList); m_importedResourceVersionIds.AddRange(updateChaptersSubtask.ImportedResourceVersionIds); var updateHeadwordsSubtask = new UpdateHeadwordsSubtask(m_resourceRepository); updateHeadwordsSubtask.UpdateHeadwords(m_projectId, m_bookVersionId, m_userId, m_bookData, updatePagesSubtask.ResultPageResourceList); m_importedResourceVersionIds.AddRange(updateHeadwordsSubtask.ImportedResourceVersionIds); var updateTracksSubtask = new UpdateTracksSubtask(m_resourceRepository); updateTracksSubtask.UpdateTracks(m_projectId, m_userId, m_bookData); updateTracksSubtask.UpdateFullBookTracks(m_projectId, m_userId, m_bookData); m_importedResourceVersionIds.AddRange(updateTracksSubtask.ImportedResourceVersionIds); new UpdateHistoryLogSubtask(m_projectRepository).UpdateHistoryLog(m_projectId, m_userId, m_message, m_bookData); }
public void TestUpdateHeadwords() { var unitOfWorkProvider = CreateMockUnitOfWorkProvider(); var resourceRepository = new MockResourceRepository(unitOfWorkProvider); var headwordDataList = new List <BookHeadwordData> { new BookHeadwordData // not exists in DB { XmlEntryId = "null", DefaultHeadword = "aaa", SortOrder = "aaa-s", Headword = "aaa", HeadwordOriginal = "aaa-o" }, new BookHeadwordData // same data in DB { XmlEntryId = "id-1", DefaultHeadword = "aaa", SortOrder = "aaa-s", Headword = "aaa", HeadwordOriginal = "aaa-o" }, new BookHeadwordData { XmlEntryId = "id-1", DefaultHeadword = "aaa", SortOrder = "aaa-s", Headword = "bbb", HeadwordOriginal = "bbb-o" }, new BookHeadwordData // HeadwordItem is different { XmlEntryId = "id-2", DefaultHeadword = "ccc", SortOrder = "ccc-s", Headword = "aaa", HeadwordOriginal = "aaa-o" }, new BookHeadwordData { XmlEntryId = "id-2", DefaultHeadword = "ccc", SortOrder = "ccc-s", Headword = "bbb-different", HeadwordOriginal = "bbb-o" }, }; var bookData = new BookData { BookHeadwords = headwordDataList }; var subtask = new UpdateHeadwordsSubtask(resourceRepository); subtask.UpdateHeadwords(41, MockResourceRepository.HeadwordBookVersionId, 2, bookData, null); var createdHeadwordResources = resourceRepository.CreatedObjects.OfType <HeadwordResource>().ToList(); var createdHeadwordItems = resourceRepository.CreatedObjects.OfType <HeadwordItem>().ToList(); var updatedResources = resourceRepository.UpdatedObjects.OfType <Resource>().ToList(); Assert.AreEqual(0, resourceRepository.UpdatedObjects.Count - updatedResources.Count); // No updates except the removed resources Assert.AreEqual(2, createdHeadwordResources.Count); Assert.AreEqual(3, createdHeadwordItems.Count); Assert.AreEqual(1, updatedResources.Count); Assert.IsTrue(updatedResources[0].IsRemoved); var newHeadword = createdHeadwordResources.First(x => x.ExternalId == "null"); var updatedHeadword = createdHeadwordResources.First(x => x.ExternalId == "id-2"); Assert.AreEqual(1, newHeadword.VersionNumber); Assert.AreEqual(2, updatedHeadword.VersionNumber); }