-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJwtBearerOptionsPostConfigurationTests.cs
More file actions
94 lines (67 loc) · 2.7 KB
/
Copy pathJwtBearerOptionsPostConfigurationTests.cs
File metadata and controls
94 lines (67 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Invio.Xunit;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Xunit;
namespace Invio.Extensions.Authentication.JwtBearer {
[UnitTest]
public sealed class JwtBearerOptionsPostConfigurationTests {
[Fact]
public void Constructor_NullOptions() {
// Act
var exception = Record.Exception(
() => new JwtBearerOptionsPostConfiguration(null)
);
// Assert
Assert.IsType<ArgumentNullException>(exception);
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("name")]
public void PostConfigure_NullBearerOptions(string name) {
// Arrange
var configuration = CreatePostConfiguration();
// Act
var exception = Record.Exception(
() => configuration.PostConfigure(name, null)
);
// Assert
Assert.IsType<ArgumentNullException>(exception);
}
public static IEnumerable<object[]> PostConfigure_AppliesEventsWrapper_MemberData {
get {
var tuples = ImmutableList.Create<(string, JwtBearerOptions)>(
("name", new JwtBearerOptions { Events = null }),
(null, new JwtBearerOptions { Events = new JwtBearerEvents() }),
("name", new JwtBearerOptions { EventsType = typeof(JwtBearerEvents) })
);
return tuples.Select(tuple => new object[] { tuple.Item1, tuple.Item2 });
}
}
[Theory]
[MemberData(nameof(PostConfigure_AppliesEventsWrapper_MemberData))]
public void PostConfigure_AppliesEventsWrapper(
string name,
JwtBearerOptions bearerOptions) {
// Arrange
var options = new JwtBearerQueryStringOptions();
var configuration = CreatePostConfiguration(options);
// Act
configuration.PostConfigure(name, bearerOptions);
// Assert
var typed = Assert.IsType<QueryStringJwtBearerEventsWrapper>(bearerOptions.Events);
Assert.Equal(options.QueryStringParameterName, typed.QueryStringParameterName);
Assert.Null(bearerOptions.EventsType);
}
private IPostConfigureOptions<JwtBearerOptions> CreatePostConfiguration(
JwtBearerQueryStringOptions options = null) {
return new JwtBearerOptionsPostConfiguration(
Options.Create(options ?? new JwtBearerQueryStringOptions())
);
}
}
}