BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

Wrap in using does nothing #97

Closed BADF00D closed 5 years ago

BADF00D commented 5 years ago

Prerequisites

Description

When executing Wrap in using CodeFix, nothing happens.

Source Code

using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Owin.Testing;

namespace SwaggerFileGenerator {
    class Program {
        private static async Task<(string route, string response)[]> GetRoutesFromServer(TestServer server) {
            var rootResponse = await server.CreateRequest(string.Empty).GetAsync();
            if (rootResponse.StatusCode != HttpStatusCode.MovedPermanently) {
                throw new Exception("Unable to retrieve Url to SwaggerUI. Expect root of server to contain redirect to swagger ui.");
            }

            var swaggerUiResponse = await server.CreateRequest(rootResponse.Headers.Location.ToString()).GetAsync();
            var swaggerUi = await swaggerUiResponse.Content.ReadAsStringAsync();

            var regex = new Regex("discoveryPaths\\:\\sarrayFrom\\(\\\'(?<paths>([a-zA-Z\\/0-9]*))\\\'\\).");
            var match = regex.Match(swaggerUi);
            if (!match.Success) {
                throw new Exception("Unable to retrieve routes from SwaggerUI. Maybe content changed."+Environment.NewLine+swaggerUi);
            }

            var paths = match.Groups["paths"].Value;

            var result = new List<(string route, string response)>();
            foreach (var path in paths.Split(',')) {
                using (var routeResponse = await server.CreateRequest(path).GetAsync()) {
                    var response = await routeResponse.Content.ReadAsStringAsync();
                    result.Add((path, response));
                }
            }

            return result.ToArray();
        }
    }
}

Screenshot

issue97

BADF00D commented 5 years ago

Will be part of release 1.1.4.