Esempio n. 1
0
        private static async Task TestExtractInterfaceCodeActionAsync(
            string markup,
            string languageName,
            string expectedMarkup,
            CompilationOptions compilationOptions = null)
        {
            using (var testState = ExtractInterfaceTestState.Create(markup, languageName, compilationOptions))
            {
                var updatedSolution = await testState.ExtractViaCodeAction();

                var updatedDocument = updatedSolution.GetDocument(testState.ExtractFromDocument.Id);
                var updatedCode     = (await updatedDocument.GetTextAsync()).ToString();
                Assert.Equal(expectedMarkup, updatedCode);
            }
        }
        private static async Task TestExtractInterfaceCommandAsync(
            string markup,
            string languageName,
            bool expectedSuccess,
            string expectedMemberName                  = null,
            string expectedInterfaceName               = null,
            string expectedNamespaceName               = null,
            string expectedTypeParameterSuffix         = null,
            string expectedUpdatedOriginalDocumentCode = null,
            string expectedInterfaceCode               = null,
            CompilationOptions compilationOptions      = null)
        {
            using (var testState = ExtractInterfaceTestState.Create(markup, languageName, compilationOptions))
            {
                var result = await testState.ExtractViaCommandAsync();

                if (expectedSuccess)
                {
                    Assert.True(result.Succeeded);
                    Assert.False(testState.Workspace.Documents.Select(d => d.Id).Contains(result.NavigationDocumentId));
                    Assert.NotNull(result.UpdatedSolution.GetDocument(result.NavigationDocumentId));

                    if (expectedMemberName != null)
                    {
                        Assert.Equal(1, testState.TestExtractInterfaceOptionsService.AllExtractableMembers.Count());
                        Assert.Equal(expectedMemberName, testState.TestExtractInterfaceOptionsService.AllExtractableMembers.Single().Name);
                    }

                    if (expectedInterfaceName != null)
                    {
                        Assert.Equal(expectedInterfaceName, testState.TestExtractInterfaceOptionsService.DefaultInterfaceName);
                    }

                    if (expectedNamespaceName != null)
                    {
                        Assert.Equal(expectedNamespaceName, testState.TestExtractInterfaceOptionsService.DefaultNamespace);
                    }

                    if (expectedTypeParameterSuffix != null)
                    {
                        Assert.Equal(expectedTypeParameterSuffix, testState.TestExtractInterfaceOptionsService.GeneratedNameTypeParameterSuffix);
                    }

                    if (expectedUpdatedOriginalDocumentCode != null)
                    {
                        var updatedOriginalDocument = result.UpdatedSolution.GetDocument(testState.ExtractFromDocument.Id);
                        var updatedCode             = (await updatedOriginalDocument.GetTextAsync()).ToString();
                        Assert.Equal(expectedUpdatedOriginalDocumentCode, updatedCode);
                    }

                    if (expectedInterfaceCode != null)
                    {
                        var interfaceDocument = result.UpdatedSolution.GetDocument(result.NavigationDocumentId);
                        var interfaceCode     = (await interfaceDocument.GetTextAsync()).ToString();
                        Assert.Equal(expectedInterfaceCode, interfaceCode);
                    }
                }
                else
                {
                    Assert.False(result.Succeeded);
                }
            }
        }