Inheritance: IAsiceAttachable
            public void ReturnsProperBytesCount()
            {
                //Arrange
                var forsendelse = DomainUtility.GetDigitalDigitalPostWithNotificationMultipleDocumentsAndHigherSecurity();

                var manifest = new Manifest(forsendelse);
                var cryptographicCertificate = forsendelse.PostInfo.Mottaker.Sertifikat;
                var signature = new Signature(forsendelse, manifest, DomainUtility.GetAvsenderCertificate());

                var asiceAttachables = new List<IAsiceAttachable>();
                asiceAttachables.AddRange(forsendelse.Dokumentpakke.Vedlegg);
                asiceAttachables.Add(forsendelse.Dokumentpakke.Hoveddokument);
                asiceAttachables.Add(manifest);
                asiceAttachables.Add(signature);

                var asiceArchive = new AsiceArchive(cryptographicCertificate, new GuidUtility(), new List<AsiceAttachableProcessor>(), asiceAttachables.ToArray());

                var expectedBytesCount = 0L;
                foreach (var dokument in asiceAttachables)
                {
                    expectedBytesCount += dokument.Bytes.Length;
                }

                //Act
                var actualBytesCount = asiceArchive.UnzippedContentBytesCount;

                //Assert
                Assert.Equal(expectedBytesCount, actualBytesCount);
            }
            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 InitializesFieldsProperly()
            {
                //Arrange
                var forsendelse = DomainUtility.GetDigitalDigitalPostWithNotificationMultipleDocumentsAndHigherSecurity();

                var manifest = new Manifest(forsendelse);
                var cryptographicCertificate = forsendelse.PostInfo.Mottaker.Sertifikat;
                var signature = new Signature(forsendelse, manifest, DomainUtility.GetAvsenderCertificate());

                var asiceAttachables = new List<IAsiceAttachable>();
                asiceAttachables.AddRange(forsendelse.Dokumentpakke.Vedlegg);
                asiceAttachables.Add(forsendelse.Dokumentpakke.Hoveddokument);
                asiceAttachables.Add(manifest);
                asiceAttachables.Add(signature);

                var asiceAttachablesArray = asiceAttachables.ToArray();

                var asiceAttachableProcessors = new List<AsiceAttachableProcessor>();

                //Act
                var asiceArchive = new AsiceArchive(cryptographicCertificate, new GuidUtility(), asiceAttachableProcessors, asiceAttachablesArray);

                //Assert
                Assert.Equal(asiceAttachableProcessors, asiceArchive.AsiceAttachableProcessors);
                Assert.Equal(asiceAttachablesArray, asiceArchive.AsiceAttachables);
            }
            public void EnkelKonstruktør()
            {
                //Arrange
                const string id = "Id_1";
                const string mimeType = "application/xml";
                const string filnavn = "manifest.xml";

                var forsendelse = DomainUtility.GetForsendelseWithTestCertificate();
                var manifest = new Manifest(forsendelse);

                //Act

                //Assert
                Assert.Equal(forsendelse, manifest.Forsendelse);
                Assert.Equal(forsendelse.Avsender, manifest.Avsender);
                Assert.Equal(id, manifest.Id);
                Assert.Equal(mimeType, manifest.MimeType);
                Assert.Equal(filnavn, manifest.Filnavn);
            }
        internal static DocumentBundle Create(Forsendelse forsendelse, GuidUtility guidUtility, X509Certificate2 senderCertificate, IAsiceConfiguration asiceConfiguration)
        {
            var manifest = new Manifest(forsendelse);
            ValidateXmlAndThrowIfInvalid(manifest.Xml(), "Manifest");

            var signature = new Signature(forsendelse, manifest, senderCertificate);
            ValidateXmlAndThrowIfInvalid(signature.Xml(), "Signatur");

            var asiceAttachables = new List<IAsiceAttachable>();
            asiceAttachables.AddRange(forsendelse.Dokumentpakke.Vedlegg);
            asiceAttachables.Add(forsendelse.Dokumentpakke.Hoveddokument);
            asiceAttachables.Add(manifest);
            asiceAttachables.Add(signature);

            var asiceAttachableProcessors = ConvertDocumentBundleProcessorsToAsiceAttachableProcessors(forsendelse, asiceConfiguration);

            var asiceArchive = new AsiceArchive(forsendelse.PostInfo.Mottaker.Sertifikat, guidUtility, asiceAttachableProcessors, asiceAttachables.ToArray());

            return new DocumentBundle(asiceArchive.Bytes, asiceArchive.UnzippedContentBytesCount, asiceArchive.ContentId);
        }
            public void UgyldigNavnPåHoveddokumentValidererIkke()
            {
                var manifest = new Manifest(DomainUtility.GetForsendelseWithTestCertificate());

                var manifestXml = manifest.Xml();
                var manifestValidator = SdpXmlValidator.Instance;

                var namespaceManager = new XmlNamespaceManager(manifestXml.NameTable);
                namespaceManager.AddNamespace("ns9", NavneromUtility.DifiSdpSchema10);
                namespaceManager.AddNamespace("ds", NavneromUtility.XmlDsig);

                var hoveddokumentNode = manifestXml.DocumentElement.SelectSingleNode("//ns9:hoveddokument",
                    namespaceManager);
                var gammelVerdi = hoveddokumentNode.Attributes["href"].Value;
                hoveddokumentNode.Attributes["href"].Value = "abc"; //Endre navn på hoveddokument til å være for kort

                string validationMessages;
                var validert = manifestValidator.Validate(manifestXml.OuterXml, out validationMessages);
                Assert.False(validert, validationMessages);

                hoveddokumentNode.Attributes["href"].Value = gammelVerdi;
            }
        internal static AsiceArchive GetAsiceArchive(Forsendelse message)
        {
            var manifest = new Manifest(message);
            var signature = new Signature(message, manifest, GetAvsenderEnhetstesterSertifikat());
            var cryptographicCertificate = message.PostInfo.Mottaker.Sertifikat;

            var asiceAttachables = new List<IAsiceAttachable>();
            asiceAttachables.AddRange(message.Dokumentpakke.Vedlegg);
            asiceAttachables.Add(message.Dokumentpakke.Hoveddokument);
            asiceAttachables.Add(manifest);
            asiceAttachables.Add(signature);

            return new AsiceArchive(cryptographicCertificate, new GuidUtility(), new List<AsiceAttachableProcessor>(), asiceAttachables.ToArray());
        }
            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);
            }