Example #1
0
        public void ExtractAndIdentifyTarFiles()
        {
            var    uuid = Uuid.Of("c3db9d4e-720c-4f75-bfb6-de90231dc44c");
            string pathToExtractedFilesRegex = ArkadeConstants.GetArkadeWorkDirectory().FullName +
                                               Path.DirectorySeparatorChar + "..............-" + uuid +
                                               Path.DirectorySeparatorChar + uuid;

            pathToExtractedFilesRegex = pathToExtractedFilesRegex.Replace("\\", "\\\\");

            var extractorMock = new Mock <ICompressionUtility>();

            extractorMock.Setup(e => e.ExtractFolderFromArchive(It.IsAny <FileInfo>(), It.IsAny <DirectoryInfo>()));

            var archiveType    = ArchiveType.Noark5;
            var identifierMock = new Mock <IArchiveIdentifier>();

            identifierMock.Setup(i => i.Identify(It.IsAny <string>())).Returns(archiveType);

            var statusEventHandler = new StatusEventHandler();

            string      file        = TestUtil.TestDataDirectory + Path.DirectorySeparatorChar + "tar" + Path.DirectorySeparatorChar + "Noark3-eksempel-1" + Path.DirectorySeparatorChar + uuid + ".tar";
            TestSession testSession =
                new TestSessionFactory(extractorMock.Object, statusEventHandler)
                .NewSession(ArchiveFile.Read(file, archiveType));

            var archive = testSession.Archive;

            archive.Should().NotBeNull();
            archive.Uuid.Should().Be(uuid);
            archive.WorkingDirectory.Root().DirectoryInfo().FullName.Should().MatchRegex(pathToExtractedFilesRegex);
            archive.ArchiveType.Should().Be(archiveType);

            System.IO.Directory.Delete(archive.WorkingDirectory.Root().DirectoryInfo().FullName, true);
        }
Example #2
0
        private FlatFile GetDokDat()
        {
            var       workingDirectory = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\noark3\\"));
            AddmlInfo addml            = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);

            AddmlDefinition addmlDefinition = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler()).GetAddmlDefinition();
            FlatFile        flatFile        = addmlDefinition.GetFlatFiles().Single(file => file.Definition.FileName == "DOK.DAT");

            return(flatFile);
        }
Example #3
0
        /// <summary>
        /// Initializes a new working directory for this archive using the uuid and timestamp as the identifier. An empty folder structure is created on disk.
        /// </summary>
        /// <param name="uuid">the archive uuid</param>
        /// <param name="externalContentDirectory">optional external content directory</param>
        /// <returns></returns>
        internal static WorkingDirectory FromUuid(Uuid uuid, DirectoryInfo externalContentDirectory)
        {
            string dateString    = DateTime.Now.ToString("yyyyMMddHHmmss");
            var    rootDirectory = new DirectoryInfo(
                ArkadeConstants.GetArkadeWorkDirectory().FullName +
                Path.DirectorySeparatorChar + dateString + "-" + uuid.GetValue());

            var workingDirectory = new WorkingDirectory(rootDirectory, externalContentDirectory);

            workingDirectory.CreateAllFolders();
            return(workingDirectory);
        }
        public void ShouldReturnTestSuiteFromTests()
        {
            var             workingDirectory = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\noark3\\"));
            AddmlInfo       addml            = AddmlUtil.ReadFromFile(workingDirectory.Root().WithFile("noark_3_arkivuttrekk_med_prosesser.xml").FullName);
            AddmlDefinition addmlDefinition  = new AddmlDefinitionParser(addml, workingDirectory).GetAddmlDefinition();

            var testSession = new TestSession(new Archive(ArchiveType.Noark3, Uuid.Random(), workingDirectory));

            testSession.AddmlDefinition = addmlDefinition;

            var       addmlDatasetTestEngine = new AddmlDatasetTestEngine(new FlatFileReaderFactory(), new AddmlProcessRunner(), new StatusEventHandler());
            TestSuite testSuite = addmlDatasetTestEngine.RunTestsOnArchive(testSession);


            testSuite.Should().NotBeNull();
            testSuite.TestRuns.Should().NotBeNullOrEmpty();

            List <TestRun> analyseFindMinMaxValues = testSuite.TestRuns
                                                     .Where(run => run.TestName == AnalyseFindMinMaxValues.Name)
                                                     .ToList();

            analyseFindMinMaxValues.Count.Should().Be(1);
        }
Example #5
0
        public void ShouldParseNoark4ConvertedArkivuttrekkXml()
        {
            // Code to convert NOARKIH.XML to addml.xml
            //string noarkihString = TestUtil.ReadFromFileInTestDataDir("noark4\\NOARKIH.XML");
            //string addmlString = NoarkihToAddmlTransformer.Transform(noarkihString);

            // File is converted from NOARKIH.XML format

            var       externalContentDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\noark4\\");
            var       workingDirectory         = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), externalContentDirectory);
            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("addml.xml").FullName);

            AddmlDefinitionParser parser = new AddmlDefinitionParser(addml, workingDirectory, new StatusEventHandler());

            AddmlDefinition addmlDefinition = parser.GetAddmlDefinition();

            List <AddmlFlatFileDefinition> addmlFlatFileDefinitions = addmlDefinition.AddmlFlatFileDefinitions;

            addmlFlatFileDefinitions.Count.Should().Be(63);
            addmlFlatFileDefinitions[0].Name.Should().Be("ORDNPRINSTYPE");
            addmlFlatFileDefinitions[0].FileName.Should().Be("OPRITYP.XML");
            addmlFlatFileDefinitions[0].Encoding.Should().Be(Encodings.ISO_8859_1);
            addmlFlatFileDefinitions[0].RecordSeparator.Should().BeNull();
            addmlFlatFileDefinitions[0].AddmlRecordDefinitions.Count.Should().Be(1);
            AddmlRecordDefinition addmlRecordDefinition = addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0];

            addmlRecordDefinition.Name.Should().Be("ORDNPRINSTYPE");
            List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;

            addmlFieldDefinitions.Count.Should().Be(2);
            addmlFieldDefinitions[0].Name.Should().Be("OT.KODE");
            addmlFieldDefinitions[0].Type.Should().Be(StringDataType.Default);
            addmlFieldDefinitions[1].Name.Should().Be("OT.BETEGN");
            addmlFieldDefinitions[1].Type.Should().Be(StringDataType.Default);
            addmlRecordDefinition.PrimaryKey.Should().BeNull();
        }
