Exemple #1
0
    public void TestLineWrapping()
    {
        var vcard = new VCard();

        const string UNITEXT = "Dies ist ein wirklich sehr sehr sehr langer Text mit ü, Ö, und ä " + "" +
                               "damit das Line-Wrappping mit Quoted-Printable-Encoding getestet werden kann. " +
                               "Um noch eine Zeile einzufügen, folgt hier noch ein Satz. ";

        const string ASCIITEXT = "This is really a very very long ASCII-Text. This is needed to test the " +
                                 "vCard 2.1 - LineWrapping. That's why I have to write so much even though I have nothing to say.";

        byte[] bytes = CreateBytes();

        vcard.Notes = new TextProperty[]
        {
            new TextProperty(UNITEXT)
        };

        vcard.Keys   = new DataProperty[] { new DataProperty(DataUrl.FromText(ASCIITEXT)) };
        vcard.Photos = new DataProperty[] { new DataProperty(DataUrl.FromBytes(bytes, "image/jpeg")) };

        string s = vcard.ToVcfString(VCdVersion.V2_1);

        Assert.IsNotNull(s);

        Assert.IsTrue(s.Split(new string[] { VCard.NewLine }, StringSplitOptions.None)
                      .All(x => x != null && x.Length <= VCard.MAX_BYTES_PER_LINE));

        _ = VCard.ParseVcf(s);

        Assert.AreEqual(((DataUrl?)vcard.Keys?.First()?.Value)?.GetEmbeddedText(), ASCIITEXT);
        Assert.AreEqual(vcard.Photos?.First()?.Parameters.MediaType, "image/jpeg");
        Assert.IsTrue(((DataUrl?)vcard.Photos?.First()?.Value)?.GetEmbeddedBytes()?.SequenceEqual(bytes) ?? false);
Exemple #2
0
    public void TryCreateTest()
    {
        const string TEXT      = "In Märchenbüchern herumstöbern.";
        const string MIME_TYPE = "application/vnd.api+json";

        byte[] DATA = new byte[] { 1, 2, 3 };



        var dataUrl1 = DataUrl.FromText(TEXT);

        Assert.IsTrue(DataUrl.TryCreate(dataUrl1.ToString(), out DataUrl? dataUrl2));

        Assert.AreEqual(dataUrl2?.MimeType.MediaType, "text/plain");
        Assert.AreEqual(dataUrl2?.MimeType.Parameters?[0].Value, "US-ASCII");
        Assert.AreEqual(TEXT, dataUrl2?.GetEmbeddedText());


        dataUrl1 = DataUrl.FromBytes(DATA, MIME_TYPE);

        Assert.IsTrue(DataUrl.TryCreate(dataUrl1.ToString(), out dataUrl2));

        Assert.AreEqual(dataUrl2?.MimeType.MediaType, MIME_TYPE);
        Assert.AreEqual(dataUrl2?.GetFileExtension(), ".json");
        Assert.IsTrue(dataUrl2?.GetEmbeddedBytes()?.SequenceEqual(DATA) ?? false);


        dataUrl1 = DataUrl.FromBytes(Encoding.GetEncoding("iso-8859-1").GetBytes(TEXT), ";charset=ISO-8859-1");

        Assert.IsTrue(DataUrl.TryCreate(dataUrl1.ToString(), out dataUrl2));

        Assert.AreEqual(dataUrl2?.MimeType.MediaType, "text/plain");
        Assert.AreEqual(dataUrl2?.MimeType.Parameters?[0].Value, "ISO-8859-1");
        Assert.AreEqual(dataUrl2?.Encoding, DataEncoding.Base64);
        Assert.IsTrue(dataUrl2?.ContainsText ?? false);
        Assert.AreEqual(TEXT, dataUrl2?.GetEmbeddedText());

        string test = "data:;charset=UTF-8,Text";

        Assert.IsTrue(DataUrl.TryCreate(test, out dataUrl2));

        Assert.AreEqual(dataUrl2?.EncodedData, "Text");
        Assert.AreEqual(dataUrl2?.MimeType.MediaType, "text/plain");
        Assert.AreEqual(dataUrl2?.MimeType.Parameters?[0].Value, "UTF-8");
        Assert.AreEqual(dataUrl2?.Encoding, DataEncoding.UrlEncoded);
        Assert.AreEqual("Text", dataUrl2?.GetEmbeddedText());

        Assert.IsFalse(DataUrl.TryCreate(null, out _));
        Assert.IsFalse(DataUrl.TryCreate("", out _));
        Assert.IsFalse(DataUrl.TryCreate("http://wwww.folker-kinzel.de/index.htm", out _));
    }
Exemple #3
0
    public void TestDataUri()
    {
        string text = "http://www.fölkerchen.de";


        string test = DATA_PROTOCOL + "text/plain;charset=utf-8" + ";" + DEFAULT_ENCODING + "," + Uri.EscapeDataString(text);

        Assert.IsTrue(DataUrl.TryCreate(test, out DataUrl? dataUri));
        Assert.AreEqual(text, dataUri?.GetEmbeddedText());

        dataUri = DataUrl.FromText(text);
        Assert.IsNotNull(dataUri);

        dataUri = DataUrl.FromBytes(new byte[] { 1, 2, 3 }, "application/x-octet");
        Assert.IsNotNull(dataUri);
    }
Exemple #4
0
 public void FromTextOnStringEmpty()
 {
     var _ = DataUrl.FromText("");
 }