Beispiel #1
0
        public async Task ExtractInterface_CodeGen_AccessibilityModifiers()
        {
            var markup = @"
using System;

abstract class MyClass$$
{
    public void Goo() { }
}";

            using var testState = ExtractInterfaceTestState.Create(
                      markup, LanguageNames.CSharp,
                      options: new OptionsCollection(LanguageNames.CSharp)
            {
                { CodeStyleOptions2.RequireAccessibilityModifiers, AccessibilityModifiersRequired.Always, NotificationOption2.Silent }
            });

            var result = await testState.ExtractViaCommandAsync();

            var interfaceDocument = result.UpdatedSolution.GetRequiredDocument(result.NavigationDocumentId);
            var interfaceCode     = (await interfaceDocument.GetTextAsync()).ToString();

            Assert.Equal(@"internal interface IMyClass
{
    void Goo();
}", interfaceCode);
        }
        public async Task ExtractInterface_NamespaceName_NestedNamespaces_FileScopedNamespace1()
        {
            var markup = @"
using System;
namespace OuterNamespace
{
    namespace InnerNamespace
    {
        class MyClass
        {
            $$public void Goo() { }
        }
    }
}";

            using var testState = ExtractInterfaceTestState.Create(
                      markup, LanguageNames.CSharp,
                      parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10),
                      options: new OptionsCollection(LanguageNames.CSharp)
            {
                { CSharpCodeStyleOptions.NamespaceDeclarations, NamespaceDeclarationPreference.FileScoped, NotificationOption2.Silent }
            });

            var result = await testState.ExtractViaCommandAsync();

            var interfaceDocument = result.UpdatedSolution.GetRequiredDocument(result.NavigationDocumentId);
            var interfaceCode     = (await interfaceDocument.GetTextAsync()).ToString();

            Assert.Equal(@"namespace OuterNamespace.InnerNamespace;

interface IMyClass
{
    void Goo();
}", interfaceCode);
        }
Beispiel #3
0
        private static async Task TestTypeDiscoveryAsync(
            string markup,
            TypeDiscoveryRule typeDiscoveryRule,
            bool expectedExtractable)
        {
            using var testState = ExtractInterfaceTestState.Create(markup, LanguageNames.CSharp, compilationOptions: null);
            var result = await testState.GetTypeAnalysisResultAsync(typeDiscoveryRule);

            Assert.Equal(expectedExtractable, result.CanExtractInterface);
        }
Beispiel #4
0
 private static void TestTypeDiscovery(
     string markup,
     TypeDiscoveryRule typeDiscoveryRule,
     bool expectedExtractable)
 {
     using (var testState = new ExtractInterfaceTestState(markup, LanguageNames.CSharp, compilationOptions: null))
     {
         var result = testState.GetTypeAnalysisResult(typeDiscoveryRule);
         Assert.Equal(expectedExtractable, result.CanExtractInterface);
     }
 }
Beispiel #5
0
        public async Task ExtractInterface_CodeGen_ImportsInsideNamespace()
        {
            var markup = @"
namespace N
{
    public class Class
    {
        $$public System.Diagnostics.BooleanSwitch M1(System.Globalization.Calendar x) { return null; }
        public void M2(System.Collections.Generic.List<System.IO.BinaryWriter> x) { }
        public void M3<T>() where T : System.Net.WebProxy { }
    }
}";

            var expectedInterfaceCode = @"namespace N
{
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Net;

    public interface IClass
    {
        BooleanSwitch M1(Calendar x);
        void M2(List<BinaryWriter> x);
        void M3<T>() where T : WebProxy;
    }
}";

            using var testState = ExtractInterfaceTestState.Create(
                      markup, LanguageNames.CSharp,
                      parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10),
                      options: new OptionsCollection(LanguageNames.CSharp)
            {
                { CSharpCodeStyleOptions.PreferredUsingDirectivePlacement, AddImportPlacement.InsideNamespace }
            });

            var result = await testState.ExtractViaCommandAsync();

            var interfaceDocument = result.UpdatedSolution.GetRequiredDocument(result.NavigationDocumentId);
            var interfaceCode     = (await interfaceDocument.GetTextAsync()).ToString();

            Assert.Equal(expectedInterfaceCode, interfaceCode);
        }