Permalink
Browse files

More StyleCop fixes.

  • Loading branch information...
1 parent b9ae2ab commit 461810cf0d89103d79e6ee0544993ee3991fe80e @AArnott AArnott committed Mar 26, 2013
View
@@ -1,4 +1,4 @@
-<StyleCopSettings Version="4.3">
+<StyleCopSettings Version="105">
<Parsers>
<Parser ParserId="StyleCop.CSharp.CsParser">
<ParserSettings>
@@ -63,5 +63,15 @@
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>
+ <Analyzer AnalyzerId="StyleCop.CSharp.MaintainabilityRules">
+ <Rules>
+ <Rule Name="StatementMustNotUseUnnecessaryParenthesis">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
</Analyzers>
</StyleCopSettings>
@@ -51,13 +51,14 @@ public partial class GoogleAddressBook : System.Web.UI.Page {
XDocument contactsDocument =
await google.GetContactsAsync(this.AccessToken, 5, 1, Response.ClientDisconnectedToken);
- var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
- select
- new {
- Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value,
- Email =
- entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value
- };
+ var contacts =
+ from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
+ select
+ new {
+ Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value,
+ Email =
+ entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value
+ };
StringBuilder tableBuilder = new StringBuilder();
tableBuilder.Append("<table><tr><td>Name</td><td>Email</td></tr>");
foreach (var contact in contacts) {
@@ -1,4 +1,10 @@
-namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
+//-----------------------------------------------------------------------
+// <copyright file="HomeController.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
using System;
using System.Collections.Generic;
using System.Linq;
@@ -1,4 +1,10 @@
-namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
+//-----------------------------------------------------------------------
+// <copyright file="ProviderController.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
using System;
using System.Collections.Generic;
using System.Linq;
@@ -1,4 +1,10 @@
-namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
+//-----------------------------------------------------------------------
+// <copyright file="UserController.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
using System;
using System.Collections.Generic;
using System.Linq;
@@ -735,19 +735,6 @@ public abstract class Channel : IDisposable {
}
/// <summary>
- /// Provides derived-types the opportunity to wrap an <see cref="HttpMessageHandler"/> with another one.
- /// </summary>
- /// <param name="innerHandler">The inner handler received from <see cref="IHostFactories"/></param>
- /// <returns>The handler to use in <see cref="HttpClient"/> instances.</returns>
- protected virtual HttpMessageHandler WrapMessageHandler(HttpMessageHandler innerHandler) {
- //TODO: make sure that everyone calls this to wrap their handlers rather than using the one directly returned
- //from IHostFactories.
-
- // No wrapping by default.
- return innerHandler;
- }
-
- /// <summary>
/// Called when receiving a direct response message, before deserialization begins.
/// </summary>
/// <param name="response">The HTTP direct response.</param>
@@ -24,7 +24,7 @@ namespace DotNetOpenAuth.OAuth {
/// outgoing HTTP requests per the OAuth 1.0 "3.4 Signature" in RFC 5849.
/// </summary>
/// <remarks>
- /// http://tools.ietf.org/html/rfc5849#section-3.4
+ /// An implementation of http://tools.ietf.org/html/rfc5849#section-3.4
/// </remarks>
public abstract class OAuth1HttpMessageHandlerBase : DelegatingHandler {
/// <summary>
@@ -116,7 +116,7 @@ internal OAuth2ClientChannel(IHostFactories hostFactories)
/// <returns>
/// The deserialized message, if one is found. Null otherwise.
/// </returns>
- protected override async Task<IDirectedProtocolMessage> ReadFromRequestCoreAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
+ protected override Task<IDirectedProtocolMessage> ReadFromRequestCoreAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
Requires.NotNull(request, "request");
Logger.Channel.DebugFormat("Incoming HTTP request: {0} {1}", request.Method, request.RequestUri.AbsoluteUri);
@@ -142,7 +142,7 @@ internal OAuth2ClientChannel(IHostFactories hostFactories)
return null;
}
- return (IDirectedProtocolMessage)this.Receive(fields, recipient);
+ return Task.FromResult((IDirectedProtocolMessage)this.Receive(fields, recipient));
}
/// <summary>
@@ -229,10 +229,11 @@ internal class ProviderSigningBindingElement : SigningBindingElement {
Protocol protocol = Protocol.Lookup(signedMessage.Version);
MessageDescription description = this.Channel.MessageDescriptions.Get(signedMessage);
- var signedParts = from part in description.Mapping.Values
- where (part.RequiredProtection & System.Net.Security.ProtectionLevel.Sign) != 0
- && part.GetValue(signedMessage) != null
- select part.Name;
+ var signedParts =
+ from part in description.Mapping.Values
+ where (part.RequiredProtection & System.Net.Security.ProtectionLevel.Sign) != 0
+ && part.GetValue(signedMessage) != null
+ select part.Name;
string prefix = Protocol.V20.openid.Prefix;
ErrorUtilities.VerifyInternal(signedParts.All(name => name.StartsWith(prefix, StringComparison.Ordinal)), "All signed message parts must start with 'openid.'.");
@@ -237,17 +237,18 @@ public OpenIdAjaxRelyingParty(IOpenIdApplicationStore applicationStore)
// jsonResponse discoveryResult; // contains result of call to SerializeDiscoveryAsJson(Identifier)
// }
var jsonAsync = (from request in requests
- group request by request.DiscoveryResult.UserSuppliedIdentifier into requestsByIdentifier
- select new {
- userSuppliedIdentifier = (string)requestsByIdentifier.Key,
- discoveryResult = this.AsJsonDiscoveryResultAsync(requestsByIdentifier, cancellationToken),
- }).ToArray();
+ group request by request.DiscoveryResult.UserSuppliedIdentifier into requestsByIdentifier
+ select new {
+ userSuppliedIdentifier = (string)requestsByIdentifier.Key,
+ discoveryResult = this.AsJsonDiscoveryResultAsync(requestsByIdentifier, cancellationToken),
+ }).ToArray();
await Task.WhenAll(jsonAsync.Select(j => j.discoveryResult));
- var json = from j in jsonAsync
- select new {
- userSuppliedIdentifier = j.userSuppliedIdentifier,
- discoveryResult = j.discoveryResult.Result, // await happened previously
- };
+ var json =
+ from j in jsonAsync
+ select new {
+ userSuppliedIdentifier = j.userSuppliedIdentifier,
+ discoveryResult = j.discoveryResult.Result, // await happened previously
+ };
return json;
}
@@ -200,63 +200,5 @@ protected OpenIdChannel(IMessageFactory messageTypeProvider, IChannelBindingElem
return preparedResponse;
}
-
- /// <summary>
- /// Provides derived-types the opportunity to wrap an <see cref="HttpMessageHandler" /> with another one.
- /// </summary>
- /// <param name="innerHandler">The inner handler received from <see cref="IHostFactories" /></param>
- /// <returns>
- /// The handler to use in <see cref="HttpClient" /> instances.
- /// </returns>
- protected override HttpMessageHandler WrapMessageHandler(HttpMessageHandler innerHandler) {
- return new ErrorFilteringMessageHandler(base.WrapMessageHandler(innerHandler));
- }
-
- /// <summary>
- /// An HTTP handler that throws an exception if the response message's HTTP status code doesn't fall
- /// within those allowed by the OpenID spec.
- /// </summary>
- private class ErrorFilteringMessageHandler : DelegatingHandler {
- /// <summary>
- /// Initializes a new instance of the <see cref="ErrorFilteringMessageHandler" /> class.
- /// </summary>
- /// <param name="innerHandler">The inner handler which is responsible for processing the HTTP response messages.</param>
- internal ErrorFilteringMessageHandler(HttpMessageHandler innerHandler)
- : base(innerHandler) {
- }
-
- /// <summary>
- /// Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
- /// </summary>
- /// <param name="request">The HTTP request message to send to the server.</param>
- /// <param name="cancellationToken">A cancellation token to cancel operation.</param>
- /// <returns>
- /// Returns <see cref="T:System.Threading.Tasks.Task`1" />. The task object representing the asynchronous operation.
- /// </returns>
- protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) {
- var response = await base.SendAsync(request, cancellationToken);
-
- // Filter the responses to the allowable set of HTTP status codes.
- if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.BadRequest) {
- if (Logger.Channel.IsErrorEnabled) {
- var content = await response.Content.ReadAsStringAsync();
- Logger.Channel.ErrorFormat(
- "Unexpected HTTP status code {0} {1} received in direct response:{2}{3}",
- (int)response.StatusCode,
- response.StatusCode,
- Environment.NewLine,
- content);
- }
-
- // Call dispose before throwing since we're not including the response in the
- // exception we're throwing.
- response.Dispose();
-
- ErrorUtilities.ThrowProtocol(OpenIdStrings.UnexpectedHttpStatusCode, (int)response.StatusCode, response.StatusCode);
- }
-
- return response;
- }
- }
}
}
@@ -117,11 +117,11 @@ public class WebServerClientAuthorizeTests : OAuth2TestBase {
.Returns(true);
authServer.Setup(
a => a.CheckAuthorizeClientCredentialsGrant(It.Is<IAccessTokenRequest>(d => d.ClientIdentifier == ClientId && MessagingUtilities.AreEquivalent(d.Scope, TestScopes))))
- .Returns<IAccessTokenRequest>(req => {
+ .Returns<IAccessTokenRequest>(req => {
var response = new AutomatedAuthorizationCheckResponse(req, true);
response.ApprovedScope.ResetContents(approvedScopes);
return response;
- });
+ });
Handle(AuthorizationServerDescription.TokenEndpoint).By(
async (req, ct) => {
var server = new AuthorizationServer(authServer.Object);
@@ -196,6 +196,7 @@ public enum Scenarios {
var rp = this.CreateRelyingParty(true);
return rp.DiscoverAsync(identifier, cancellationToken);
}
+
/// <summary>
/// Simulates an extension request and response.
/// </summary>
@@ -206,8 +207,7 @@ public enum Scenarios {
/// This method relies on the extension objects' Equals methods to verify
/// accurate transport. The Equals methods should be verified by separate tests.
/// </remarks>
- internal async Task RoundtripAsync(
- Protocol protocol, IEnumerable<IOpenIdMessageExtension> requests, IEnumerable<IOpenIdMessageExtension> responses) {
+ internal async Task RoundtripAsync(Protocol protocol, IEnumerable<IOpenIdMessageExtension> requests, IEnumerable<IOpenIdMessageExtension> responses) {
var securitySettings = new ProviderSecuritySettings();
var cryptoKeyStore = new MemoryCryptoKeyStore();
var associationStore = new ProviderAssociationHandleEncoder(cryptoKeyStore);
@@ -334,6 +334,5 @@ public enum Scenarios {
var op = new OpenIdProvider(new StandardProviderApplicationStore(), this.HostFactories);
return op;
}
-
}
}
@@ -148,12 +148,12 @@ internal Handler(TestBase test, Uri uri)
internal void By(string responseContent, string contentType, HttpStatusCode statusCode = HttpStatusCode.OK) {
this.By(
- req => {
- var response = new HttpResponseMessage(statusCode);
- response.Content = new StringContent(responseContent);
- response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
- return response;
- });
+ req => {
+ var response = new HttpResponseMessage(statusCode);
+ response.Content = new StringContent(responseContent);
+ response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
+ return response;
+ });
}
}
}

0 comments on commit 461810c

Please sign in to comment.