コード例 #1
0
        public async Task ActionsShouldExecuteInOrder()
        {
            var contextBag = ApFrameworkHelper.GetEmptyBag();

            contextBag.Add("testObj", new TestArguments());

            var request   = new Request <string>(ProcessRequest);
            var processor = new RequestProcessor();

            processor.AddAddtionalAction(Last, AddtionalActionSequence.Last);
            processor.AddAddtionalAction(First, AddtionalActionSequence.First); // 0
            processor.AddAddtionalAction(BeforeAuth, AddtionalActionSequence.BeforeAuthorization);
            processor.AddAddtionalAction(AfterAuth, AddtionalActionSequence.AfterAuthorization);
            processor.AddAddtionalAction(BeforeVal, AddtionalActionSequence.BeforeValidation);
            processor.AddAddtionalAction(AfterVal, AddtionalActionSequence.AfterValidation);
            processor.AddAddtionalAction(BeforeProcess, AddtionalActionSequence.BeforeRequestProcessing);
            processor.AddAddtionalAction(AfterProcess, AddtionalActionSequence.AfterRequestProcessing);


            await processor.ProcessRequestAsync(request, contextBag);

            var updatedObj = contextBag["testObj"] as TestArguments;

            for (int i = 0; i < 9; i++)
            {
                Assert.True(updatedObj.Logs[i] == i.ToString());
            }
        }
コード例 #2
0
        public async Task StopExectionIfCancellationIsRequested()
        {
            var contextBag = ApFrameworkHelper.GetEmptyBag();

            var testArgs = new TestArguments();
            CancellationTokenSource source = new CancellationTokenSource();

            testArgs.CancellationTokenSource  = source;
            testArgs.CancellationMatchStrinig = "2";


            contextBag.Add("testObj", testArgs);

            var request   = new Request <string>(ProcessRequest);
            var processor = new RequestProcessor();

            processor.AddAddtionalAction(Last, AddtionalActionSequence.Last);
            processor.AddAddtionalAction(First, AddtionalActionSequence.First); // 0
            processor.AddAddtionalAction(BeforeAuth, AddtionalActionSequence.BeforeAuthorization);
            processor.AddAddtionalAction(AfterAuth, AddtionalActionSequence.AfterAuthorization);
            processor.AddAddtionalAction(BeforeVal, AddtionalActionSequence.BeforeValidation);
            processor.AddAddtionalAction(AfterVal, AddtionalActionSequence.AfterValidation);
            processor.AddAddtionalAction(BeforeProcess, AddtionalActionSequence.BeforeRequestProcessing);
            processor.AddAddtionalAction(AfterProcess, AddtionalActionSequence.AfterRequestProcessing);


            await processor.ProcessRequestAsync(request, contextBag, source.Token);

            var updatedObj = contextBag["testObj"] as TestArguments;

            for (int i = 0; i < 3; i++)
            {
                Assert.True(updatedObj.Logs[i] == i.ToString());
            }

            for (int i = 3; i < 9; i++)
            {
                Assert.True(string.IsNullOrEmpty(updatedObj.Logs[i]));
            }
        }