|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Globalization; |
3 | 4 | using System.Linq;
|
4 | 5 | using Xunit;
|
5 | 6 |
|
@@ -73,6 +74,10 @@ public void GetSetString()
|
73 | 74 | props.SetString("foo", null);
|
74 | 75 | Assert.Null(props.GetString("foo"));
|
75 | 76 | Assert.Equal(1, props.Items.Count);
|
| 77 | + |
| 78 | + props.SetString("doesntexist", null); |
| 79 | + Assert.False(props.Items.ContainsKey("doesntexist")); |
| 80 | + Assert.Equal(1, props.Items.Count); |
76 | 81 | }
|
77 | 82 |
|
78 | 83 | [Fact]
|
@@ -203,5 +208,94 @@ public void AllowRefresh_Test()
|
203 | 208 | props.Items.Clear();
|
204 | 209 | Assert.Null(props.AllowRefresh);
|
205 | 210 | }
|
| 211 | + |
| 212 | + [Fact] |
| 213 | + public void SetDateTimeOffset() |
| 214 | + { |
| 215 | + var props = new MyAuthenticationProperties(); |
| 216 | + |
| 217 | + props.SetDateTimeOffset("foo", new DateTimeOffset(new DateTime(2018, 03, 19, 12, 34, 56, DateTimeKind.Utc))); |
| 218 | + Assert.Equal("Mon, 19 Mar 2018 12:34:56 GMT", props.Items["foo"]); |
| 219 | + |
| 220 | + props.SetDateTimeOffset("foo", null); |
| 221 | + Assert.False(props.Items.ContainsKey("foo")); |
| 222 | + |
| 223 | + props.SetDateTimeOffset("doesnotexist", null); |
| 224 | + Assert.False(props.Items.ContainsKey("doesnotexist")); |
| 225 | + } |
| 226 | + |
| 227 | + [Fact] |
| 228 | + public void GetDateTimeOffset() |
| 229 | + { |
| 230 | + var props = new MyAuthenticationProperties(); |
| 231 | + var dateTimeOffset = new DateTimeOffset(new DateTime(2018, 03, 19, 12, 34, 56, DateTimeKind.Utc)); |
| 232 | + |
| 233 | + props.Items["foo"] = dateTimeOffset.ToString("r", CultureInfo.InvariantCulture); |
| 234 | + Assert.Equal(dateTimeOffset, props.GetDateTimeOffset("foo")); |
| 235 | + |
| 236 | + props.Items.Remove("foo"); |
| 237 | + Assert.Null(props.GetDateTimeOffset("foo")); |
| 238 | + |
| 239 | + props.Items["foo"] = "BAR"; |
| 240 | + Assert.Null(props.GetDateTimeOffset("foo")); |
| 241 | + Assert.Equal("BAR", props.Items["foo"]); |
| 242 | + } |
| 243 | + |
| 244 | + [Fact] |
| 245 | + public void SetBool() |
| 246 | + { |
| 247 | + var props = new MyAuthenticationProperties(); |
| 248 | + |
| 249 | + props.SetBool("foo", true); |
| 250 | + Assert.Equal(true.ToString(), props.Items["foo"]); |
| 251 | + |
| 252 | + props.SetBool("foo", false); |
| 253 | + Assert.Equal(false.ToString(), props.Items["foo"]); |
| 254 | + |
| 255 | + props.SetBool("foo", null); |
| 256 | + Assert.False(props.Items.ContainsKey("foo")); |
| 257 | + } |
| 258 | + |
| 259 | + [Fact] |
| 260 | + public void GetBool() |
| 261 | + { |
| 262 | + var props = new MyAuthenticationProperties(); |
| 263 | + |
| 264 | + props.Items["foo"] = true.ToString(); |
| 265 | + Assert.True(props.GetBool("foo")); |
| 266 | + |
| 267 | + props.Items["foo"] = false.ToString(); |
| 268 | + Assert.False(props.GetBool("foo")); |
| 269 | + |
| 270 | + props.Items["foo"] = null; |
| 271 | + Assert.Null(props.GetBool("foo")); |
| 272 | + |
| 273 | + props.Items["foo"] = "BAR"; |
| 274 | + Assert.Null(props.GetBool("foo")); |
| 275 | + Assert.Equal("BAR", props.Items["foo"]); |
| 276 | + } |
| 277 | + |
| 278 | + public class MyAuthenticationProperties : AuthenticationProperties |
| 279 | + { |
| 280 | + public new DateTimeOffset? GetDateTimeOffset(string key) |
| 281 | + { |
| 282 | + return base.GetDateTimeOffset(key); |
| 283 | + } |
| 284 | + |
| 285 | + public new void SetDateTimeOffset(string key, DateTimeOffset? value) |
| 286 | + { |
| 287 | + base.SetDateTimeOffset(key, value); |
| 288 | + } |
| 289 | + |
| 290 | + public new void SetBool(string key, bool? value) |
| 291 | + { |
| 292 | + base.SetBool(key, value); |
| 293 | + } |
| 294 | + |
| 295 | + public new bool? GetBool(string key) |
| 296 | + { |
| 297 | + return base.GetBool(key); |
| 298 | + } |
| 299 | + } |
206 | 300 | }
|
207 | 301 | }
|
0 commit comments