@@ -76,63 +76,69 @@ public void Save_NullSession_NonEmptyDictionary_Throws()
76
76
} ) ;
77
77
}
78
78
79
+ public static TheoryData < object , Type > InvalidTypes
80
+ {
81
+ get
82
+ {
83
+ return new TheoryData < object , Type >
84
+ {
85
+ { new object ( ) , typeof ( object ) } ,
86
+ { new object [ 3 ] , typeof ( object ) } ,
87
+ { new TestItem ( ) , typeof ( TestItem ) } ,
88
+ { new List < TestItem > ( ) , typeof ( TestItem ) } ,
89
+ { new Dictionary < string , TestItem > ( ) , typeof ( TestItem ) } ,
90
+ { new Dictionary < object , string > ( ) , typeof ( object ) } ,
91
+ { new Dictionary < TestItem , TestItem > ( ) , typeof ( TestItem ) }
92
+ } ;
93
+ }
94
+ }
95
+
79
96
[ Theory ]
80
97
[ MemberData ( nameof ( InvalidTypes ) ) ]
81
- public void EnsureObjectCanBeSerialized_InvalidType_Throws ( string key , object value , Type type )
98
+ public void EnsureObjectCanBeSerialized_InvalidType_Throws ( object value , Type type )
82
99
{
83
100
// Arrange
84
101
var testProvider = new SessionStateTempDataProvider ( ) ;
85
102
86
103
// Act & Assert
87
104
var exception = Assert . Throws < InvalidOperationException > ( ( ) =>
88
105
{
89
- testProvider . EnsureObjectCanBeSerialized ( new Dictionary < string , object > { { key , value } } ) ;
106
+ testProvider . EnsureObjectCanBeSerialized ( value ) ;
90
107
} ) ;
91
108
Assert . Equal ( $ "The type { type } cannot be serialized to Session by '{ typeof ( SessionStateTempDataProvider ) . FullName } '.",
92
109
exception . Message ) ;
93
110
}
94
111
95
- [ Theory ]
96
- [ MemberData ( nameof ( ValidTypes ) ) ]
97
- public void EnsureObjectCanBeSerialized_ValidType_DoesNotThrow ( string key , object value )
98
- {
99
- // Arrange
100
- var testProvider = new SessionStateTempDataProvider ( ) ;
101
-
102
- // Act & Assert (Does not throw)
103
- testProvider . EnsureObjectCanBeSerialized ( new Dictionary < string , object > { { key , value } } ) ;
104
- }
105
-
106
- public static TheoryData < string , object , Type > InvalidTypes
112
+ public static TheoryData < object > ValidTypes
107
113
{
108
114
get
109
115
{
110
- return new TheoryData < string , object , Type >
116
+ return new TheoryData < object >
111
117
{
112
- { "Object" , new object ( ) , typeof ( object ) } ,
113
- { "ObjectArray" , new object [ 3 ] , typeof ( object ) } ,
114
- { "TestItem" , new TestItem ( ) , typeof ( TestItem ) } ,
115
- { "ListTestItem" , new List < TestItem > ( ) , typeof ( TestItem ) } ,
116
- { "DictTestItem" , new Dictionary < string , TestItem > ( ) , typeof ( TestItem ) }
118
+ { 10 } ,
119
+ { new int [ ] { 10 , 20 } } ,
120
+ { "FooValue" } ,
121
+ { new Dictionary < string , int > ( ) } ,
122
+ { new Uri ( "http://Foo" ) } ,
123
+ { Guid . NewGuid ( ) } ,
124
+ { new List < string > { "foo" , "bar" } } ,
125
+ { new DateTimeOffset ( ) } ,
126
+ { 100.1m } ,
127
+ { new Dictionary < Uri , Guid > ( ) } ,
128
+ { new Uri [ ] { new Uri ( "http://Foo" ) , new Uri ( "http://Bar" ) } }
117
129
} ;
118
130
}
119
131
}
120
132
121
- public static TheoryData < string , object > ValidTypes
133
+ [ Theory ]
134
+ [ MemberData ( nameof ( ValidTypes ) ) ]
135
+ public void EnsureObjectCanBeSerialized_ValidType_DoesNotThrow ( object value )
122
136
{
123
- get
124
- {
125
- return new TheoryData < string , object >
126
- {
127
- { "int" , 10 } ,
128
- { "IntArray" , new int [ ] { 10 , 20 } } ,
129
- { "string" , "FooValue" } ,
130
- { "SimpleDict" , new Dictionary < string , int > ( ) } ,
131
- { "Uri" , new Uri ( "http://Foo" ) } ,
132
- { "Guid" , Guid . NewGuid ( ) } ,
133
- { "SimpleList" , new List < string > { "foo" , "bar" } }
134
- } ;
135
- }
137
+ // Arrange
138
+ var testProvider = new SessionStateTempDataProvider ( ) ;
139
+
140
+ // Act & Assert (Does not throw)
141
+ testProvider . EnsureObjectCanBeSerialized ( value ) ;
136
142
}
137
143
138
144
private class TestItem
0 commit comments