Exemple #1
0
        public void AddStartupProperties_Produces_Expected_Basic_Result()
        {
            var expectedDeclarationStrings = new[] { ExpectedConfigPropertyDeclarationFullText, ExpectedEnvPropertyDeclarationFullText };
            var actualDeclarationStrings   = StartupSyntaxHelper.AddStartupProperties().Select(declaration => declaration.NormalizeWhitespace().ToFullString());

            Assert.AreEqual(expectedDeclarationStrings, actualDeclarationStrings);
        }
Exemple #2
0
        public void ConstructStartupClass_Produces_Expected_Fully_Modified_Result()
        {
            var additionalStatements = new[] { SyntaxHelperSetupFixture.AdditionalStatement };
            var modifiedStartupClass = StartupSyntaxHelper.ConstructStartupClass(
                constructorAdditionalStatements: additionalStatements,
                configureAdditionalStatements: additionalStatements,
                configureServicesAdditionalStatements: additionalStatements,
                additionalFieldDeclarations: new[] { SyntaxHelperSetupFixture.AdditionalFieldDeclaration },
                additionalPropertyDeclarations: new[] { SyntaxHelperSetupFixture.AdditionalPropertyDeclaration },
                additionalMethodDeclarations: new[] { SyntaxHelperSetupFixture.AdditionalMethodDeclaration });

            Assert.AreEqual(ExpectedFullyModifiedClassText, modifiedStartupClass.NormalizeWhitespace().ToFullString());
        }
Exemple #3
0
        public void AddStartupProperties_Produces_Expected_Result_When_Additional_Properties_Present()
        {
            var additionalPropertyDeclarations = new[] { SyntaxHelperSetupFixture.AdditionalPropertyDeclaration };
            var expectedDeclarationStrings     = new[]
            {
                ExpectedConfigPropertyDeclarationFullText,
                ExpectedEnvPropertyDeclarationFullText,
                SyntaxHelperSetupFixture.AdditionalPropertyFullText
            };
            var actualDeclarationStrings = StartupSyntaxHelper.AddStartupProperties(additionalPropertyDeclarations)
                                           .Select(declaration => declaration.NormalizeWhitespace().ToFullString());

            Assert.AreEqual(expectedDeclarationStrings, actualDeclarationStrings);
        }
Exemple #4
0
        public override async Task <IEnumerable <FileInformation> > MigrateClassAsync()
        {
            LogStart();
            _metricsContext.CollectActionMetrics(WebFormsActionType.ClassConversion, ActionName);

            // Make this call once now so we don't have to keep doing it later
            var originalDescendantNodes = _originalDeclarationSyntax.DescendantNodes();

            // Currently not implementing service layer so add blank line with a comment instead
            var configureServicesLines = new[]
            {
                CodeSyntaxHelper.GetBlankLine().AddComment(string.Format(Constants.OperationUnattemptedCommentTemplate, MigrateServiceLayerOperation), isLeading: false)
            };

            // Iterate through methods and process them as needed
            ProcessMethods(originalDescendantNodes.OfType <MethodDeclarationSyntax>());

            // With middleware lambdas added we need to retrieve registrations
            // before we have all statements required to build startup class
            await InsertRequestPipelineMiddlewareRegistrations();

            var fileText = string.Empty;

            try
            {
                var startupClassDeclaration = StartupSyntaxHelper.ConstructStartupClass(
                    constructorAdditionalStatements: originalDescendantNodes.OfType <ConstructorDeclarationSyntax>().FirstOrDefault()?.Body?.Statements,
                    configureAdditionalStatements: _configureMethodStatements,
                    configureServicesAdditionalStatements: configureServicesLines,
                    additionalFieldDeclarations: originalDescendantNodes.OfType <FieldDeclarationSyntax>(),
                    additionalPropertyDeclarations: originalDescendantNodes.OfType <PropertyDeclarationSyntax>(),
                    additionalMethodDeclarations: _keepableMethods)
                                              .AddClassBlockComment(_endOfClassComments, false);

                var containingNamespace = CodeSyntaxHelper.BuildNamespace(_originalClassSymbol.ContainingNamespace?.ToDisplayString(), startupClassDeclaration);
                fileText = CodeSyntaxHelper.GetFileSyntaxAsString(containingNamespace, await GetAllUsingStatements());
            }
            catch (Exception e)
            {
                LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Failed to construct new Startup file content from {OriginalClassName} class at {_fullPath}");
            }

            DoCleanUp();
            LogEnd();

            // Global.asax.cs turns into Startup.cs
            var newRelativePath = FilePathHelper.RemoveDuplicateDirectories(Path.Combine(Path.GetDirectoryName(_relativePath), Constants.StartupFileName));

            return(new[] { new FileInformation(newRelativePath, Encoding.UTF8.GetBytes(fileText)) });
        }
Exemple #5
0
        public void ConstructStartupConfigureServicesMethod_Produces_Expected_Result_When_Additional_Statements_Present()
        {
            var additionalStatements = new[] { SyntaxHelperSetupFixture.AdditionalStatement };

            Assert.AreEqual(ExpectedModifiedConfigureServicesText, StartupSyntaxHelper.ConstructStartupConfigureServicesMethod(additionalStatements).NormalizeWhitespace().ToFullString());
        }
Exemple #6
0
 public void ConstructStartupConfigureServicesMethod_Produces_Expected_Result()
 {
     Assert.AreEqual(ExpectedBasicConfigureServicesText, StartupSyntaxHelper.ConstructStartupConfigureServicesMethod().NormalizeWhitespace().ToFullString());
 }
Exemple #7
0
 public void ConstructStartupConstructor_Produces_Expected_Basic_Result()
 {
     Assert.AreEqual(ExpectedBasicStartupConstructorText, StartupSyntaxHelper.ConstructStartupConstructor().NormalizeWhitespace().ToFullString());
 }