public async Task EnsureNameUniquenessAgainstBaseClasses()
        {
            var markup = @"
class Base
{
    protected int Console_CancelKeyPress;
}
class Program : Base
{
    void Main(string[] args)
    {
        var goo = Console_CancelKeyPress + 23;
        System.Console.CancelKeyPress +$$
    }
}";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertShowing("Console_CancelKeyPress1");
        }
        public async Task HandlerName_DefaultHandlerNameAlreadyExistsAsField()
        {
            var markup = @"
class C
{
    event System.Action MyEvent;
    int C_MyEvent;

    void M(string[] args)
    {
        MyEvent +$$
    }
}";

            using (var testState = EventHookupTestState.CreateTestState(markup))
            {
                testState.SendTypeChar('=');
                await testState.WaitForAsynchronousOperationsAsync();

                testState.AssertShowing("C_MyEvent1;");
            }
        }
        public async Task EventHookupWithQualifiedMethodAccess()
        {
            var markup =
                @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using var testState = EventHookupTestState.CreateTestState(
                      markup,
                      QualifyMethodAccessWithNotification(NotificationOption2.Error)
                      );
            testState.SendTypeChar('=');
            testState.SendTab();
            await testState.WaitForAsynchronousOperationsAsync();

            var expectedCode =
                @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent += this.C_MyEvent;
    }

    private void C_MyEvent()
    {
        throw new System.NotImplementedException();
    }
}";

            testState.AssertCodeIs(expectedCode);
        }
        public async Task HookupInLambdaInLocalDeclaration()
        {
            var markup = @"
class C
{
    public event System.Action MyEvent;

    void Goo()
    {
        Action a = () => MyEvent +$$
    }
}
";

            using (var testState = EventHookupTestState.CreateTestState(markup))
            {
                testState.SendTypeChar('=');
                await testState.WaitForAsynchronousOperationsAsync();

                testState.AssertShowing("C_MyEvent;");
            }
        }
        public async Task DelegateInvokeMethodReturnsNonVoid()
        {
            var markup = @"
class C
{
    delegate int D(double d);
    event D MyEvent;

    void M()
    {
        MyEvent +$$
    }
}";

            using (var testState = EventHookupTestState.CreateTestState(markup))
            {
                testState.SendTypeChar('=');
                testState.SendTab();
                await testState.WaitForAsynchronousOperationsAsync();

                var expectedCode = @"
class C
{
    delegate int D(double d);
    event D MyEvent;

    void M()
    {
        MyEvent += C_MyEvent;
    }

    private int C_MyEvent(double d)
    {
        throw new System.NotImplementedException();
    }
}";
                testState.AssertCodeIs(expectedCode);
            }
        }
        public async Task EventHookupWithQualifiedMethodAccessAndNotificationOptionNone()
        {
            // This validates the scenario where the user has stated that they prefer `this.` qualification but the
            // notification level is `None`, which means existing violations of the rule won't be flagged but newly
            // generated code will conform appropriately.
            var markup = @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using (var testState = EventHookupTestState.CreateTestState(markup, QualifyMethodAccessWithNotification(NotificationOption.None)))
            {
                testState.SendTypeChar('=');
                testState.SendTab();
                await testState.WaitForAsynchronousOperationsAsync();

                var expectedCode = @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent += this.C_MyEvent;
    }

    private void C_MyEvent()
    {
        throw new System.NotImplementedException();
    }
}";
                testState.AssertCodeIs(expectedCode);
            }
        }
        public async Task HandlerName_EventInThisClass_CamelCaseRule()
        {
            var markup =
                @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using var testState = new EventHookupTestState(
                      EventHookupTestState.GetWorkspaceXml(markup),
                      _namingOptions.MethodNamesAreCamelCase
                      );

            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertShowing("c_MyEvent");
        }
Example #8
0
        public async Task MoveCaretOutOfSpanBeforeEventHookupDeterminationCompleted()
        {
            var markup = @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SetEventHookupCheckMutex();

            testState.SendTypeChar('=');
            testState.SendLeftKey();
            testState.ReleaseEventHookupCheckMutex();

            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertNotShowing();
        }
