Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for Org in PayloadGenerator.ContactData #276

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public class ContactData : Payload
private readonly string firstname;
private readonly string lastname;
private readonly string nickname;
private readonly string org;
private readonly string phone;
private readonly string mobilePhone;
private readonly string workPhone;
Expand Down Expand Up @@ -420,11 +421,12 @@ public class ContactData : Payload
/// <param name="country">Country</param>
/// <param name="addressOrder">The address order format to use</param>
/// <param name="note">Memo text / notes</param>
public ContactData(ContactOutputType outputType, string firstname, string lastname, string nickname = null, string phone = null, string mobilePhone = null, string workPhone = null, string email = null, DateTime? birthday = null, string website = null, string street = null, string houseNumber = null, string city = null, string zipCode = null, string country = null, string note = null, string stateRegion = null, AddressOrder addressOrder = AddressOrder.Default)
public ContactData(ContactOutputType outputType, string firstname, string lastname, string nickname = null, string phone = null, string mobilePhone = null, string workPhone = null, string email = null, DateTime? birthday = null, string website = null, string street = null, string houseNumber = null, string city = null, string zipCode = null, string country = null, string note = null, string stateRegion = null, AddressOrder addressOrder = AddressOrder.Default, string org = null)
{
this.firstname = firstname;
this.lastname = lastname;
this.nickname = nickname;
this.org = org;
this.phone = phone;
this.mobilePhone = mobilePhone;
this.workPhone = workPhone;
Expand Down Expand Up @@ -452,6 +454,8 @@ public override string ToString()
payload += $"N:{lastname}, {firstname}\r\n";
else if (!string.IsNullOrEmpty(firstname) || !string.IsNullOrEmpty(lastname))
payload += $"N:{firstname}{lastname}\r\n";
if (!string.IsNullOrEmpty(org))
payload += $"ORG:{org}\r\n";
if (!string.IsNullOrEmpty(phone))
payload += $"TEL:{phone}\r\n";
if (!string.IsNullOrEmpty(mobilePhone))
Expand Down Expand Up @@ -493,7 +497,10 @@ public override string ToString()

payload += $"N:{(!string.IsNullOrEmpty(lastname) ? lastname : "")};{(!string.IsNullOrEmpty(firstname) ? firstname : "")};;;\r\n";
payload += $"FN:{(!string.IsNullOrEmpty(firstname) ? firstname + " " : "")}{(!string.IsNullOrEmpty(lastname) ? lastname : "")}\r\n";

if (!string.IsNullOrEmpty(org))
{
payload += $"ORG:" + org + "\r\n";
}
if (!string.IsNullOrEmpty(phone))
{
payload += $"TEL;";
Expand Down
30 changes: 18 additions & 12 deletions QRCoderTests/PayloadGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,7 @@ public void contactdata_generator_can_generate_payload_full_mecard()
var firstname = "John";
var lastname = "Doe";
var nickname = "Johnny";
var org = "Johnny's Badass Programming";
var phone = "+4253212222";
var mobilePhone = "+421701234567";
var workPhone = "+4253211337";
Expand All @@ -2747,11 +2748,11 @@ public void contactdata_generator_can_generate_payload_full_mecard()
var note = "Badass programmer.";
var outputType = PayloadGenerator.ContactData.ContactOutputType.MeCard;

var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note);
var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, org: org);

generator
.ToString()
.ShouldBe("MECARD+\r\nN:Doe, John\r\nTEL:+4253212222\r\nTEL:+421701234567\r\nTEL:+4253211337\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nBDAY:19700201\r\nADR:,,Long street 42,12345,Super-Town,,Starlight Country\r\nURL:http://john.doe\r\nNICKNAME:Johnny");
.ShouldBe("MECARD+\r\nN:Doe, John\r\nORG:Johnny's Badass Programming\r\nTEL:+4253212222\r\nTEL:+421701234567\r\nTEL:+4253211337\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nBDAY:19700201\r\nADR:,,Long street 42,12345,Super-Town,,Starlight Country\r\nURL:http://john.doe\r\nNICKNAME:Johnny");
}

