Пример #1
0
 public void CanReadEmptyContentWithoutAttachments()
 {
     using (var stream = new MemoryStream())
         using (var reader = new XRoadMessageReader(stream, "text/xml; charset=UTF-8", Path.GetTempPath(), serviceManagers))
             using (var message = new XRoadMessage())
             {
                 reader.Read(message, false);
                 Assert.Equal(0L, message.ContentLength);
             }
 }
Пример #2
0
        public void CanReadContentWithAttachments()
        {
            using (var stream = new MemoryStream())
                using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
                {
                    streamWriter.Write("\r\n");
                    streamWriter.Write("--5e7a8827-5850-45be-9a1e-8bbf6aff5da7\r\n");
                    streamWriter.Write("Content-Type: text/xml; charset=UTF-8\r\n");
                    streamWriter.Write("Content-Transfer-Encoding: 8bit\r\n");
                    streamWriter.Write("Content-ID: <rQI0gpIFuQMxlrqBj3qHKw==>\r\n");
                    streamWriter.Write("\r\n");
                    streamWriter.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n");
                    streamWriter.Write("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:repr=\"http://x-road.eu/xsd/representation.xsd\">\r\n");
                    streamWriter.Write("  <Header xmlns:xrd=\"http://x-road.ee/xsd/x-road.xsd\">\r\n");
                    streamWriter.Write("  </Header>\r\n");
                    streamWriter.Write("  <Body />\r\n");
                    streamWriter.Write("</Envelope>\r\n");
                    streamWriter.Write("\r\n");
                    streamWriter.Write("--5e7a8827-5850-45be-9a1e-8bbf6aff5da7\r\n");
                    streamWriter.Write("Content-Type: application/octet-stream\r\n");
                    streamWriter.Write("Content-Transfer-Encoding: binary\r\n");
                    streamWriter.Write("Content-ID: <CNbAWiFRKnmh3+udKo8mLw==>\r\n");
                    streamWriter.Write("\r\n");
                    streamWriter.Write("proovikas\r\n");
                    streamWriter.Write("--5e7a8827-5850-45be-9a1e-8bbf6aff5da7\r\n");
                    streamWriter.Write("Content-Type: application/octet-stream\r\n");
                    streamWriter.Write("Content-Transfer-Encoding: binary\r\n");
                    streamWriter.Write("Content-ID: <qrOlKraewrdRAu86cFnqwg==>\r\n");
                    streamWriter.Write("\r\n");
                    streamWriter.Write("testikas sisu\r\n");
                    streamWriter.Write("--5e7a8827-5850-45be-9a1e-8bbf6aff5da7--");
                    streamWriter.Flush();

                    var contentTypeHeader = "multipart/related; type=\"application/xml+xop\"; start=\"rQI0gpIFuQMxlrqBj3qHKw==\"; boundary=\"5e7a8827-5850-45be-9a1e-8bbf6aff5da7\"";

                    stream.Position = 0L;
                    using (var reader = new XRoadMessageReader(stream, contentTypeHeader, Path.GetTempPath(), serviceManagers))
                        using (var message = new XRoadMessage())
                        {
                            reader.Read(message, false);
                            Assert.Equal(838L, message.ContentLength);
                        }
                }
        }
Пример #3
0
        public void CanReadContentWithoutAttachments()
        {
            using (var stream = new MemoryStream())
                using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
                {
                    streamWriter.Write("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:repr=\"http://x-road.eu/xsd/representation.xsd\">\r\n");
                    streamWriter.Write("  <Header xmlns:xrd=\"http://x-road.ee/xsd/x-road.xsd\">\r\n");
                    streamWriter.Write("  </Header>\r\n");
                    streamWriter.Write("  <Body />\r\n");
                    streamWriter.Write("</Envelope>");
                    streamWriter.Flush();

                    stream.Position = 0L;
                    using (var reader = new XRoadMessageReader(stream, "text/xml; charset=UTF-8", Path.GetTempPath(), serviceManagers))
                        using (var message = new XRoadMessage())
                        {
                            reader.Read(message, false);
                            Assert.Equal(254L, message.ContentLength);
                        }
                }
        }
Пример #4
0
        public static Tuple <IXRoadHeader, IList <XElement>, IXRoadProtocol> ParseHeader(string xml, string ns)
        {
            using (var stream = new MemoryStream())
                using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
                {
                    streamWriter.WriteLine(@"<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:id=""http://x-road.eu/xsd/identifiers"" xmlns:repr=""http://x-road.eu/xsd/representation.xsd"">");
                    streamWriter.WriteLine($"<Header xmlns:xrd=\"{ns}\">");
                    streamWriter.WriteLine(xml);
                    streamWriter.WriteLine(@"</Header>");
                    streamWriter.WriteLine(@"</Envelope>");
                    streamWriter.Flush();

                    stream.Position = 0;
                    using (var reader = new XRoadMessageReader(stream, "text/xml; charset=UTF-8", Path.GetTempPath(), new[] { Globals.XRoadProtocol20, Globals.XRoadProtocol31, Globals.XRoadProtocol40 }))
                        using (var msg = new XRoadMessage())
                        {
                            reader.Read(msg, false);
                            return(Tuple.Create(msg.Header, msg.UnresolvedHeaders, msg.Protocol));
                        }
                }
        }