Skip to content

Commit a4473c3

Browse files
committed
Fixing OAuth1 tests
1 parent 193b6ca commit a4473c3

File tree

1 file changed

+20
-76
lines changed

1 file changed

+20
-76
lines changed

test/RestSharp.Tests/OAuth1AuthenticatorTests.cs

Lines changed: 20 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -70,81 +70,25 @@ public void Authenticate_ShouldAddSignatureToRequestAsSeparateParameters_OnUrlOr
7070

7171
// Assert
7272
var parameters = request.Parameters;
73-
74-
Assert.NotNull(
75-
parameters.FirstOrDefault(
76-
x => x.Type == ParameterType.GetOrPost &&
77-
x.Name == "x_auth_username" &&
78-
(string)x.Value == "ClientUsername" &&
79-
x.ContentType == null
80-
)
81-
);
82-
83-
Assert.NotNull(
84-
parameters.FirstOrDefault(
85-
x => x.Type == ParameterType.GetOrPost &&
86-
x.Name == "x_auth_password" &&
87-
(string)x.Value == "ClientPassword" &&
88-
x.ContentType == null
89-
)
90-
);
91-
92-
Assert.NotNull(
93-
parameters.FirstOrDefault(
94-
x => x.Type == ParameterType.GetOrPost && x.Name == "x_auth_mode" && (string)x.Value == "client_auth" && x.ContentType == null
95-
)
96-
);
97-
98-
Assert.NotNull(
99-
parameters.FirstOrDefault(
100-
x => x.Type == ParameterType.GetOrPost &&
101-
x.Name == "oauth_consumer_key" &&
102-
(string)x.Value == "ConsumerKey" &&
103-
x.ContentType == null
104-
)
105-
);
106-
107-
Assert.NotNull(
108-
parameters.FirstOrDefault(
109-
x => x.Type == ParameterType.GetOrPost &&
110-
x.Name == "oauth_signature" &&
111-
!string.IsNullOrWhiteSpace((string)x.Value) &&
112-
x.ContentType == null
113-
)
114-
);
115-
116-
Assert.NotNull(
117-
parameters.FirstOrDefault(
118-
x => x.Type == ParameterType.GetOrPost &&
119-
x.Name == "oauth_signature_method" &&
120-
(string)x.Value == "PLAINTEXT" &&
121-
x.ContentType == null
122-
)
123-
);
124-
125-
Assert.NotNull(
126-
parameters.FirstOrDefault(
127-
x => x.Type == ParameterType.GetOrPost && x.Name == "oauth_version" && (string)x.Value == "Version" && x.ContentType == null
128-
)
129-
);
130-
131-
Assert.NotNull(
132-
parameters.FirstOrDefault(
133-
x => x.Type == ParameterType.GetOrPost &&
134-
x.Name == "oauth_nonce" &&
135-
!string.IsNullOrWhiteSpace((string)x.Value) &&
136-
x.ContentType == null
137-
)
138-
);
139-
140-
Assert.NotNull(
141-
parameters.FirstOrDefault(
142-
x => x.Type == ParameterType.GetOrPost &&
143-
x.Name == "oauth_timestamp" &&
144-
!string.IsNullOrWhiteSpace((string)x.Value) &&
145-
x.ContentType == null
146-
)
147-
);
73+
ParameterShouldBe("x_auth_username", "ClientUsername");
74+
ParameterShouldBe("x_auth_password", "ClientPassword");
75+
ParameterShouldBe("x_auth_mode", "client_auth");
76+
ParameterShouldBe("oauth_consumer_key", "ConsumerKey");
77+
ParameterShouldHaveValue("oauth_signature");
78+
ParameterShouldBe("oauth_signature_method", "PLAINTEXT");
79+
ParameterShouldBe("oauth_version", "Version");
80+
ParameterShouldHaveValue("oauth_nonce");
81+
ParameterShouldHaveValue("oauth_timestamp");
82+
83+
void ParameterShould(string name, Func<Parameter, bool> check) {
84+
var parameter = parameters.FirstOrDefault(x => x.Type == ParameterType.GetOrPost && x.Name == name);
85+
parameter.Should().NotBeNull();
86+
check(parameter).Should().BeTrue();
87+
}
88+
89+
void ParameterShouldBe(string name, string value) => ParameterShould(name, x => (string)x.Value == value);
90+
91+
void ParameterShouldHaveValue(string name) => ParameterShould(name, x => !string.IsNullOrWhiteSpace((string)x.Value));
14892
}
14993

15094
[Theory]
@@ -200,4 +144,4 @@ public void Authenticate_ShouldAllowEmptyConsumerSecret_OnHttpAuthorizationHeade
200144
Assert.Contains("OAuth", value!);
201145
Assert.Contains($"oauth_signature=\"{OAuthTools.UrlEncodeStrict("&")}", value);
202146
}
203-
}
147+
}

0 commit comments

Comments
 (0)