Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single type per file, file name matches class name #7700

Merged
merged 4 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<Rule Id="SA1119" Action="None" /> <!-- Statement should not use unnecessary parenthesis -->
<Rule Id="SA1400" Action="Warning" /> <!-- Access modifier should be declared -->
<Rule Id="SA1401" Action="None" /> <!-- Fields should be private -->
<Rule Id="SA1402" Action="None" /> <!-- File may only contain a single type -->
<Rule Id="SA1402" Action="Warning" /> <!-- File may only contain a single type -->
<Rule Id="SA1403" Action="None" /> <!-- File may only contain a single namespace -->
<Rule Id="SA1404" Action="None" /> <!-- Code analysis suppression should have justification -->
<Rule Id="SA1405" Action="None" /> <!-- Debug.Assert should provide message text -->
Expand Down Expand Up @@ -210,7 +210,7 @@
<Rule Id="SA1646" Action="None" /> <!-- Included documentation XPath does not exist -->
<Rule Id="SA1647" Action="None" /> <!-- Include node does not contain valid file and path -->
<Rule Id="SA1648" Action="None" /> <!-- Inheritdoc should be used with inheriting class -->
<Rule Id="SA1649" Action="None" /> <!-- File name should match first type name -->
<Rule Id="SA1649" Action="Warning" /> <!-- File name should match first type name -->
<Rule Id="SA1650" Action="None" /> <!-- Element documentation should be spelled correctly -->
<Rule Id="SA1651" Action="None" /> <!-- Do not use placeholder elements -->
</Rules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,23 +701,4 @@ public async Task GetBatchSettingWithAllFields()
}
}
}

