Skip to content

Commit

Permalink
Refactoring tests to xUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Dec 6, 2021
1 parent 603c3c4 commit 5e1ccb1
Show file tree
Hide file tree
Showing 98 changed files with 7,738 additions and 8,823 deletions.
88 changes: 88 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

[*]

# ReSharper properties
resharper_align_multiline_binary_expressions_chain = false
resharper_blank_lines_around_single_line_auto_property = 0
resharper_blank_lines_around_single_line_field = 0
resharper_blank_lines_before_multiline_statements = 1
resharper_csharp_blank_lines_around_single_line_invocable = 1
resharper_csharp_empty_block_style = together
resharper_csharp_int_align_comments = true
resharper_csharp_keep_blank_lines_in_code = 1
resharper_csharp_keep_blank_lines_in_declarations = 1
resharper_csharp_wrap_after_declaration_lpar = true
resharper_csharp_wrap_after_invocation_lpar = true
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_before_declaration_rpar = true
resharper_csharp_wrap_before_invocation_rpar = true
resharper_csharp_wrap_parameters_style = chop_if_long
resharper_int_align_assignments = true
resharper_int_align_fields = true
resharper_int_align_nested_ternary = true
resharper_int_align_parameters = true
resharper_int_align_properties = true
resharper_int_align_property_patterns = true
resharper_int_align_switch_expressions = true
resharper_int_align_switch_sections = true
resharper_int_align_variables = true
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_expr_method_on_single_line = false
resharper_place_expr_property_on_single_line = true
resharper_place_simple_initializer_on_single_line = false
resharper_show_autodetect_configure_formatting_tip = false
resharper_use_indent_from_vs = false
resharper_wrap_array_initializer_style = chop_always
resharper_wrap_before_arrow_with_expressions = true
resharper_wrap_chained_binary_expressions = chop_if_long
resharper_wrap_object_and_collection_initializer_style = chop_always

# Microsoft .NET properties
csharp_using_directive_placement = outside_namespace
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = none
csharp_preferred_modifier_order = public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True
dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field
dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef
dotnet_naming_rule.unity_serialized_field_rule.severity = warning
dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style
dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = *
dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds =
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field
dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_require_accessibility_modifiers = never:suggestion

# ReSharper inspection severities
resharper_arrange_redundant_parentheses_highlighting = hint
resharper_arrange_this_qualifier_highlighting = hint
resharper_arrange_type_member_modifiers_highlighting = hint
resharper_arrange_type_modifiers_highlighting = hint
resharper_built_in_type_reference_style_for_member_access_highlighting = hint
resharper_built_in_type_reference_style_highlighting = hint
resharper_redundant_base_qualifier_highlighting = warning
resharper_suggest_var_or_type_built_in_types_highlighting = hint
resharper_suggest_var_or_type_elsewhere_highlighting = hint
resharper_suggest_var_or_type_simple_types_highlighting = hint
resharper_web_config_module_not_resolved_highlighting = warning
resharper_web_config_type_not_resolved_highlighting = warning
resharper_web_config_wrong_module_highlighting = warning

[*.{appxmanifest,asax,ascx,aspx,axaml,build,cg,cginc,compute,cs,cshtml,dtd,fs,fsi,fsscript,fsx,hlsl,hlsli,hlslinc,master,ml,mli,nuspec,paml,razor,resw,resx,shader,skin,usf,ush,vb,xaml,xamlx,xoml,xsd}]
indent_style = space
indent_size = 4
tab_width = 4
10 changes: 10 additions & 0 deletions props/Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName)</RepoRoot>
<AssemblyOriginatorKeyFile>$(RepoRoot)\RestSharp.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
20 changes: 7 additions & 13 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'RestSharp.sln'))\props\Common.props" />
<PropertyGroup>
<PackageReleaseNotes>For full release notes see https://github.com/restsharp/RestSharp/blob/master/releasenotes.md</PackageReleaseNotes>
<PackageIcon>restsharp.png</PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>http://restsharp.dev</PackageProjectUrl>
<PackageProjectUrl>https://restsharp.dev</PackageProjectUrl>
<RepositoryUrl>https://github.com/restsharp/RestSharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Description>Simple REST and HTTP API Client</Description>
<Authors>John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community</Authors>
<AssemblyOriginatorKeyFile>..\..\RestSharp.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
<UpdateVersionProperties>true</UpdateVersionProperties>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,14 +25,10 @@
</ItemGroup>

<ItemGroup>
<None Include="..\..\restsharp.png" Pack="true" PackagePath="\"/>
<None Include="$(RepoRoot)\restsharp.png" Pack="true" PackagePath="\"/>
<Using Remove="System.Net.Http"/>
</ItemGroup>

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<Target Name="CustomVersion" AfterTargets="MinVer">
<PropertyGroup>
<FileVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch)</FileVersion>
Expand Down
56 changes: 19 additions & 37 deletions src/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
using RestSharp.Extensions;
using RestSharp.Validation;

