-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split PayloadGeneratorTests into multiple files (#569)
- Loading branch information
Showing
24 changed files
with
3,560 additions
and
3,387 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Globalization; | ||
using System.Threading; | ||
using QRCoder; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace QRCoderTests.PayloadGeneratorTests; | ||
|
||
public class BitcoinAddressTests | ||
{ | ||
[Fact] | ||
public void bitcoin_address_generator_can_generate_address() | ||
{ | ||
var address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | ||
var amount = .123; | ||
var label = "Some Label to Encode"; | ||
var message = "Some Message to Encode"; | ||
|
||
var generator = new PayloadGenerator.BitcoinAddress(address, amount, label, message); | ||
|
||
generator | ||
.ToString() | ||
.ShouldBe("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Some%20Label%20to%20Encode&message=Some%20Message%20to%20Encode&amount=.123"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoin_address_generator_should_skip_missing_label() | ||
{ | ||
var address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | ||
var amount = .123; | ||
var message = "Some Message to Encode"; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinAddress(address, amount, null, message); | ||
|
||
generator | ||
.ToString() | ||
.ShouldNotContain("label"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoin_address_generator_should_skip_missing_message() | ||
{ | ||
var address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | ||
var amount = .123; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinAddress(address, amount); | ||
|
||
generator | ||
.ToString() | ||
.ShouldNotContain("message"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoin_address_generator_should_round_to_satoshi() | ||
{ | ||
var address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | ||
var amount = .123456789; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinAddress(address, amount); | ||
|
||
generator | ||
.ToString() | ||
.ShouldContain("amount=.12345679"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoin_address_generator_disregards_current_culture() | ||
{ | ||
#if NETCOREAPP1_1 | ||
var currentCulture = CultureInfo.DefaultThreadCurrentCulture; | ||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("de-DE"); | ||
#else | ||
var currentCulture = Thread.CurrentThread.CurrentCulture; | ||
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); | ||
#endif | ||
|
||
var address = "175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"; | ||
var amount = .123; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinAddress(address, amount); | ||
|
||
generator | ||
.ToString() | ||
.ShouldBe("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=.123"); | ||
|
||
#if NETCOREAPP1_1 | ||
CultureInfo.DefaultThreadCurrentCulture = currentCulture; | ||
#else | ||
Thread.CurrentThread.CurrentCulture = currentCulture; | ||
#endif | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
QRCoderTests/PayloadGeneratorTests/BitcoinCashAddressTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Globalization; | ||
using System.Threading; | ||
using QRCoder; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace QRCoderTests.PayloadGeneratorTests; | ||
|
||
public class BitcoinCashAddressTests | ||
{ | ||
[Fact] | ||
public void bitcoincash_address_generator_can_generate_address() | ||
{ | ||
var address = "qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890"; | ||
var amount = .123; | ||
var label = "Some Label to Encode"; | ||
var message = "Some Message to Encode"; | ||
|
||
var generator = new PayloadGenerator.BitcoinCashAddress(address, amount, label, message); | ||
|
||
generator | ||
.ToString() | ||
.ShouldBe("bitcoincash:qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890?label=Some%20Label%20to%20Encode&message=Some%20Message%20to%20Encode&amount=.123"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoincash_address_generator_should_skip_missing_label() | ||
{ | ||
var address = "qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890"; | ||
var amount = .123; | ||
var message = "Some Message to Encode"; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinCashAddress(address, amount, null, message); | ||
|
||
generator | ||
.ToString() | ||
.ShouldNotContain("label"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoincash_address_generator_should_skip_missing_message() | ||
{ | ||
var address = "qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890"; | ||
var amount = .123; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinCashAddress(address, amount); | ||
|
||
generator | ||
.ToString() | ||
.ShouldNotContain("message"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoincash_address_generator_should_round_to_satoshi() | ||
{ | ||
var address = "qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890"; | ||
var amount = .123456789; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinCashAddress(address, amount); | ||
|
||
generator | ||
.ToString() | ||
.ShouldContain("amount=.12345679"); | ||
} | ||
|
||
[Fact] | ||
public void bitcoincash_address_generator_disregards_current_culture() | ||
{ | ||
#if NETCOREAPP1_1 | ||
var currentCulture = CultureInfo.DefaultThreadCurrentCulture; | ||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("de-DE"); | ||
#else | ||
var currentCulture = Thread.CurrentThread.CurrentCulture; | ||
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); | ||
#endif | ||
|
||
var address = "qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890"; | ||
var amount = .123; | ||
|
||
|
||
var generator = new PayloadGenerator.BitcoinCashAddress(address, amount); | ||
|
||
generator | ||
.ToString() | ||
.ShouldBe("bitcoincash:qqtlfk37qyey50f4wfuhc7jw85zsdp8s2swffjk890?amount=.123"); | ||
|
||
#if NETCOREAPP1_1 | ||
CultureInfo.DefaultThreadCurrentCulture = currentCulture; | ||
#else | ||
Thread.CurrentThread.CurrentCulture = currentCulture; | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using QRCoder; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace QRCoderTests.PayloadGeneratorTests; | ||
|
||
public class BookmarkTests | ||
{ | ||
[Fact] | ||
public void bookmark_should_build() | ||
{ | ||
var url = "http://code-bude.net"; | ||
var title = "A nerd's blog"; | ||
|
||
var generator = new PayloadGenerator.Bookmark(url, title); | ||
|
||
generator.ToString().ShouldBe("MEBKM:TITLE:A nerd's blog;URL:http\\://code-bude.net;;"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void bookmark_should_escape_input() | ||
{ | ||
var url = "http://code-bude.net/fake,url.html"; | ||
var title = "A nerd's blog: \\All;the;things\\"; | ||
|
||
var generator = new PayloadGenerator.Bookmark(url, title); | ||
|
||
generator.ToString().ShouldBe("MEBKM:TITLE:A nerd's blog\\: \\\\All\\;the\\;things\\\\;URL:http\\://code-bude.net/fake\\,url.html;;"); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
QRCoderTests/PayloadGeneratorTests/CalendarEventTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using QRCoder; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace QRCoderTests.PayloadGeneratorTests; | ||
|
||
public class CalendarEventTests | ||
{ | ||
[Fact] | ||
public void calendarevent_should_build_universal() | ||
{ | ||
var subject = "Release party"; | ||
var description = "A small party for the new QRCoder. Bring some beer!"; | ||
var location = "Programmer's paradise, Beachtown, Paradise"; | ||
var alldayEvent = false; | ||
var begin = new DateTime(2016, 01, 03, 12, 00, 00); | ||
var end = new DateTime(2016, 01, 03, 14, 30, 00); | ||
var encoding = PayloadGenerator.CalendarEvent.EventEncoding.Universal; | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent, encoding); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DESCRIPTION:A small party for the new QRCoder. Bring some beer!{Environment.NewLine}LOCATION:Programmer's paradise, Beachtown, Paradise{Environment.NewLine}DTSTART:20160103T120000{Environment.NewLine}DTEND:20160103T143000{Environment.NewLine}END:VEVENT"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void calendarevent_should_build_ical() | ||
{ | ||
var subject = "Release party"; | ||
var description = "A small party for the new QRCoder. Bring some beer!"; | ||
var location = "Programmer's paradise, Beachtown, Paradise"; | ||
var alldayEvent = false; | ||
var begin = new DateTime(2016, 01, 03, 12, 00, 00); | ||
var end = new DateTime(2016, 01, 03, 14, 30, 0); | ||
var encoding = PayloadGenerator.CalendarEvent.EventEncoding.iCalComplete; | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent, encoding); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VCALENDAR{Environment.NewLine}VERSION:2.0{Environment.NewLine}BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DESCRIPTION:A small party for the new QRCoder. Bring some beer!{Environment.NewLine}LOCATION:Programmer's paradise, Beachtown, Paradise{Environment.NewLine}DTSTART:20160103T120000{Environment.NewLine}DTEND:20160103T143000{Environment.NewLine}END:VEVENT{Environment.NewLine}END:VCALENDAR"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void calendarevent_should_build_with_utc_datetime() | ||
{ | ||
var subject = "Release party"; | ||
var description = "A small party for the new QRCoder. Bring some beer!"; | ||
var location = "Programmer's paradise, Beachtown, Paradise"; | ||
var alldayEvent = false; | ||
var begin = new DateTime(2016, 01, 03, 12, 00, 00, DateTimeKind.Utc); | ||
var end = new DateTime(2016, 01, 03, 14, 30, 00, DateTimeKind.Utc); | ||
var encoding = PayloadGenerator.CalendarEvent.EventEncoding.Universal; | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent, encoding); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DESCRIPTION:A small party for the new QRCoder. Bring some beer!{Environment.NewLine}LOCATION:Programmer's paradise, Beachtown, Paradise{Environment.NewLine}DTSTART:20160103T120000Z{Environment.NewLine}DTEND:20160103T143000Z{Environment.NewLine}END:VEVENT"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void calendarevent_should_build_with_utc_offset() | ||
{ | ||
var subject = "Release party"; | ||
var description = "A small party for the new QRCoder. Bring some beer!"; | ||
var location = "Programmer's paradise, Beachtown, Paradise"; | ||
var alldayEvent = false; | ||
var begin = new DateTimeOffset(2016, 01, 03, 12, 00, 00, new TimeSpan(3, 0, 0)); | ||
var end = new DateTimeOffset(2016, 01, 03, 14, 30, 00, new TimeSpan(3, 0, 0)); | ||
var encoding = PayloadGenerator.CalendarEvent.EventEncoding.Universal; | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent, encoding); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DESCRIPTION:A small party for the new QRCoder. Bring some beer!{Environment.NewLine}LOCATION:Programmer's paradise, Beachtown, Paradise{Environment.NewLine}DTSTART:20160103T090000Z{Environment.NewLine}DTEND:20160103T113000Z{Environment.NewLine}END:VEVENT"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void calendarevent_should_build_allday() | ||
{ | ||
var subject = "Release party"; | ||
var description = "A small party for the new QRCoder. Bring some beer!"; | ||
var location = "Programmer's paradise, Beachtown, Paradise"; | ||
var alldayEvent = true; | ||
var begin = new DateTime(2016, 01, 03); | ||
var end = new DateTime(2016, 01, 03); | ||
var encoding = PayloadGenerator.CalendarEvent.EventEncoding.Universal; | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent, encoding); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DESCRIPTION:A small party for the new QRCoder. Bring some beer!{Environment.NewLine}LOCATION:Programmer's paradise, Beachtown, Paradise{Environment.NewLine}DTSTART:20160103{Environment.NewLine}DTEND:20160103{Environment.NewLine}END:VEVENT"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void calendarevent_should_care_empty_fields() | ||
{ | ||
var subject = "Release party"; | ||
var description = ""; | ||
var location = string.Empty; | ||
var alldayEvent = false; | ||
var begin = new DateTime(2016, 01, 03, 12, 00, 00); | ||
var end = new DateTime(2016, 01, 03, 14, 30, 0); | ||
var encoding = PayloadGenerator.CalendarEvent.EventEncoding.Universal; | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent, encoding); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DTSTART:20160103T120000{Environment.NewLine}DTEND:20160103T143000{Environment.NewLine}END:VEVENT"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void calendarevent_should_add_unused_params() | ||
{ | ||
var subject = "Release party"; | ||
var description = "A small party for the new QRCoder. Bring some beer!"; | ||
var location = "Programmer's paradise, Beachtown, Paradise"; | ||
var alldayEvent = false; | ||
var begin = new DateTime(2016, 01, 03, 12, 00, 00); | ||
var end = new DateTime(2016, 01, 03, 14, 30, 0); | ||
|
||
var generator = new PayloadGenerator.CalendarEvent(subject, description, location, begin, end, alldayEvent); | ||
|
||
generator.ToString().ShouldBe($"BEGIN:VEVENT{Environment.NewLine}SUMMARY:Release party{Environment.NewLine}DESCRIPTION:A small party for the new QRCoder. Bring some beer!{Environment.NewLine}LOCATION:Programmer's paradise, Beachtown, Paradise{Environment.NewLine}DTSTART:20160103T120000{Environment.NewLine}DTEND:20160103T143000{Environment.NewLine}END:VEVENT"); | ||
} | ||
} |
Oops, something went wrong.