public void TestUpdatePageImages() { var unitOfWorkProvider = CreateMockUnitOfWorkProvider(); var resourceRepository = new MockResourceRepository(unitOfWorkProvider); var bookData = new BookData { Pages = new List <BookPageData> { new BookPageData { Text = "39v", Image = "image_39v.jpg" }, new BookPageData { Text = "40r", Image = "image_40r.jpg" } }, FileNameMapping = new Dictionary <string, FileResource> { { "image_39v.jpg", new FileResource { NewNameInStorage = "guid-39v" } }, { "image_40r.jpg", new FileResource { NewNameInStorage = "guid-40r" } }, } }; var subtask = new UpdatePagesSubtask(resourceRepository); subtask.UpdatePages(41, 3, 2, bookData, GetTestTermCache()); var createdImages = resourceRepository.CreatedObjects.OfType <ImageResource>().ToList(); var updatedImages = resourceRepository.UpdatedObjects.OfType <ImageResource>().ToList(); var updatedResources = resourceRepository.UpdatedObjects.OfType <Resource>().ToList(); Assert.AreEqual(2, createdImages.Count); Assert.AreEqual(0, updatedImages.Count); Assert.AreEqual(1, updatedResources.Count); var firstImage = createdImages.First(x => x.FileName == "image_39v.jpg"); var secondImage = createdImages.First(x => x.FileName == "image_40r.jpg"); Assert.AreEqual(1, firstImage.VersionNumber); Assert.AreEqual(2, secondImage.VersionNumber); Assert.AreEqual(900, secondImage.Resource.Id); Assert.IsNotNull(firstImage.FileId); Assert.IsNotNull(firstImage.FileId); Assert.IsTrue(updatedResources[0].IsRemoved); }
public void TestUpdatePages() { var unitOfWorkProvider = CreateMockUnitOfWorkProvider(); var resourceRepository = new MockResourceRepository(unitOfWorkProvider); var bookData = new BookData { Pages = new List <BookPageData> { new BookPageData { Position = 1, Text = "39v", }, new BookPageData { Position = 2, Text = "40r", TermXmlIds = new List <string> { "id-2", "id-1" } } } }; var subtask = new UpdatePagesSubtask(resourceRepository); subtask.UpdatePages(40, 3, 1, bookData, GetTestTermCache()); Assert.AreEqual(2, resourceRepository.CreatedObjects.Count); Assert.AreEqual(1, resourceRepository.UpdatedObjects.Count); var firstPage = resourceRepository.CreatedObjects.Cast <PageResource>().First(x => x.Name == "39v"); var secondPage = resourceRepository.CreatedObjects.Cast <PageResource>().First(x => x.Name == "40r"); var removedResourcePage = resourceRepository.UpdatedObjects.Cast <Resource>().First(); Assert.AreEqual(1, firstPage.Position); Assert.AreEqual(2, secondPage.Position); Assert.IsTrue(removedResourcePage.IsRemoved); // Test term assignment Assert.IsNull(firstPage.Terms); Assert.AreEqual(2, secondPage.Terms.Count); }
public void TestUpdatePageTexts() { var unitOfWorkProvider = CreateMockUnitOfWorkProvider(); var resourceRepository = new MockResourceRepository(unitOfWorkProvider); var bookData = new BookData { Pages = new List <BookPageData> { new BookPageData { Text = "39v", XmlId = "xml-39-v" }, new BookPageData { Text = "40r", XmlId = "xml-40-r" } } }; var subtask = new UpdatePagesSubtask(resourceRepository); subtask.UpdatePages(40, 3, 1, bookData, GetTestTermCache()); var createdTexts = resourceRepository.CreatedObjects.OfType <TextResource>().ToList(); var updatedTexts = resourceRepository.UpdatedObjects.OfType <TextResource>().ToList(); var updatedResources = resourceRepository.UpdatedObjects.OfType <Resource>().ToList(); Assert.AreEqual(2, createdTexts.Count); Assert.AreEqual(0, updatedTexts.Count); Assert.AreEqual(1, updatedResources.Count); var firstText = createdTexts.First(x => x.ExternalId == "xml-39-v"); var secondText = createdTexts.First(x => x.ExternalId == "xml-40-r"); Assert.AreEqual(1, firstText.VersionNumber); Assert.AreEqual(2, secondText.VersionNumber); Assert.AreEqual(900, secondText.Resource.Id); Assert.IsTrue(updatedResources[0].IsRemoved); }
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); }