public void VedleggTittelSkalSettesIManifestet() { //Arrange var resourceUtility = new ResourceUtility("Difi.SikkerDigitalPost.Klient.Tester.testdata"); var dokument = new Dokument("hoved", resourceUtility.ReadAllBytes(true, "hoveddokument", "Hoveddokument.pdf"), "application/pdf"); var vedleggTittel = "tittel"; var vedlegg = new Dokument(vedleggTittel, resourceUtility.ReadAllBytes(true, "hoveddokument", "Hoveddokument.pdf"), "application/pdf"); var dokumentPakke = new Dokumentpakke(dokument); dokumentPakke.LeggTilVedlegg(vedlegg); var message = new Forsendelse(DomainUtility.GetAvsender(), DomainUtility.GetDigitalPostInfoSimple(), dokumentPakke, Prioritet.Normal, Guid.NewGuid().ToString()); var asiceArkiv = DomainUtility.GetAsiceArchive(message); var manifestXml = new Manifest(message).Xml(); var namespaceManager = new XmlNamespaceManager(manifestXml.NameTable); namespaceManager.AddNamespace("ns9", NavneromUtility.DifiSdpSchema10); namespaceManager.AddNamespace("ds", NavneromUtility.XmlDsig); //Act //Assert var vedleggNodeInnerText = manifestXml.DocumentElement.SelectSingleNode("//ns9:vedlegg", namespaceManager).InnerText; Assert.Equal(vedleggTittel, vedleggNodeInnerText); }
public void ConstructorGeneratesBytes() { //Arrange var message = new Forsendelse(DomainUtility.GetAvsender(), DomainUtility.GetDigitalPostInfoSimple(), DomainUtility.GetDokumentpakkeWithMultipleVedlegg()); var asiceArchive = DomainUtility.GetAsiceArchive(message); //Act var archiveBytes = asiceArchive.UnencryptedBytes; //Assert using (var memoryStream = new MemoryStream(archiveBytes)) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Read)) { Assert.True(archive.Entries.Any(entry => entry.FullName == "manifest.xml")); Assert.True(archive.Entries.Any(entry => entry.FullName == "META-INF/signatures.xml")); Assert.True(archive.Entries.Any(entry => entry.FullName == message.Dokumentpakke.Hoveddokument.Filnavn)); foreach (var document in message.Dokumentpakke.Vedlegg) { Assert.True(archive.Entries.Any(entry => entry.FullName == document.Filnavn)); } } } }
public void ValidereManifestMotXsdValiderer() { var message = DomainUtility.GetForsendelseWithTestCertificate(); var arkiv = DomainUtility.GetAsiceArchive(message); var manifestXml = new Manifest(message).Xml(); string validationMessages; var validert = SdpXmlValidator.Instance.Validate(manifestXml.OuterXml, out validationMessages); Assert.True(validert, validationMessages); }
public void PersistsFileToDisk() { //Arrange var tmpDirectory = Path.GetTempPath(); var processor = new LagreDokumentpakkeTilDiskProsessor(tmpDirectory); var message = DomainUtility.GetForsendelseSimple(); var asiceBytes = DomainUtility.GetAsiceArchive(message).Bytes; var asiceStream = new MemoryStream(asiceBytes); //Act processor.Prosesser(message, asiceStream); var processedFileName = processor.LastFileProcessed; var tempFile = Path.Combine(tmpDirectory, processedFileName); //Assert Assert.Equal(asiceBytes.Length, new FileInfo(tempFile).Length); }
public void FileNameContainsEssentialData() { //Arrange var tmpDirectory = Path.GetTempPath(); var fileEnding = "asice.zip"; var processor = new LagreDokumentpakkeTilDiskProsessor(tmpDirectory); var message = DomainUtility.GetForsendelseSimple(); var asiceBytes = DomainUtility.GetAsiceArchive(message).Bytes; var asiceStream = new MemoryStream(asiceBytes); //Act processor.Prosesser(message, asiceStream); var processedFileName = processor.LastFileProcessed; var tempFileName = Path.Combine(tmpDirectory, processedFileName); //Assert Assert.True(tempFileName.Contains(tmpDirectory)); Assert.True(tempFileName.Contains(fileEnding)); Assert.True(tempFileName.Contains(message.KonversasjonsId.ToString())); Assert.True(tempFileName.Contains(DateTime.Now.Year.ToString())); }