Exemplo n.º 1
0
    public void TimeZonePropertyTest2()
    {
        var tz   = new TimeZoneID(TimeZoneInfo.GetSystemTimeZones()[4].Id);
        var prop = new TimeZoneProperty(tz, GROUP);

        var vcard = new VCard
        {
            TimeZones = prop
        };

        string s = vcard.ToVcfString();

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.TimeZones);

        prop = vcard.TimeZones !.First();
        Assert.IsFalse(prop !.IsEmpty);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsTrue(tz.TryGetUtcOffset(out TimeSpan utc1));
        Assert.IsTrue(prop.Value !.TryGetUtcOffset(out TimeSpan utc2));
        Assert.AreEqual(utc1, utc2);
    }
Exemplo n.º 2
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);
Exemplo n.º 3
0
    public void GenderPropertyTest3()
    {
        var prop = new GenderProperty(VCdSex.Female, IDENTITY, GROUP);

        var vcard = new VCard
        {
            GenderViews = prop
        };

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

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.GenderViews);

        prop = vcard.GenderViews !.First() as GenderProperty;

        Assert.IsNotNull(prop);
        Assert.AreEqual(VCdSex.Female, prop !.Value.Sex);
        Assert.AreEqual(IDENTITY, prop !.Value.GenderIdentity);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);
    }
Exemplo n.º 4
0
    public void ProfilePropertyTest2()
    {
        var prop = new ProfileProperty(GROUP);

        var vcard = new VCard
        {
            Profile = prop
        };

        string s = vcard.ToVcfString();

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.Profile);

        prop = vcard.Profile;

        Assert.AreEqual(GROUP, prop !.Group);
        Assert.IsFalse(prop.IsEmpty);
    }
    public void PropertyIDMappingPropertyTest1()
    {
        var pidMap = new PropertyIDMapping(7, new Uri("http://folkerkinzel.de/"));
        var prop   = new PropertyIDMappingProperty(pidMap);

        var vcard = new VCard
        {
            PropertyIDMappings = prop
        };

        string s = vcard.ToVcfString(Enums.VCdVersion.V4_0);

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.PropertyIDMappings);

        prop = vcard.PropertyIDMappings !.First() as PropertyIDMappingProperty;

        Assert.IsNotNull(prop);
        Assert.AreEqual(pidMap.ID, prop !.Value?.ID);
        Assert.AreEqual(pidMap.Mapping, prop !.Value?.Mapping);
        Assert.IsNull(prop.Group);
        Assert.IsFalse(prop.IsEmpty);
    }
Exemplo n.º 6
0
    public void KindPropertyTest2()
    {
        const Enums.VCdKind kind = Enums.VCdKind.Application;

        var prop = new KindProperty(kind, GROUP);

        var vcard = new VCard
        {
            Kind = prop
        };

        string s = vcard.ToVcfString(Enums.VCdVersion.V4_0);

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.Kind);

        prop = vcard.Kind;

        Assert.AreEqual(kind, prop !.Value);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);
    }
