Skip to content

Commit e24e20c

Browse files
committed
Added more InternetAddress[List]TypeConverter tests
1 parent 5b2406f commit e24e20c

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

UnitTests/InternetAddressListTypeConverterTests.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void TestIsValid ()
4949
}
5050

5151
[Test]
52-
public void TestConvertFromValid ()
52+
public void TestConvertValid ()
5353
{
5454
var converter = TypeDescriptor.GetConverter (typeof (InternetAddressList));
5555
var result = converter.ConvertFrom ("Skye <[email protected]>, Leo Fitz <[email protected]>, Melinda May <[email protected]>");
@@ -60,20 +60,25 @@ public void TestConvertFromValid ()
6060
Assert.That (list[0].Name, Is.EqualTo ("Skye"));
6161
Assert.That (list[1].Name, Is.EqualTo ("Leo Fitz"));
6262
Assert.That (list[2].Name, Is.EqualTo ("Melinda May"));
63+
64+
var text = converter.ConvertTo (list, typeof (string));
65+
Assert.That (text, Is.EqualTo ("\"Skye\" <[email protected]>, \"Leo Fitz\" <[email protected]>, \"Melinda May\" <[email protected]>"));
6366
}
6467

6568
[Test]
66-
public void TestIsNotValid ()
69+
public void TestConvertNotValid ()
6770
{
6871
var converter = TypeDescriptor.GetConverter (typeof (InternetAddressList));
69-
Assert.That (converter.IsValid (""), Is.False);
72+
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
73+
Assert.Throws<NotSupportedException> (() => converter.ConvertFrom (5));
74+
Assert.Throws<NotSupportedException> (() => converter.ConvertTo (new InternetAddressList (), typeof (int)));
7075
}
7176

7277
[Test]
73-
public void TestConvertFromNotValid ()
78+
public void TestIsNotValid ()
7479
{
7580
var converter = TypeDescriptor.GetConverter (typeof (InternetAddressList));
76-
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
81+
Assert.That (converter.IsValid (""), Is.False);
7782
}
7883
}
7984
}

UnitTests/InternetAddressTypeConverterTests.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,38 @@ public void TestCanConvert ()
4444
public void TestIsValid ()
4545
{
4646
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
47-
Assert.That (converter.IsValid ("Jeffrey Stedfast <[email protected]>"), Is.True);
47+
Assert.That (converter.IsValid ("Unit Tests <[email protected]>"), Is.True);
4848
}
4949

5050
[Test]
51-
public void TestConvertFromValid ()
51+
public void TestConvertValid ()
5252
{
5353
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
54-
var result = converter.ConvertFrom ("Jeffrey Stedfast <[email protected]>");
54+
var result = converter.ConvertFrom ("Unit Tests <[email protected]>");
5555
Assert.That (result, Is.InstanceOf (typeof (MailboxAddress)));
5656

5757
var mailbox = (MailboxAddress) result;
58-
Assert.That (mailbox.Name, Is.EqualTo ("Jeffrey Stedfast"));
59-
Assert.That (mailbox.Address, Is.EqualTo ("[email protected]"));
58+
Assert.That (mailbox.Name, Is.EqualTo ("Unit Tests"));
59+
Assert.That (mailbox.Address, Is.EqualTo ("[email protected]"));
60+
61+
var text = converter.ConvertTo (mailbox, typeof (string));
62+
Assert.That (text, Is.EqualTo ("\"Unit Tests\" <[email protected]>"));
6063
}
6164

6265
[Test]
63-
public void TestIsNotValid ()
66+
public void TestConvertNotValid ()
6467
{
6568
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
66-
Assert.That (converter.IsValid (""), Is.False);
69+
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
70+
Assert.Throws<NotSupportedException> (() => converter.ConvertFrom (5));
71+
Assert.Throws<NotSupportedException> (() => converter.ConvertTo (new MailboxAddress ("Unit Tests", "[email protected]"), typeof (int)));
6772
}
6873

6974
[Test]
70-
public void TestConvertFromNotValid ()
75+
public void TestIsNotValid ()
7176
{
7277
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
73-
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
78+
Assert.That (converter.IsValid (""), Is.False);
7479
}
7580
}
7681
}

0 commit comments

Comments
 (0)