Exemplo n.º 1
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.º 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 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 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 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 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);
    }
Exemplo n.º 7
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);
    }
    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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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);
    }