Exemplo n.º 7
0
    public void GeoPropertyTest2()
    {
        var geo = new GeoCoordinate(17.44, 8.33);

        var prop = new GeoProperty(geo, GROUP);

        var vcard = new VCard
        {
            GeoCoordinates = prop
        };

        string s = vcard.ToVcfString();

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.GeoCoordinates);

        prop = vcard.GeoCoordinates !.First();

        Assert.AreEqual(geo, prop !.Value);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);
    }
    public void RelationUriPropertyTest4()
    {
        const Enums.RelationTypes relation = Enums.RelationTypes.Agent;
        var uri = new Uri("cid:test.com/", UriKind.Absolute);

        var prop = new RelationUriProperty(uri, relation, GROUP);

        var vcard = new VCard
        {
            Relations = prop
        };

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

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.Relations);

        prop = vcard.Relations !.First() as RelationUriProperty;

        Assert.IsNotNull(prop);
        Assert.AreEqual(uri, prop !.Value);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);
        Assert.AreEqual(relation, prop.Parameters.RelationType);
        Assert.AreEqual(Enums.VCdDataType.Uri, prop.Parameters.DataType);
    }
    public void RelationTextPropertyTest3()
    {
        const Enums.RelationTypes relation = Enums.RelationTypes.Agent;
        var text = "Bruno Hübchen";

        var prop = new RelationTextProperty(text, relation, GROUP);

        var vcard = new VCard
        {
            Relations = prop
        };

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

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.Relations);

        prop = vcard.Relations !.First() as RelationTextProperty;

        Assert.IsNotNull(prop);
        Assert.AreEqual(text, prop !.Value);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);

        Assert.AreEqual(relation, prop.Parameters.RelationType);
        Assert.AreEqual(Enums.VCdDataType.Text, prop.Parameters.DataType);
    }
    public void DateTimeOffsetPropertyTest2()
    {
        var now = new DateTimeOffset(2021, 4, 4, 12, 41, 2, TimeSpan.FromHours(2));

        var prop = new DateTimeOffsetProperty(now, GROUP);

        var vcard = new VCard
        {
            BirthDayViews = prop
        };

        string s = vcard.ToVcfString(Enums.VCdVersion.V4_0);

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.BirthDayViews);

        prop = vcard.BirthDayViews !.First() as DateTimeOffsetProperty;

        Assert.IsNotNull(prop);
        Assert.AreEqual(now, prop !.Value);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);

        Assert.AreEqual(Enums.VCdDataType.DateAndOrTime, prop.Parameters.DataType);
    }
Exemplo n.º 11
0
    public void DateTimeTextPropertyTest1()
    {
        string now = "Früh morgens";

        var prop = new DateTimeTextProperty(now, GROUP);

        var vcard = new VCard
        {
            BirthDayViews = prop
        };

        string s = vcard.ToVcfString(Enums.VCdVersion.V4_0);

        IList <VCard> list = VCard.ParseVcf(s);

        Assert.IsNotNull(list);
        Assert.AreEqual(1, list.Count);

        vcard = list[0];

        Assert.IsNotNull(vcard.BirthDayViews);

        prop = vcard.BirthDayViews !.First() as DateTimeTextProperty;

        Assert.IsNotNull(prop);
        Assert.AreEqual(now, prop !.Value);
        Assert.AreEqual(GROUP, prop.Group);
        Assert.IsFalse(prop.IsEmpty);
        Assert.AreEqual(Enums.VCdDataType.Text, prop.Parameters.DataType);
    }
Exemplo n.º 12
0
    public static void IntegrateWhatsAppNumberUsingIMPP()
    {
        const string mobilePhoneNumber = "tel:+1-234-567-89";

        // The IMPP-Extension (Instant Messaging [IM] and Presence Protocol [PP] applications)
        // is available in vCard 3.0 through RFC 4770:
        var whatsAppImpp = new VC::TextProperty(mobilePhoneNumber);

        whatsAppImpp.Parameters.InstantMessengerType = VC::Enums.ImppTypes.Personal
                                                       | VC::Enums.ImppTypes.Business
                                                       | VC::Enums.ImppTypes.Mobile;


        // The vCard 4.0 standard RFC 6350 recommends to add an additional TEL entry
        // if the instant messenging device supports voice and/or video.
        // I think, that's a good practice also in vCard 3.0.
        var xiamoiMobilePhone = new VC::TextProperty(mobilePhoneNumber.Substring(4));

        xiamoiMobilePhone.Parameters.PropertyClass = VC::Enums.PropertyClassTypes.Home
                                                     | VC::Enums.PropertyClassTypes.Work;
        xiamoiMobilePhone.Parameters.TelephoneType = VC::Enums.TelTypes.Voice
                                                     | VC::Enums.TelTypes.BBS
                                                     | VC::Enums.TelTypes.Cell
                                                     | VC::Enums.TelTypes.Msg
                                                     | VC::Enums.TelTypes.Text
                                                     | VC::Enums.TelTypes.Video;

        // Initialize the VCard:
        var vcard = new VCard
        {
            NameViews = new VC::NameProperty[]
            {
                new VC::NameProperty(lastName: null, firstName: "zzMad Perla 45")
            },

            DisplayNames = new VC::TextProperty[]
            {
                new VC::TextProperty("zzMad Perla 45")
            },

            // Add the WhatsApp-Handle:
            InstantMessengerHandles = new VC::TextProperty[]
            {
                whatsAppImpp
            },

            // Add the mobile phone too:
            PhoneNumbers = new VC::TextProperty[]
            {
                xiamoiMobilePhone
            }
        };

        Console.WriteLine(vcard.ToVcfString());
    }