Example #6
0
        public void ShouldParseJegerreg98ArkivuttrekkXml()
        {
            var       externalContentDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\TestData\\jegerreg-98-dos\\");
            var       workingDirectory         = new WorkingDirectory(ArkadeConstants.GetArkadeWorkDirectory(), externalContentDirectory);
            AddmlInfo addml = AddmlUtil.ReadFromFile(workingDirectory.Content().WithFile("arkivuttrekk.xml").FullName);

            AddmlDefinition addmlDefinition = new AddmlDefinitionParser(addml, workingDirectory).GetAddmlDefinition();

            List <AddmlFlatFileDefinition> addmlFlatFileDefinitions = addmlDefinition.AddmlFlatFileDefinitions;

            addmlFlatFileDefinitions.Count.Should().Be(10);
            {
                addmlFlatFileDefinitions[0].Name.Should().Be("ffd_3");
                addmlFlatFileDefinitions[0].FileName.Should().Be("jeger.dat");
                addmlFlatFileDefinitions[0].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[0].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[0].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(36);
                addmlFieldDefinitions[0].Name.Should().Be("fodselsnummer");
                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0]
                });
            }
            {
                addmlFlatFileDefinitions[1].Name.Should().Be("ffd_4");
                addmlFlatFileDefinitions[1].FileName.Should().Be("ut_jeger.dat");
                addmlFlatFileDefinitions[1].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[1].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[1].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[1].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(37);
                addmlFieldDefinitions[0].Name.Should().Be("plassnummer");
                addmlFieldDefinitions[0].Type.Should().Be(IntegerDataType.Default);
                addmlFieldDefinitions[1].Name.Should().Be("landkort");
                addmlFieldDefinitions[8].Name.Should().Be("personnummer");
                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0],
                    addmlFieldDefinitions[1],
                    addmlFieldDefinitions[8]
                });
            }
            {
                addmlFlatFileDefinitions[2].Name.Should().Be("ffd_5");
                addmlFlatFileDefinitions[2].FileName.Should().Be("ikkejeg.dat");
                addmlFlatFileDefinitions[2].Encoding.Should().Be(Encodings.ISO_8859_1);
                addmlFlatFileDefinitions[2].RecordSeparator.Should().Be(Separator.CRLF);
                addmlFlatFileDefinitions[2].AddmlRecordDefinitions.Count.Should().Be(1);
                AddmlRecordDefinition       addmlRecordDefinition = addmlFlatFileDefinitions[2].AddmlRecordDefinitions[0];
                List <AddmlFieldDefinition> addmlFieldDefinitions = addmlRecordDefinition.AddmlFieldDefinitions;
                addmlFieldDefinitions.Count.Should().Be(44);
                addmlFieldDefinitions[0].Name.Should().Be("fodselsnummer");
                addmlFieldDefinitions[0].StartPosition.Should().Be(1);
                addmlFieldDefinitions[0].FixedLength.Should().Be(11);
                addmlFieldDefinitions[0].IsUnique.Should().BeTrue();
                addmlFieldDefinitions[0].IsNullable.Should().BeFalse();
                addmlFieldDefinitions[0].MaxLength.Should().NotHaveValue();
                addmlFieldDefinitions[0].MinLength.Should().NotHaveValue();
                addmlFieldDefinitions[0].Type.Should().Be(StringDataType.Default);
                addmlFieldDefinitions[0].ForeignKey.Should().Be(
                    addmlFlatFileDefinitions[0].AddmlRecordDefinitions[0].AddmlFieldDefinitions[0]
                    );

                addmlFieldDefinitions[1].Name.Should().Be("etternavn");
                addmlFieldDefinitions[1].StartPosition.Should().Be(12);
                addmlFieldDefinitions[1].FixedLength.Should().Be(25);
                addmlFieldDefinitions[1].IsUnique.Should().BeFalse();
                addmlFieldDefinitions[1].IsNullable.Should().BeTrue();
                addmlFieldDefinitions[1].MaxLength.Should().NotHaveValue();
                addmlFieldDefinitions[1].MinLength.Should().NotHaveValue();
                addmlFieldDefinitions[1].Type.Should().Be(StringDataType.Default);
                addmlFieldDefinitions[1].ForeignKey.Should().BeNull();

                addmlRecordDefinition.PrimaryKey.Should()
                .Equal(new List <AddmlFieldDefinition>()
                {
                    addmlFieldDefinitions[0]
                });


                TestDateDataType(addmlDefinition);
                TestBooleanDataType(addmlDefinition);
                TestFloatDataType(addmlDefinition);
            }
        }