[Fact]
Expand All @@ -2761,6 +2762,7 @@ public void contactdata_generator_can_generate_payload_full_mecard_reversed()
var firstname = "John";
var lastname = "Doe";
var nickname = "Johnny";
var org = "Johnny's Badass Programming";
var phone = "+4253212222";
var mobilePhone = "+421701234567";
var workPhone = "+4253211337";
Expand All @@ -2775,11 +2777,11 @@ public void contactdata_generator_can_generate_payload_full_mecard_reversed()
var note = "Badass programmer.";
var outputType = PayloadGenerator.ContactData.ContactOutputType.MeCard;

var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, addressOrder: PayloadGenerator.ContactData.AddressOrder.Reversed);
var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, addressOrder: PayloadGenerator.ContactData.AddressOrder.Reversed, org: org);

generator
.ToString()
.ShouldBe("MECARD+\r\nN:Doe, John\r\nTEL:+4253212222\r\nTEL:+421701234567\r\nTEL:+4253211337\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nBDAY:19700201\r\nADR:,,42 Long street,Super-Town,,12345,Starlight Country\r\nURL:http://john.doe\r\nNICKNAME:Johnny");
.ShouldBe("MECARD+\r\nN:Doe, John\r\nORG:Johnny's Badass Programming\r\nTEL:+4253212222\r\nTEL:+421701234567\r\nTEL:+4253211337\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nBDAY:19700201\r\nADR:,,42 Long street,Super-Town,,12345,Starlight Country\r\nURL:http://john.doe\r\nNICKNAME:Johnny");
}

[Fact]
Expand All @@ -2789,6 +2791,7 @@ public void contactdata_generator_can_generate_payload_full_vcard21()
var firstname = "John";
var lastname = "Doe";
var nickname = "Johnny";
var org = "Johnny's Badass Programming";
var phone = "+4253212222";
var mobilePhone = "+421701234567";
var workPhone = "+4253211337";
Expand All @@ -2803,11 +2806,11 @@ public void contactdata_generator_can_generate_payload_full_vcard21()
var note = "Badass programmer.";
var outputType = PayloadGenerator.ContactData.ContactOutputType.VCard21;

var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note);
var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, org: org);

generator
.ToString()
.ShouldBe("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Doe;John;;;\r\nFN:John Doe\r\nTEL;HOME;VOICE:+4253212222\r\nTEL;HOME;CELL:+421701234567\r\nTEL;WORK;VOICE:+4253211337\r\nADR;HOME;PREF:;;Long street 42;12345;Super-Town;;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nEND:VCARD");
.ShouldBe("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Doe;John;;;\r\nFN:John Doe\r\nORG:Johnny's Badass Programming\r\nTEL;HOME;VOICE:+4253212222\r\nTEL;HOME;CELL:+421701234567\r\nTEL;WORK;VOICE:+4253211337\r\nADR;HOME;PREF:;;Long street 42;12345;Super-Town;;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nEND:VCARD");
}

[Fact]
Expand All @@ -2817,6 +2820,7 @@ public void contactdata_generator_can_generate_payload_full_vcard3()
var firstname = "John";
var lastname = "Doe";
var nickname = "Johnny";
var org = "Johnny's Badass Programming";
var phone = "+4253212222";
var mobilePhone = "+421701234567";
var workPhone = "+4253211337";
Expand All @@ -2831,11 +2835,11 @@ public void contactdata_generator_can_generate_payload_full_vcard3()
var note = "Badass programmer.";
var outputType = PayloadGenerator.ContactData.ContactOutputType.VCard3;

var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note);
var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, org: org);

generator
.ToString()
.ShouldBe("BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John;;;\r\nFN:John Doe\r\nTEL;TYPE=HOME,VOICE:+4253212222\r\nTEL;TYPE=HOME,CELL:+421701234567\r\nTEL;TYPE=WORK,VOICE:+4253211337\r\nADR;TYPE=HOME,PREF:;;Long street 42;12345;Super-Town;;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nNICKNAME:Johnny\r\nEND:VCARD");
.ShouldBe("BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John;;;\r\nFN:John Doe\r\nORG:Johnny's Badass Programming\r\nTEL;TYPE=HOME,VOICE:+4253212222\r\nTEL;TYPE=HOME,CELL:+421701234567\r\nTEL;TYPE=WORK,VOICE:+4253211337\r\nADR;TYPE=HOME,PREF:;;Long street 42;12345;Super-Town;;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nNICKNAME:Johnny\r\nEND:VCARD");
}

