diff --git a/src/Arkivverket.Arkade.Test/Arkivverket.Arkade.Test.csproj b/src/Arkivverket.Arkade.Test/Arkivverket.Arkade.Test.csproj index e31274d51..dc4857750 100644 --- a/src/Arkivverket.Arkade.Test/Arkivverket.Arkade.Test.csproj +++ b/src/Arkivverket.Arkade.Test/Arkivverket.Arkade.Test.csproj @@ -181,6 +181,7 @@ + @@ -344,7 +345,10 @@ Always - + + Always + + Always @@ -353,10 +357,10 @@ Always - + Always - + Always @@ -581,6 +585,7 @@ + diff --git a/src/Arkivverket.Arkade.Test/Core/DocumentsDirectoryTest.cs b/src/Arkivverket.Arkade.Test/Core/DocumentsDirectoryTest.cs new file mode 100644 index 000000000..cfc952c31 --- /dev/null +++ b/src/Arkivverket.Arkade.Test/Core/DocumentsDirectoryTest.cs @@ -0,0 +1,108 @@ +using System; +using System.IO; +using Arkivverket.Arkade.Core; +using FluentAssertions; +using Xunit; + +namespace Arkivverket.Arkade.Test.Core +{ + public class DocumentsDirectoryTest + { + private static DirectoryInfo _physicalWorkingDirectory; + + public DocumentsDirectoryTest() + { + _physicalWorkingDirectory = new DirectoryInfo( + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "DocumentDirectoryTest") + ); + + if (!_physicalWorkingDirectory.Exists) + _physicalWorkingDirectory.Create(); + } + + [Fact] + [Trait("Category", "Integration")] + public void ArhiveDetectsDocumentsDirectoriesWithSupportedNames() + { + // Plural, lowercase documents directory name: + DirectoryInfo documentsDirectoryA = SetupArchiveWithPhysicalDocumentsDirectory("dokumenter"); + documentsDirectoryA.Name.Should().Be("dokumenter"); + documentsDirectoryA.Exists.Should().BeTrue(); + + // Plural, uppercase documents directory name: + DirectoryInfo documentsDirectoryB = SetupArchiveWithPhysicalDocumentsDirectory("DOKUMENTER"); + documentsDirectoryB.Name.Should().Be("DOKUMENTER"); + documentsDirectoryB.Exists.Should().BeTrue(); + + // Singular, lowercase documents directory name: + DirectoryInfo documentsDirectoryC = SetupArchiveWithPhysicalDocumentsDirectory("dokument"); + documentsDirectoryC.Name.Should().Be("dokument"); + documentsDirectoryC.Exists.Should().BeTrue(); + + // Singular, uppercase documents directory name: + DirectoryInfo documentsDirectoryD = SetupArchiveWithPhysicalDocumentsDirectory("DOKUMENT"); + documentsDirectoryD.Name.Should().Be("DOKUMENT"); + documentsDirectoryD.Exists.Should().BeTrue(); + } + + [Fact] + [Trait("Category", "Integration")] + public void DocumentsDirectoriesWithUnsupportedNamesResultsInFallback() + { + // Mixed case documents directory name: + DirectoryInfo documentsDirectoryA = SetupArchiveWithPhysicalDocumentsDirectory("Dokumenter"); + documentsDirectoryA.Name.Should().Be("dokumenter"); + + // English documents directory name: + DirectoryInfo documentsDirectoryB = SetupArchiveWithPhysicalDocumentsDirectory("documenter"); + documentsDirectoryB.Name.Should().Be("dokumenter"); + } + + [Fact] + [Trait("Category", "Integration")] + public void MissingDocumentsDirectoryResultsInFallback() + { + // Missing documents directory: + DirectoryInfo documentsDirectoryA = SetupArchiveWithPhysicalDocumentsDirectory(string.Empty); + documentsDirectoryA.Name.Should().Be("dokumenter"); + documentsDirectoryA.Exists.Should().BeFalse(); + } + + private static DirectoryInfo SetupArchiveWithPhysicalDocumentsDirectory(string documentsDirectoryName) + { + // Remove any existing document directories: + RemovePhysicalContentsDirectory(); + + // Make new archive to reset any existing documentsdirectory reference: + Archive archive = SetupArchive(); + + // Create an actual documentsdirectory for the archive to look for: + CreatePhysicalDocumentsDirectory(documentsDirectoryName); + + // Return what the archive has defined as its documentsdirectory: + return archive.GetDocumentsDirectory(); + } + private static void RemovePhysicalContentsDirectory() + { + var contentDirectory = new DirectoryInfo(Path.Combine(_physicalWorkingDirectory.FullName, "content")); + + if (contentDirectory.Exists) + contentDirectory.Delete(true); + } + + private static Archive SetupArchive() + { + return new ArchiveBuilder() + .WithArchiveType(ArchiveType.Noark5) + .WithWorkingDirectoryRoot(_physicalWorkingDirectory.FullName) + .Build(); + } + + private static void CreatePhysicalDocumentsDirectory(string documentsDirectoryName) + { + Directory.CreateDirectory( + Path.Combine(_physicalWorkingDirectory.FullName, "content", documentsDirectoryName) + ); + } + } +} diff --git a/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/dokumenter/5000001.pdf b/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/B.PDF similarity index 100% rename from src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/dokumenter/5000001.pdf rename to src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/B.PDF diff --git a/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/dokumenter/5000000.pdf b/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/a.pdf similarity index 100% rename from src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/dokumenter/5000000.pdf rename to src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/a.pdf diff --git a/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/dokumenter/underkatalog/5000002.pdf b/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/underkatalog/C.pdf similarity index 100% rename from src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/dokumenter/underkatalog/5000002.pdf rename to src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/underkatalog/C.pdf diff --git a/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/underkatalog/d.PDF b/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/underkatalog/d.PDF new file mode 100644 index 000000000..a1abeda36 Binary files /dev/null and b/src/Arkivverket.Arkade.Test/TestData/Noark5/DocumentfilesControl/FilesToBeReferenced/content/DOKUMENT/underkatalog/d.PDF differ diff --git a/src/Arkivverket.Arkade.Test/Tests/Noark5/DocumentfilesReferenceControlTest.cs b/src/Arkivverket.Arkade.Test/Tests/Noark5/DocumentfilesReferenceControlTest.cs index f5b0a4795..eb94bb1a0 100644 --- a/src/Arkivverket.Arkade.Test/Tests/Noark5/DocumentfilesReferenceControlTest.cs +++ b/src/Arkivverket.Arkade.Test/Tests/Noark5/DocumentfilesReferenceControlTest.cs @@ -11,6 +11,13 @@ public class DocumentfilesReferenceControlTest [Fact] public void AllFilesAreReferenced() { + /* + The documents directory does not use the default/fallback name (dokumenter). + One of the references use backslashes in the path. + 2 of the referenced files are located in a documents directory subdirectory. + The referenced files have all combinations of lowercase/uppercase in their filename + extension. + */ + XmlElementHelper xmlElementHelper = new XmlElementHelper().Add("arkiv", new XmlElementHelper().Add("arkivdel", @@ -18,24 +25,30 @@ public void AllFilesAreReferenced() new XmlElementHelper().Add("klasse", new XmlElementHelper().Add("mappe", new XmlElementHelper() - .Add("registrering", new[] {"xsi:type", "journalpost"}, + .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper().Add("dokumentbeskrivelse", new XmlElementHelper().Add("dokumentobjekt", - new XmlElementHelper().Add("referanseDokumentfil", - "dokumenter/5000000.pdf")))) - .Add("registrering", new[] {"xsi:type", "journalpost"}, + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT/a.pdf" + )))) + .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper().Add("dokumentbeskrivelse", new XmlElementHelper().Add("dokumentobjekt", - new XmlElementHelper().Add("referanseDokumentfil", - // Backslashed file reference supported: - "dokumenter\\5000001.pdf")))) + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT\\B.PDF" + )))) .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper().Add("dokumentbeskrivelse", new XmlElementHelper().Add("dokumentobjekt", - new XmlElementHelper().Add("referanseDokumentfil", - // Subdirectory file reference: - "dokumenter/underkatalog/5000002.pdf"))))))))); - + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT/underkatalog/C.pdf" + )))) + .Add("registrering", new[] { "xsi:type", "journalpost" }, + new XmlElementHelper().Add("dokumentbeskrivelse", + new XmlElementHelper().Add("dokumentobjekt", + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT/underkatalog/d.PDF" + ))))))))); TestRun testRun = CreateTestRun(xmlElementHelper); @@ -52,22 +65,30 @@ public void SomeFilesAreNotReferenced() new XmlElementHelper().Add("klasse", new XmlElementHelper().Add("mappe", new XmlElementHelper() - .Add("registrering", new[] {"xsi:type", "journalpost"}, + .Add("registrering", new[] { "xsi:type", "journalpost" }, + new XmlElementHelper().Add("dokumentbeskrivelse", + new XmlElementHelper().Add("dokumentobjekt", + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT/a.pdf" + )))) + .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper().Add("dokumentbeskrivelse", new XmlElementHelper().Add("dokumentobjekt", - new XmlElementHelper().Add("referanseDokumentfil", - "dokumenter/5000000.pdf")))) + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT\\B.PDF" + )))) .Add("registrering", new[] { "xsi:type", "journalpost" }, new XmlElementHelper().Add("dokumentbeskrivelse", new XmlElementHelper().Add("dokumentobjekt", - new XmlElementHelper().Add("referanseDokumentfil", - "dokumenter/underkatalog/5000002.pdf"))))))))); + new XmlElementHelper().Add( + "referanseDokumentfil", "DOKUMENT/underkatalog/C.pdf" + ))))))))); TestRun testRun = CreateTestRun(xmlElementHelper); testRun.Results.Should().Contain(r => r.Message.Equals( - "Ikke-referert fil funnet: dokumenter/5000001.pdf") + "Ikke-referert fil funnet: DOKUMENT/underkatalog/d.PDF") ); testRun.Results.Count.Should().Be(1);