public async Task GetMiddlewarePipelineAdditions_Organizes_Pipeline_Addition_Statements_By_Event()
        {
            var testLambda = SyntaxFactory.ParenthesizedLambdaExpression().WithBlock(SyntaxFactory.Block());

            // Should be the second registration in the sequence
            _lcManager.RegisterMiddlewareLambda(WebFormsAppLifecycleEvent.PostAcquireRequestState, testLambda);
            // Should be the first registration in the sequence
            _lcManager.RegisterMiddlewareClass(WebFormsAppLifecycleEvent.BeginRequest, TestMiddlewareName1, TestMiddlewareNamespace, TestOriginClassName, false);
            // Should be the third registration in the sequence
            _lcManager.RegisterMiddlewareClass(WebFormsAppLifecycleEvent.EndRequest, TestMiddlewareName2, TestMiddlewareNamespace, TestOriginClassName, false);

            var expectedResults = new[]
            {
                SyntaxFactory.ParseStatement($"app.UseMiddleware<{TestMiddlewareName1}>();"),
                SyntaxFactory.ParseStatement("app.Use(()=>{});"),
                SyntaxFactory.ParseStatement($"app.UseMiddleware<{TestMiddlewareName2}>();")
            };
            var actualResults = await _lcManager.GetMiddlewarePipelineAdditions(_token);

            for (int i = 0; i < expectedResults.Length; i++)
            {
                // Use trivialess and formatless comparison
                Assert.True(expectedResults[i].IsEquivalentTo(actualResults.ElementAt(i), false));
            }
        }
Beispiel #2
0
        private void HandleLifecycleMethod(MethodDeclarationSyntax methodDeclaration, WebFormsAppLifecycleEvent lifecycleEvent)
        {
            var statements       = methodDeclaration.Body.Statements;
            var lambdaExpression = LifecycleManagerService.ContentIsPreHandle(lifecycleEvent) ?
                                   MiddlewareSyntaxHelper.ConstructMiddlewareLambda(preHandleStatements: statements) :
                                   MiddlewareSyntaxHelper.ConstructMiddlewareLambda(postHandleStatements: statements);

            _lifecycleManager.RegisterMiddlewareLambda(lifecycleEvent, lambdaExpression);
        }