コード例 #1
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);
     }
 }
コード例 #2
0
        private static void TestExtractInterfaceCommand(
            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 = new ExtractInterfaceTestState(markup, languageName, compilationOptions))
            {
                var result = testState.ExtractViaCommand();

                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 = updatedOriginalDocument.GetTextAsync(CancellationToken.None).Result.ToString();
                        Assert.Equal(expectedUpdatedOriginalDocumentCode, updatedCode);
                    }

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