namespace RestSharp.Authenticators.OAuth
{
namespace RestSharp.Authenticators.OAuth {
/// <summary>
/// A class to encapsulate OAuth authentication flow.
/// </summary>
sealed class OAuthWorkflow
{
sealed class OAuthWorkflow {
public string Version { get; set; }

public string ConsumerKey { get; set; }
Expand Down Expand Up @@ -64,8 +62,7 @@ sealed class OAuthWorkflow
/// <param name="method">The HTTP method for the intended request</param>
/// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
/// <returns></returns>
public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection parameters)
{
public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection parameters) {
ValidateTokenRequestState();

var allParameters = new WebPairCollection();
Expand All @@ -79,8 +76,7 @@ public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection pa

var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, allParameters);

return new OAuthParameters
{
return new OAuthParameters {
Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret),
Parameters = authParameters
};
Expand All @@ -93,8 +89,7 @@ public OAuthParameters BuildRequestTokenInfo(string method, WebPairCollection pa
/// </summary>
/// <param name="method">The HTTP method for the intended request</param>
/// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
public OAuthParameters BuildAccessTokenSignature(string method, WebPairCollection parameters)
{
public OAuthParameters BuildAccessTokenSignature(string method, WebPairCollection parameters) {
ValidateAccessRequestState();

var allParameters = new WebPairCollection();
Expand All @@ -109,8 +104,7 @@ public OAuthParameters BuildAccessTokenSignature(string method, WebPairCollectio

var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), allParameters);

return new OAuthParameters
{
return new OAuthParameters {
Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret),
Parameters = authParameters
};
Expand All @@ -123,8 +117,7 @@ public OAuthParameters BuildAccessTokenSignature(string method, WebPairCollectio
/// </summary>
/// <param name="method">The HTTP method for the intended request</param>
/// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
public OAuthParameters BuildClientAuthAccessTokenSignature(string method, WebPairCollection parameters)
{
public OAuthParameters BuildClientAuthAccessTokenSignature(string method, WebPairCollection parameters) {
ValidateClientAuthAccessRequestState();

var allParameters = new WebPairCollection();
Expand All @@ -139,15 +132,13 @@ public OAuthParameters BuildClientAuthAccessTokenSignature(string method, WebPai

var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), allParameters);

return new OAuthParameters
{
return new OAuthParameters {
Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret),
Parameters = authParameters
};
}

public OAuthParameters BuildProtectedResourceSignature(string method, WebPairCollection parameters, string url)
{
public OAuthParameters BuildProtectedResourceSignature(string method, WebPairCollection parameters, string url) {
ValidateProtectedResourceState();

var allParameters = new WebPairCollection();
Expand All @@ -167,42 +158,35 @@ public OAuthParameters BuildProtectedResourceSignature(string method, WebPairCol

var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, allParameters);

return new OAuthParameters
{
return new OAuthParameters {
Signature = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret),
Parameters = authParameters
};
}

void ValidateTokenRequestState()
{
void ValidateTokenRequestState() {
Ensure.NotEmpty(RequestTokenUrl, nameof(RequestTokenUrl));
Ensure.NotEmpty(ConsumerKey, nameof(ConsumerKey));
}

void ValidateAccessRequestState()
{
void ValidateAccessRequestState() {
Ensure.NotEmpty(AccessTokenUrl, nameof(AccessTokenUrl));
Ensure.NotEmpty(ConsumerKey, nameof(ConsumerKey));
Ensure.NotEmpty(Token, nameof(Token));
}

void ValidateClientAuthAccessRequestState()
{
void ValidateClientAuthAccessRequestState() {
Ensure.NotEmpty(AccessTokenUrl, nameof(AccessTokenUrl));
Ensure.NotEmpty(ConsumerKey, nameof(ConsumerKey));
Ensure.NotEmpty(ClientUsername, nameof(ClientUsername));
}

void ValidateProtectedResourceState()
{
void ValidateProtectedResourceState() {
Ensure.NotEmpty(ConsumerKey, nameof(ConsumerKey));
}

WebPairCollection GenerateAuthParameters(string timestamp, string nonce)
{
var authParameters = new WebPairCollection
{
WebPairCollection GenerateAuthParameters(string timestamp, string nonce) {
var authParameters = new WebPairCollection {
new WebPair("oauth_consumer_key", ConsumerKey),
new WebPair("oauth_nonce", nonce),
new WebPair("oauth_signature_method", SignatureMethod.ToRequestValue()),
Expand All @@ -222,8 +206,7 @@ WebPairCollection GenerateAuthParameters(string timestamp, string nonce)
}

WebPairCollection GenerateXAuthParameters(string timestamp, string nonce)
=> new WebPairCollection
{
=> new WebPairCollection {
new WebPair("x_auth_username", ClientUsername),
new WebPair("x_auth_password", ClientPassword),
new WebPair("x_auth_mode", "client_auth"),
Expand All @@ -234,10 +217,9 @@ WebPairCollection GenerateXAuthParameters(string timestamp, string nonce)
new WebPair("oauth_version", Version ?? "1.0")
};

internal class OAuthParameters
{
internal class OAuthParameters {
public WebPairCollection Parameters { get; set; }
public string Signature { get; set; }
}
}
}
}
5 changes: 2 additions & 3 deletions src/RestSharp/Extensions/ResponseStatusExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Net;
using static System.Net.WebExceptionStatus;

Expand All @@ -31,8 +30,8 @@ public static WebException ToWebException(this ResponseStatus responseStatus)
{
ResponseStatus.None => new WebException("The request could not be processed.", ServerProtocolViolation),
ResponseStatus.Error => new WebException("An error occurred while processing the request.", ServerProtocolViolation),
ResponseStatus.TimedOut => new WebException("The request timed-out.", Timeout),
ResponseStatus.Aborted => new WebException("The request was aborted.", Timeout),
ResponseStatus.TimedOut => new WebException("The request timed-out.", WebExceptionStatus.Timeout),
ResponseStatus.Aborted => new WebException("The request was aborted.", WebExceptionStatus.Timeout),
_ => throw new ArgumentOutOfRangeException(nameof(responseStatus))
};
}
Expand Down
Loading

0 comments on commit 5e1ccb1

Please sign in to comment.