Example #9
0
        public void TypingLettersDismisses()
        {
            var markup = @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using (var testState = EventHookupTestState.CreateTestState(markup))
            {
                testState.SendTypeChar('=');
                testState.WaitForAsynchronousOperations();
                testState.AssertShowing("C_MyEvent;");

                testState.SendTypeChar('d');
                testState.WaitForAsynchronousOperations();
                testState.AssertNotShowing();
            }
        }
Example #10
0
        public async Task TypingEqualsInSessionDismisses()
        {
            var markup = @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertShowing("C_MyEvent");

            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertNotShowing();
        }
Example #11
0
        public async Task HandlerName_GlobalAlias02()
        {
            var markup = @"
using System;

class C
{
    void M()
    {
        global::Generic<int>.MyEvent +$$
    }
}

class Generic<T>
{
    public static event EventHandler MyEvent;
}";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertShowing("Generic_MyEvent");
        }
Example #12
0
        public async Task HandlerName_EventOnLocal()
        {
            var markup = @"
class C
{
    public event System.Action MyEvent;
}

class D
{
    void M()
    {
        C local = new C();
        local.MyEvent +$$
    }
}
";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertShowing("Local_MyEvent");
        }
Example #13
0
        public async Task HandlerName_DefaultHandlerNameAlreadyExistsWithDifferentStaticState()
        {
            var markup = @"
class C
{
    public event System.Action MyEvent;

    void Goo()
    {
        MyEvent +$$
    }

    private static void C_MyEvent()
    {
    }
}
";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            await testState.WaitForAsynchronousOperationsAsync();

            testState.AssertShowing("C_MyEvent1");
        }
Example #14
0
        public void SessionCancelledByCharacterBeforeEventHookupDeterminationCompleted()
        {
            var markup = @"
class C
{
    event System.Action MyEvent;
    void M()
    {
        MyEvent +$$
    }
}";

            using (var testState = EventHookupTestState.CreateTestState(markup))
            {
                testState.SetEventHookupCheckMutex();

                testState.SendTypeChar('=');
                testState.SendTypeChar('z');

                testState.ReleaseEventHookupCheckMutex();
                testState.WaitForAsynchronousOperations();
                testState.AssertNotShowing();
            }
        }
        public async Task NoHookupOnIntegerPlusEquals()
        {
            var markup = @"
class C
{
    void Foo()
    {
        int x = 7;
        x +$$
    }
}";

            using (var testState = EventHookupTestState.CreateTestState(markup))
            {
                testState.SendTypeChar('=');
                await testState.WaitForAsynchronousOperationsAsync();

                testState.AssertNotShowing();

                // Make sure that sending the tab works correctly. Note the 4 spaces after the +=
                testState.SendTab();
                await testState.WaitForAsynchronousOperationsAsync();

                var expectedCode = @"
class C
{
    void Foo()
    {
        int x = 7;
        x +=    
    }
}";

                testState.AssertCodeIs(expectedCode);
            }
        }
        public async Task HookupInFieldDeclarationMultiLineLambda()
        {
            var markup =
                @"
class C
{
    static event System.Action MyEvent;
    System.Action A = () =>
    {
        MyEvent +$$
    };
}";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            testState.SendTab();
            await testState.WaitForAsynchronousOperationsAsync();

            var expectedCode =
                @"
class C
{
    static event System.Action MyEvent;
    System.Action A = () =>
    {
        MyEvent += C_MyEvent;
    };

    private static void C_MyEvent()
    {
        throw new System.NotImplementedException();
    }
}";

            testState.AssertCodeIs(expectedCode);
        }
        public async Task EventHookupInTopLevelCode()
        {
            var markup = @"

System.AppDomain.CurrentDomain.UnhandledException +$$

";

            using var testState = EventHookupTestState.CreateTestState(markup);
            testState.SendTypeChar('=');
            testState.SendTab();
            await testState.WaitForAsynchronousOperationsAsync();

            var expectedCode = @"

System.AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
{
    throw new System.NotImplementedException();
}";

            testState.AssertCodeIs(expectedCode);
        }