Exemplo n.º 1
0
        protected ProjectState(string name, string defaultPrefix, string defaultExtension)
        {
            Name              = name;
            _defaultPrefix    = defaultPrefix;
            _defaultExtension = defaultExtension;

            Sources = new SourceFileList(defaultPrefix, defaultExtension);
        }
        public async Task TaskResult_FixUpdatesCallers()
        {
            var test = new SourceFileList("Test", "cs")
            {
                @"
using System;
using System.Threading.Tasks;

class Test {
    internal static int GetNumber(int a) {
        var task = Task.Run(() => a);
        return task.Result;
    }

    int Add(int a, int b) {
        return GetNumber(a) + b;
    }

    int Subtract(int a, int b) {
        return GetNumber(a) - b;
    }

    static int Main(string[] args)
    {
        return new Test().Add(1, 2);
    }
}
",
                @"
class TestClient {
    int Multiply(int a, int b) {
        return Test.GetNumber(a) * b;
    }
}
",
            };
            var withFix = new SourceFileList("Test", "cs")
            {
                @"
using System;
using System.Threading.Tasks;

class Test {
    internal static async Task<int> GetNumberAsync(int a) {
        var task = Task.Run(() => a);
        return await task;
    }

    async Task<int> AddAsync(int a, int b) {
        return await GetNumberAsync(a) + b;
    }

    async Task<int> SubtractAsync(int a, int b) {
        return await GetNumberAsync(a) - b;
    }

    static async Task<int> Main(string[] args)
    {
        return await new Test().AddAsync(1, 2);
    }
}
",
                @"
class TestClient {
    async System.Threading.Tasks.Task<int> MultiplyAsync(int a, int b) {
        return await Test.GetNumberAsync(a) * b;
    }
}
",
            };

            var verifyTest = new Verify.Test
            {
                ExpectedDiagnostics =
                {
                    Verify.Diagnostic().WithSpan("Test0.cs", 8, 21, 8, 27),
                },
                HasEntryPoint = true,
            };

            verifyTest.TestState.Sources.AddRange(test);
            verifyTest.FixedState.Sources.AddRange(withFix);
            await verifyTest.RunAsync();
        }