Skip to content

Commit

Permalink
Added more InternetAddress[List]TypeConverter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Dec 22, 2024
1 parent 5b2406f commit e24e20c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
15 changes: 10 additions & 5 deletions UnitTests/InternetAddressListTypeConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void TestIsValid ()
}

[Test]
public void TestConvertFromValid ()
public void TestConvertValid ()
{
var converter = TypeDescriptor.GetConverter (typeof (InternetAddressList));
var result = converter.ConvertFrom ("Skye <[email protected]>, Leo Fitz <[email protected]>, Melinda May <[email protected]>");
Expand All @@ -60,20 +60,25 @@ public void TestConvertFromValid ()
Assert.That (list[0].Name, Is.EqualTo ("Skye"));
Assert.That (list[1].Name, Is.EqualTo ("Leo Fitz"));
Assert.That (list[2].Name, Is.EqualTo ("Melinda May"));

var text = converter.ConvertTo (list, typeof (string));
Assert.That (text, Is.EqualTo ("\"Skye\" <[email protected]>, \"Leo Fitz\" <[email protected]>, \"Melinda May\" <[email protected]>"));
}

[Test]
public void TestIsNotValid ()
public void TestConvertNotValid ()
{
var converter = TypeDescriptor.GetConverter (typeof (InternetAddressList));
Assert.That (converter.IsValid (""), Is.False);
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
Assert.Throws<NotSupportedException> (() => converter.ConvertFrom (5));
Assert.Throws<NotSupportedException> (() => converter.ConvertTo (new InternetAddressList (), typeof (int)));
}

[Test]
public void TestConvertFromNotValid ()
public void TestIsNotValid ()
{
var converter = TypeDescriptor.GetConverter (typeof (InternetAddressList));
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
Assert.That (converter.IsValid (""), Is.False);
}
}
}
23 changes: 14 additions & 9 deletions UnitTests/InternetAddressTypeConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,38 @@ public void TestCanConvert ()
public void TestIsValid ()
{
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
Assert.That (converter.IsValid ("Jeffrey Stedfast <[email protected]>"), Is.True);
Assert.That (converter.IsValid ("Unit Tests <[email protected]>"), Is.True);
}

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

var mailbox = (MailboxAddress) result;
Assert.That (mailbox.Name, Is.EqualTo ("Jeffrey Stedfast"));
Assert.That (mailbox.Address, Is.EqualTo ("[email protected]"));
Assert.That (mailbox.Name, Is.EqualTo ("Unit Tests"));
Assert.That (mailbox.Address, Is.EqualTo ("[email protected]"));

var text = converter.ConvertTo (mailbox, typeof (string));
Assert.That (text, Is.EqualTo ("\"Unit Tests\" <[email protected]>"));
}

[Test]
public void TestIsNotValid ()
public void TestConvertNotValid ()
{
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
Assert.That (converter.IsValid (""), Is.False);
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
Assert.Throws<NotSupportedException> (() => converter.ConvertFrom (5));
Assert.Throws<NotSupportedException> (() => converter.ConvertTo (new MailboxAddress ("Unit Tests", "[email protected]"), typeof (int)));
}

[Test]
public void TestConvertFromNotValid ()
public void TestIsNotValid ()
{
var converter = TypeDescriptor.GetConverter (typeof (InternetAddress));
Assert.Throws<ParseException> (() => converter.ConvertFrom (""));
Assert.That (converter.IsValid (""), Is.False);
}
}
}

0 comments on commit e24e20c

Please sign in to comment.