public static class ConfigurationSettingExtensions
{
public static ConfigurationSetting Clone(this ConfigurationSetting setting)
{
Dictionary<string, string> tags = new Dictionary<string, string>();
foreach (string key in setting.Tags.Keys)
{
tags.Add(key, setting.Tags[key]);
}

return new ConfigurationSetting(setting.Key, setting.Value)
{
Label = setting.Label,
ContentType = setting.ContentType,
Tags = tags
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace Azure.Data.AppConfiguration.Tests
{
public static class ConfigurationSettingExtensions
{
public static ConfigurationSetting Clone(this ConfigurationSetting setting)
{
Dictionary<string, string> tags = new Dictionary<string, string>();
foreach (string key in setting.Tags.Keys)
{
tags.Add(key, setting.Tags[key]);
}

return new ConfigurationSetting(setting.Key, setting.Value)
{
Label = setting.Label,
ContentType = setting.ContentType,
Tags = tags
};
}
}
}
78 changes: 0 additions & 78 deletions sdk/core/Azure.Core/src/Pipeline/HttpEnvironmentProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,6 @@

namespace Azure.Core.Pipeline
{
internal sealed class HttpEnvironmentProxyCredentials : ICredentials
{
// Wrapper class for cases when http and https have different authentication.
private readonly NetworkCredential _httpCred;
private readonly NetworkCredential _httpsCred;
private readonly Uri _httpProxy;
private readonly Uri _httpsProxy;

public HttpEnvironmentProxyCredentials(Uri httpProxy, NetworkCredential httpCred,
Uri httpsProxy, NetworkCredential httpsCred)
{
_httpCred = httpCred;
_httpsCred = httpsCred;
_httpProxy = httpProxy;
_httpsProxy = httpsProxy;
}

public NetworkCredential GetCredential(Uri uri, string authType)
{
if (uri == null)
{
return null;
}
return uri.Equals(_httpProxy) ? _httpCred :
uri.Equals(_httpsProxy) ? _httpsCred : null;
}

public static HttpEnvironmentProxyCredentials TryCreate(Uri httpProxy, Uri httpsProxy)
{
NetworkCredential httpCred = null;
NetworkCredential httpsCred = null;

if (httpProxy != null)
{
httpCred = GetCredentialsFromString(httpProxy.UserInfo);
}
if (httpsProxy != null)
{
httpsCred = GetCredentialsFromString(httpsProxy.UserInfo);
}
if (httpCred == null && httpsCred == null)
{
return null;
}
return new HttpEnvironmentProxyCredentials(httpProxy, httpCred, httpsProxy, httpsCred);
}

/// <summary>
/// Converts string containing user:password to NetworkCredential object
/// </summary>
private static NetworkCredential GetCredentialsFromString(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return null;
}

value = Uri.UnescapeDataString(value);

string password = "";
string domain = null;
int idx = value.IndexOf(':');
if (idx != -1)
{
password = value.Substring(idx + 1);
value = value.Substring(0, idx);
}

idx = value.IndexOf('\\');
if (idx != -1)
{
domain = value.Substring(0, idx);
value = value.Substring(idx + 1);
}

return new NetworkCredential(value, password, domain);
}
}

internal sealed partial class HttpEnvironmentProxy : IWebProxy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// Copied from https://raw.githubusercontent.com/dotnet/corefx/master/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs

#nullable disable

using System;
using System.Net;
using System.Collections.Generic;

namespace Azure.Core.Pipeline
{
internal sealed class HttpEnvironmentProxyCredentials : ICredentials
{
// Wrapper class for cases when http and https have different authentication.
private readonly NetworkCredential _httpCred;
private readonly NetworkCredential _httpsCred;
private readonly Uri _httpProxy;
private readonly Uri _httpsProxy;

public HttpEnvironmentProxyCredentials(Uri httpProxy, NetworkCredential httpCred,
Uri httpsProxy, NetworkCredential httpsCred)
{
_httpCred = httpCred;
_httpsCred = httpsCred;
_httpProxy = httpProxy;
_httpsProxy = httpsProxy;
}

public NetworkCredential GetCredential(Uri uri, string authType)
{
if (uri == null)
{
return null;
}
return uri.Equals(_httpProxy) ? _httpCred :
uri.Equals(_httpsProxy) ? _httpsCred : null;
}

public static HttpEnvironmentProxyCredentials TryCreate(Uri httpProxy, Uri httpsProxy)
{
NetworkCredential httpCred = null;
NetworkCredential httpsCred = null;

if (httpProxy != null)
{
httpCred = GetCredentialsFromString(httpProxy.UserInfo);
}
if (httpsProxy != null)
{
httpsCred = GetCredentialsFromString(httpsProxy.UserInfo);
}
if (httpCred == null && httpsCred == null)
{
return null;
}
return new HttpEnvironmentProxyCredentials(httpProxy, httpCred, httpsProxy, httpsCred);
}

/// <summary>
/// Converts string containing user:password to NetworkCredential object
/// </summary>
private static NetworkCredential GetCredentialsFromString(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return null;
}

value = Uri.UnescapeDataString(value);

string password = "";
string domain = null;
int idx = value.IndexOf(':');
if (idx != -1)
{
password = value.Substring(idx + 1);
value = value.Substring(0, idx);
}

idx = value.IndexOf('\\');
if (idx != -1)
{
domain = value.Substring(0, idx);
value = value.Substring(idx + 1);
}

return new NetworkCredential(value, password, domain);
}
}
}
3 changes: 3 additions & 0 deletions sdk/core/Azure.Core/src/Shared/NullableAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#define INTERNAL_NULLABLE_ATTRIBUTES

#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1649 // File name should match first type name

namespace System.Diagnostics.CodeAnalysis
{
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
Expand Down
118 changes: 59 additions & 59 deletions sdk/core/Azure.Core/tests/ClientTestBaseDiagnosticScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,67 +51,67 @@ public async Task DoesNotThrowForCorrectDiagnosticScope()
InvalidDiagnosticScopeTestClient client = InstrumentClient(new InvalidDiagnosticScopeTestClient());
await client.CorrectScopeAsync();
}
}

public class InvalidDiagnosticScopeTestClient
{
private void FireScope(string method)
{
ClientDiagnostics clientDiagnostics = new ClientDiagnostics(true);
string activityName = $"{typeof(InvalidDiagnosticScopeTestClient).FullName}.{method}";
DiagnosticScope scope = clientDiagnostics.CreateScope(activityName);
scope.Start();
scope.Dispose();
}

[ForwardsClientCalls]
public virtual Task<bool> NoScopeAsync()
{
return Task.FromResult(true);
}

[ForwardsClientCalls]
public virtual bool NoScope()
{
return true;
}

public virtual Task<bool> WrongScopeAsync()
{
FireScope("DoesNotExist");
return Task.FromResult(true);
}

public virtual bool WrongScope()
{
FireScope("DoesNotExist");
return true;
}

public virtual Task<bool> CorrectScopeAsync()
{
FireScope(nameof(CorrectScope));
return Task.FromResult(true);
}

public virtual bool CorrectScope()
{
FireScope(nameof(CorrectScope));
return true;
}

[ForwardsClientCalls]
public virtual Task<bool> ForwardsAsync()
{
FireScope(nameof(CorrectScope));
return Task.FromResult(true);
}

[ForwardsClientCalls]
public virtual bool Forwards()
public class InvalidDiagnosticScopeTestClient
{
FireScope(nameof(CorrectScope));
return true;
private void FireScope(string method)
{
ClientDiagnostics clientDiagnostics = new ClientDiagnostics(true);
string activityName = $"{typeof(InvalidDiagnosticScopeTestClient).FullName}.{method}";
DiagnosticScope scope = clientDiagnostics.CreateScope(activityName);
scope.Start();
scope.Dispose();
}

[ForwardsClientCalls]
public virtual Task<bool> NoScopeAsync()
{
return Task.FromResult(true);
}

[ForwardsClientCalls]
public virtual bool NoScope()
{
return true;
}

public virtual Task<bool> WrongScopeAsync()
{
FireScope("DoesNotExist");
return Task.FromResult(true);
}

public virtual bool WrongScope()
{
FireScope("DoesNotExist");
return true;
}

public virtual Task<bool> CorrectScopeAsync()
{
FireScope(nameof(CorrectScope));
return Task.FromResult(true);
}

public virtual bool CorrectScope()
{
FireScope(nameof(CorrectScope));
return true;
}

[ForwardsClientCalls]
public virtual Task<bool> ForwardsAsync()
{
FireScope(nameof(CorrectScope));
return Task.FromResult(true);
}

[ForwardsClientCalls]
public virtual bool Forwards()
{
FireScope(nameof(CorrectScope));
return true;
}
}
}
}
6 changes: 0 additions & 6 deletions sdk/core/Azure.Core/tests/TestEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,4 @@ public override void Dispose()
base.Dispose();
}
}

public static class TestEventListenerExtensions
{
public static T GetProperty<T>(this EventWrittenEventArgs data, string propName)
=> (T)data.Payload[data.PayloadNames.IndexOf(propName)];
}
}
Loading