diff options
| author | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
|---|---|---|
| committer | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
| commit | 1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch) | |
| tree | 4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs | |
| parent | 42d66bcab8262c7b8b2452615df535e694a3ec1c (diff) | |
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs')
| -rw-r--r-- | slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs new file mode 100644 index 0000000..b7a3540 --- /dev/null +++ b/slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs @@ -0,0 +1,45 @@ +using System;
+using System.Collections.Specialized;
+using Marina.Presentation;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class PayloadKeyTest {
+ [Test]
+ public void Should_be_able_to_convert_an_item_from_the_payload_into_an_item_of_the_correct_type( ) {
+ string key = "DID";
+ int expectedValue = 1;
+
+ NameValueCollection payload = new NameValueCollection( );
+ payload.Add( key, expectedValue.ToString( ) );
+
+ int actualValue = CreateSUT< int >( key ).ParseFrom( payload );
+ Assert.AreEqual( expectedValue, actualValue );
+ }
+
+ [Test]
+ [ExpectedException( typeof( Exception ) )]
+ public void Should_not_be_able_to_parse_if_the_item_in_the_payload_does_not_match_the_data_type_for_the_key( ) {
+ NameValueCollection payload = new NameValueCollection( );
+ payload.Add( "DID", "NotAnInt" );
+ CreateSUT< int >( "DID" ).ParseFrom( payload );
+ }
+
+ [Test]
+ public void Should_be_able_to_implicitly_cast_to_a_string( ) {
+ string implictlyCasted = CreateSUT< int >( "DID" );
+ Assert.AreEqual( "DID", implictlyCasted );
+ }
+
+ [Test]
+ [ExpectedException( typeof( PayloadKeyNotFoundException ) )]
+ public void Should_return_default_value_if_key_is_not_in_payload( ) {
+ CreateSUT< string >( "NOTINPAYLOAD" ).ParseFrom( new NameValueCollection( ) );
+ }
+
+ private PayloadKey< T > CreateSUT< T >( string key ) {
+ return new PayloadKey< T >( key );
+ }
+ }
+}
\ No newline at end of file |