Exemplo n.º 13
0
    public void WriteEmptyVCard()
    {
        var    vcard = new VCard();
        string s     = vcard.ToVcfString(VCdVersion.V4_0);

        IList <VCard>?cards = VCard.ParseVcf(s);

        Assert.AreEqual(cards.Count, 1);

        vcard = cards[0];

        Assert.AreEqual(VCdVersion.V4_0, vcard.Version);
        Assert.IsNotNull(vcard.DisplayNames);
        Assert.AreEqual(vcard.DisplayNames !.Count(), 1);
        Assert.IsNotNull(vcard.DisplayNames !.First());
    }
Exemplo n.º 14
0
    public void WriteEmptyVCard()
    {
        var    vcard = new VCard();
        string s     = vcard.ToVcfString(VCdVersion.V2_1);

        IList <VCard> cards = VCard.ParseVcf(s);

        Assert.AreEqual(cards.Count, 1);

        vcard = cards[0];

        Assert.AreEqual(vcard.Version, VCdVersion.V2_1);

        Assert.IsNotNull(vcard.NameViews);
        Assert.AreEqual(vcard.NameViews !.Count(), 1);
        Assert.IsNotNull(vcard.NameViews !.First());
    }
Exemplo n.º 15
0
    public static void UsingTheWhatsAppType()
    {
        var xiamoiMobilePhone = new VC::TextProperty("+1-234-567-89");

        xiamoiMobilePhone.Parameters.NonStandardParameters = new KeyValuePair <string, string>[]
        {
            new KeyValuePair <string, string>("TYPE", "WhatsApp")
        };

        // Initialize the VCard:
        var vcard = new VCard
        {
            NameViews = new VC::NameProperty[]
            {
                new VC::NameProperty(lastName: null, firstName: "zzMad Perla 45")
            },

            DisplayNames = new VC::TextProperty[]
            {
                new VC::TextProperty("zzMad Perla 45")
            },

            PhoneNumbers = new VC::TextProperty[]
            {
                xiamoiMobilePhone
            }
        };

        // Don't forget to set VcfOptions.WriteNonStandardParameters when serializing the
        // VCard: The default ignores NonStandardParameters (and NonStandardProperties):
        string vcfString = vcard.ToVcfString(options: VcfOptions.Default | VcfOptions.WriteNonStandardParameters);

        Console.WriteLine(vcfString);

        // Parse the VCF string:
        vcard = VCard.ParseVcf(vcfString)[0];

        // Find the WhatsApp number:
        string?whatsAppNumber = vcard.PhoneNumbers?
                                .FirstOrDefault(x => x?.Parameters.NonStandardParameters?.Any(x => x.Key == "TYPE" && x.Value == "WhatsApp") ?? false)?
                                .Value;

        Console.Write("The WhatsApp number is: ");
        Console.WriteLine(whatsAppNumber ?? "Don't know.");
    }
Exemplo n.º 16
0
    public void AppendValueTest()
    {
        var vcard = new VCard
        {
            Access = new AccessProperty(Enums.VCdAccess.Private, GROUP)
        };

        string serialized = vcard.ToVcfString();

        IList <VCard> list = VCard.ParseVcf(serialized);

        Assert.AreEqual(1, list.Count);

        vcard = list[0];
        Assert.IsNotNull(vcard.Access);
        Assert.AreEqual(GROUP, vcard.Access !.Group);
        Assert.AreEqual(Enums.VCdAccess.Private, vcard.Access.Value);
    }
Exemplo n.º 17
0
 public static string ToVcfString(
     this IEnumerable <VCard?> vCards,
     VCdVersion version = VCard.DEFAULT_VERSION,
     VcfOptions options = VcfOptions.Default)
 => VCard.ToVcfString(vCards, version, options: options);
Exemplo n.º 18
0
 public string ToVcfString(VCdVersion version = DEFAULT_VERSION, ITimeZoneIDConverter?tzConverter = null, VcfOptions options = VcfOptions.Default)
 => VCard.ToVcfString(this, version, tzConverter, options);