Ejemplo n.º 1
0
            public TestRequirements()
            {
                StatePersistence = new TestStatePersistence((r) =>
                {
                    var value = (r.Payload as IntegerPayload).Value;
                    return(value <= 0 ? "Start" :
                           value >= 4 ? "Complete" :
                           $"Level{value}");
                });

                RequestPersistence = new TestRequestPersistence(
                    new ActionRequest <IntegerPayload>("LevelUp", IntegerPayload.New(0)),
                    new ActionRequest <IntegerPayload>("LevelUp", IntegerPayload.New(1)),
                    new ActionRequest <IntegerPayload>("LevelUp", IntegerPayload.New(2))
                    );

                IActionProcessingStateChange LevelUp(IActionRequest <IntegerPayload> r) => LastState      = new SuccessStateChange(IntegerPayload.Add(r.Payload as IntegerPayload, 1), TestState.New((r.Payload as IntegerPayload).Value < 3 ? $"Level{(r.Payload as IntegerPayload).Value + 1}" : "Complete"));
                IActionProcessingStateChange LevelDown(IActionRequest <IntegerPayload> r) => LastState    = new SuccessStateChange(IntegerPayload.Add(r.Payload as IntegerPayload, -1), TestState.New((r.Payload as IntegerPayload).Value > 1 ? $"Level{(r.Payload as IntegerPayload).Value - 1}" : "Start"));
                IActionProcessingStateChange BrucieBonus(IActionRequest <IntegerPayload> r) => LastState  = new SuccessStateChange(IntegerPayload.Add(r.Payload as IntegerPayload, 2), TestState.New((r.Payload as IntegerPayload).Value < 2 ? $"Level{(r.Payload as IntegerPayload).Value + 2}" : "Complete"));
                IActionProcessingStateChange BackToStart(IActionRequest <IntegerPayload> r) => LastState  = new SuccessStateChange(IntegerPayload.New(0, r.Payload.TrackingReference), TestState.New("Start"));
                IActionProcessingStateChange SideQuest(IActionRequest <IntegerPayload> r) => LastState    = new SuccessStateChange(r.Payload, r.Context.ProcessingState);
                IActionProcessingStateChange ToggleUpDown(IActionRequest <IntegerPayload> r) => LastState = (Toggle ? LevelUp(r) : LevelDown(r));

                PipelineConfiguration = new ActionPipelineConfiguration(
                    "TestPipeline",
                    new AllowedState("Start",
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelUp), LevelUp),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BrucieBonus), BrucieBonus)),
                    new AllowedState("Level1",
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelUp), LevelUp),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelDown), LevelDown),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BackToStart), BackToStart),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BrucieBonus), BrucieBonus)),
                    new AllowedState("Level2",
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelUp), LevelUp),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelDown), LevelDown),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(ToggleUpDown), ToggleUpDown),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BackToStart), BackToStart),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BrucieBonus), BrucieBonus),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(SideQuest), SideQuest)),
                    new AllowedState("Level3",
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelUp), LevelUp),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(LevelDown), LevelDown),
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BackToStart), BackToStart)),
                    new AllowedState("Complete",
                                     new ExternalDelegateAction <IntegerPayload>(nameof(BackToStart), BackToStart))
                    );
            }
Ejemplo n.º 2
0
            public TestRequirements(IKernel kernel)
            {
                RequestPersistence = new TestRequestPersistence();
                StatePersistence   = new TestStatePersistence((r) => "Zero");
                var actionFactory = new TestActionFactory(kernel);

                PipelineConfiguration = new ActionPipelineConfiguration(
                    actionFactory, "TestPipeline",
                    new AllowedState("Zero",
                                     nameof(Add)),
                    new AllowedState("Positive",
                                     nameof(Add)),
                    new AllowedState("Negative",
                                     nameof(Add))
                    );
            }