[Fact]
Expand All @@ -2845,6 +2849,7 @@ public void contactdata_generator_can_generate_payload_full_vcard4()
var firstname = "John";
var lastname = "Doe";
var nickname = "Johnny";
var org = "Johnny's Badass Programming";
var phone = "+4253212222";
var mobilePhone = "+421701234567";
var workPhone = "+4253211337";
Expand All @@ -2859,11 +2864,11 @@ public void contactdata_generator_can_generate_payload_full_vcard4()
var note = "Badass programmer.";
var outputType = PayloadGenerator.ContactData.ContactOutputType.VCard4;

var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note);
var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, org: org);

generator
.ToString()
.ShouldBe("BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;\r\nFN:John Doe\r\nTEL;TYPE=home,voice;VALUE=uri:tel:+4253212222\r\nTEL;TYPE=home,cell;VALUE=uri:tel:+421701234567\r\nTEL;TYPE=work,voice;VALUE=uri:tel:+4253211337\r\nADR;TYPE=home,pref:;;Long street 42;12345;Super-Town;;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nNICKNAME:Johnny\r\nEND:VCARD");
.ShouldBe("BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;\r\nFN:John Doe\r\nORG:Johnny's Badass Programming\r\nTEL;TYPE=home,voice;VALUE=uri:tel:+4253212222\r\nTEL;TYPE=home,cell;VALUE=uri:tel:+421701234567\r\nTEL;TYPE=work,voice;VALUE=uri:tel:+4253211337\r\nADR;TYPE=home,pref:;;Long street 42;12345;Super-Town;;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nNICKNAME:Johnny\r\nEND:VCARD");
}

[Fact]
Expand All @@ -2873,6 +2878,7 @@ public void contactdata_generator_can_generate_payload_full_vcard4_reverse()
var firstname = "John";
var lastname = "Doe";
var nickname = "Johnny";
var org = "Johnny's Badass Programming";
var phone = "+4253212222";
var mobilePhone = "+421701234567";
var workPhone = "+4253211337";
Expand All @@ -2887,11 +2893,11 @@ public void contactdata_generator_can_generate_payload_full_vcard4_reverse()
var note = "Badass programmer.";
var outputType = PayloadGenerator.ContactData.ContactOutputType.VCard4;

var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, addressOrder: PayloadGenerator.ContactData.AddressOrder.Reversed);
var generator = new PayloadGenerator.ContactData(outputType, firstname, lastname, nickname, phone, mobilePhone, workPhone, email, birthday, website, street, houseNumber, city, zipCode, country, note, addressOrder: PayloadGenerator.ContactData.AddressOrder.Reversed, org: org);

generator
.ToString()
.ShouldBe("BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;\r\nFN:John Doe\r\nTEL;TYPE=home,voice;VALUE=uri:tel:+4253212222\r\nTEL;TYPE=home,cell;VALUE=uri:tel:+421701234567\r\nTEL;TYPE=work,voice;VALUE=uri:tel:+4253211337\r\nADR;TYPE=home,pref:;;42 Long street;Super-Town;;12345;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nNICKNAME:Johnny\r\nEND:VCARD");
.ShouldBe("BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;\r\nFN:John Doe\r\nORG:Johnny's Badass Programming\r\nTEL;TYPE=home,voice;VALUE=uri:tel:+4253212222\r\nTEL;TYPE=home,cell;VALUE=uri:tel:+421701234567\r\nTEL;TYPE=work,voice;VALUE=uri:tel:+4253211337\r\nADR;TYPE=home,pref:;;42 Long street;Super-Town;;12345;Starlight Country\r\nBDAY:19700201\r\nURL:http://john.doe\r\nEMAIL:me@john.doe\r\nNOTE:Badass programmer.\r\nNICKNAME:Johnny\r\nEND:VCARD");
}

[Fact]
Expand Down