Exemple #1
0
        public async Task ExecuteAsync_doesnt_change_state_if_condition_not_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAutoForwardParameterizedAsync <Sale, SaleState, SaleEvent, string>(
                GetStateMachine()
                , endState
                , startState
                , conditionAsync: (_, stringParam, inCancelToken) => Task.FromResult(result: false)
                , name: "test"
                , priority: 1);

            var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request : "notUsed"),
                                                new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay
                                                                                                 , startState
                                                                                                 , startState
                                                                                                 , startState
                                                                                                 , "transactionName"));

            Assert.Equal(startState, sale.State);
            Assert.False(result.ConditionMet);
            Assert.False(result.WasTransitioned);
            Assert.True(result.TransitionDefined);
        }
        public void Execute_does_not_change_state_if_condition_not_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleId: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAutoForwardParameterized <Sale, SaleState, SaleEvent, string>(
                GetStateMachine()
                , endState
                , startState
                , condition: (_, stringParam) => false
                , name: "test"
                , priority: 1);

            var result = sut.Execute(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request: "notUsed"),
                                     new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay
                                                                                      , startState
                                                                                      , startState
                                                                                      , startState
                                                                                      , "transactionName"));

            Assert.Equal(startState, sale.State);
            Assert.False(result.ConditionMet);
            Assert.False(result.WasTransitioned);
            Assert.True(result.TransitionDefined);
        }
Exemple #3
0
        public void ExecuteAsync_ConditionAsync_can_be_cancelled()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAutoFallbackParameterizedAsync <Sale, SaleState, SaleEvent, string>(
                getStateMachine()
                , startState
                , SaleState.Complete
                , SaleState.Open
                , conditionAsync: (_, stringParam, cancellationToken) =>
            {
                Task.Delay(millisecondsDelay: 999999, cancellationToken: cancellationToken);
                return(Task.FromResult(!cancellationToken.IsCancellationRequested));
            }
                , name: "test"
                , priority: 1);

            using (var cancelSource = new CancellationTokenSource())
            {
                var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, cancellationToken: cancelSource.Token);
                Task.Run(async() => await sut.ExecuteAsync(parameters, currentResult: null));
                cancelSource.Cancel();

                Assert.Equal(startState, sale.State);
            }
        }
        public void Execute_does_not_change_state_if_triggerState_does_not_match()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState = SaleState.Complete;
            var sale = new Sale(saleId: 66) { State = startState };

            var sut = new StateTransitionAutoForward<Sale, SaleState, SaleEvent>(
                getStateMachine()
              , triggerState: SaleState.Complete
              , toState: endState
              , condition: _ => false
              , name: "test"
              , priority: 1);

            var result = sut.Execute(new ExecutionParameters<Sale, SaleEvent>(SaleEvent.Pay, sale), getDummyResult());

            Assert.Equal(startState, sale.State);
            Assert.False(result.ConditionMet);
            Assert.False(result.WasTransitioned);
            Assert.False(result.WasCancelled);
            Assert.True(result.TransitionDefined);
            Assert.Equal(startState, result.StartingState);
            Assert.Equal(startState, result.PreviousState);
            Assert.Equal(startState, result.CurrentState);
        }
Exemple #5
0
        public void ExecuteAsync_ConditionAsync_can_be_cancelled()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAsync <Sale, SaleState, SaleEvent>(
                stateAccessor: saleToUpdate => saleToUpdate.State
                , stateMutator: (saleToUpdate, newState) => saleToUpdate.State = newState
                , toState: SaleState.Complete
                , conditionAsync: (_, cancellationToken) =>
            {
                Task.Delay(millisecondsDelay: 999999, cancellationToken: cancellationToken);
                return(Task.FromResult(!cancellationToken.IsCancellationRequested));
            }
                , name: "test"
                , priority: 1);

            using (var cancelSource = new CancellationTokenSource())
            {
                var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, cancellationToken: cancelSource.Token);
                Task.Run(async() => await sut.ExecuteAsync(parameters), cancelSource.Token);
                cancelSource.Cancel();

                Assert.Equal(startState, sale.State);
            }
        }
        public async void Execute_changes_state_for_superState()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = SaleState.ChangeDue
            };
            var stateMachine = getStateMachine();

            var openStateConfig = stateMachine.ConfigureState(SaleState.Open);

            stateMachine.ConfigureState(SaleState.ChangeDue)
            .MakeSubStateOf(openStateConfig);

            var sut = new StateTransitionAutoForwardAsync <Sale, SaleState, SaleEvent>(
                stateMachine
                , triggerState: startState
                , toState: endState
                , conditionAsync: (_, cancelToke) => Task.FromResult(true)
                , name: "test"
                , priority: 1);
            var previousResult = getDummyResult();

            previousResult.CurrentState = SaleState.ChangeDue;

            var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale), previousResult);

            Assert.True(result.WasTransitioned);
            Assert.Equal(endState, sale.State);
            Assert.Equal(endState, result.CurrentState);
            Assert.Equal(SaleState.ChangeDue, result.PreviousState);
            Assert.Equal(startState, result.StartingState);
            Assert.True(result.TransitionDefined);
        }
Exemple #7
0
        public async Task ExecuteAsync_doesnt_execute_if_CancelRequested()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAsync <Sale, SaleState, SaleEvent>(
                stateAccessor: saleToUpdate => saleToUpdate.State
                , stateMutator: (saleToUpdate, newState) => saleToUpdate.State = newState
                , toState: SaleState.Complete
                , conditionAsync: (_, inCancelToken) => Task.FromResult(result: true)
                , name: "test"
                , priority: 1);

            using (var cancelSource = new CancellationTokenSource())
            {
                var cancelToken = cancelSource.Token;
                cancelSource.Cancel();

                var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request: null, cancellationToken: cancelToken);
                var result     = await sut.ExecuteAsync(parameters);

                Assert.True(result.WasCancelled);
                Assert.False(result.WasTransitioned);
                Assert.Equal(startState, sale.State);
            }
        }
Exemple #8
0
 public SaleStateChange(Guid id, string reason, SaleState state, Guid?causedByPointOfSaleId, Guid?causedByUserId) : base(id)
 {
     SetReason(reason);
     SetState(state);
     SetCausedByPointOfSaleId(causedByPointOfSaleId);
     SetCausedByUserId(causedByUserId);
 }
        public async void Execute_does_not_change_state_if_condition_not_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAutoForwardAsync <Sale, SaleState, SaleEvent>(
                getStateMachine()
                , triggerState: startState
                , toState: endState
                , conditionAsync: (_, cancelToken) => Task.FromResult(false)
                , name: "test"
                , priority: 1);

            var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale), getDummyResult());

            Assert.Equal(startState, sale.State);
            Assert.False(result.ConditionMet);
            Assert.False(result.WasTransitioned);
            Assert.False(result.WasCancelled);
            Assert.True(result.TransitionDefined);
            Assert.Equal(startState, result.StartingState);
            Assert.Equal(startState, result.PreviousState);
            Assert.Equal(startState, result.CurrentState);
        }
Exemple #10
0
        public async Task ExecuteAsync_does_not_execute_if_CancelRequested()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleId: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAutoFallback <Sale, SaleState, SaleEvent>(
                getStateMachine()
                , SaleState.Open
                , SaleState.Open
                , toState: SaleState.Complete
                , conditionAsync: (_, inCancelToken) => Task.FromResult(result: true)
                , name: "test"
                , priority: 1);

            using var cancelSource = new CancellationTokenSource();
            var cancelToken = cancelSource.Token;

            cancelSource.Cancel();

            var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request: null, cancellationToken: cancelToken);
            var result     = await sut.ExecuteAsync(parameters, getDummyResult(wasCancelled : true));

            Assert.True(result.WasCancelled);
            Assert.False(result.WasTransitioned);
            Assert.Equal(startState, sale.State);
        }
Exemple #11
0
        public void Execute_changes_state_if_condition_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAutoForward <Sale, SaleState, SaleEvent>(
                GetStateMachine()
                , triggerState: startState
                , toState: endState
                , condition: (_) => true
                , name: "test"
                , priority: 1);

            var result = sut.Execute(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale), GetDummyResult());

            Assert.True(result.WasTransitioned);
            Assert.Equal(endState, sale.State);
            Assert.Equal(endState, result.CurrentState);
            Assert.Equal(startState, result.PreviousState);
            Assert.Equal(startState, result.StartingState);
            Assert.True(result.TransitionDefined);
        }
Exemple #12
0
        public async Task ExecuteAsync_doesnt_execute_if_cancel_requested()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAutoForwardParameterizedAsync <Sale, SaleState, SaleEvent, string>(
                GetStateMachine()
                , SaleState.Complete
                , SaleState.Open
                , conditionAsync: (_, stringParam, cancelToken) => Task.FromResult(result: true)
                , name: "test"
                , priority: 1);

            using (var cancelSource = new CancellationTokenSource())
            {
                var cancelToken = cancelSource.Token;
                cancelSource.Cancel();
                var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request: "notUsed", cancellationToken: cancelToken);

                var result = await sut.ExecuteAsync(parameters, GetDummyResult(wasCancelled : true));

                Assert.True(result.WasCancelled);
                Assert.False(result.WasTransitioned);
                Assert.Equal(startState, sale.State);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SaleState saleState = db.SaleStates.Find(id);

            db.SaleStates.Remove(saleState);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #14
0
        public void ExecuteAsync_ConditionAsync_can_be_cancelled()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAutoForwardParameterizedAsync <Sale, SaleState, SaleEvent, string>(
                getStateMachine()
                , SaleState.Complete
                , SaleState.Open
                , conditionAsync: (_, stringParam, cancellationToken) =>
            {
                do
                {
                    Task.Delay(millisecondsDelay: 99).Wait();
                } while (!cancellationToken.IsCancellationRequested);

                return(Task.FromResult(!cancellationToken.IsCancellationRequested));
            }
                , name: "test"
                , priority: 1);

            using (var mutex = new Mutex(initiallyOwned: false))
                using (var cancelSource = new CancellationTokenSource())
                {
                    StateTransitionResult <SaleState, SaleEvent> result = null;

                    var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, cancellationToken: cancelSource.Token, request: "test");
                    Task.Factory.StartNew(async() =>
                    {
                        mutex.WaitOne();
                        result = await sut.ExecuteAsync(parameters, getDummyResult());
                        mutex.ReleaseMutex();
                    }, TaskCreationOptions.LongRunning);

                    try
                    {
                        Task.Delay(2222).Wait();

                        cancelSource.Cancel();
                    }
                    catch
                    {
                        cancelSource.Cancel();
                    }

                    mutex.WaitOne();

                    Assert.True(result.WasCancelled);
                    Assert.Equal(startState, sale.State);
                    Assert.Equal(startState, result.CurrentState);
                    Assert.False(result.ConditionMet);
                    Assert.True(result.TransitionDefined);
                    Assert.True(result.TransitionDefined);
                }
        }
Exemple #15
0
 public void SwitchFightToGuitarHero()
 {
     door.SetTrigger("EndFight");
     player.SetTrigger("Win");
     saleState = Game.SaleState.Talk;
     ResetImpatience();
     gameUi.SwitchCanvas(false);
     guitarHeroGame.StartSale();
 }
 public ActionResult Edit([Bind(Include = "idSaleState,state")] SaleState saleState)
 {
     if (ModelState.IsValid)
     {
         db.Entry(saleState).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(saleState));
 }
Exemple #17
0
        public void Constructor_throws_ArgumentNullException_if_Mutator_null()
        {
            SaleState StateAccessor(Sale sale) => sale.State;

            const SaleState toState = SaleState.ChangeDue;

            Assert.Throws <ArgumentNullException>(() => new StateConfigurationBaseTester <Sale, SaleState, SaleEvent>(StateAccessor
                                                                                                                      , stateMutator: null
                                                                                                                      , state: toState));
        }
        public ActionResult Create([Bind(Include = "idSaleState,state")] SaleState saleState)
        {
            if (ModelState.IsValid)
            {
                db.SaleStates.Add(saleState);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(saleState));
        }
Exemple #19
0
        public void Constructor_throws_ArgumentNullException_if_Accessor_null()
        {
            Func <Sale, SaleState> stateAccessor = null;

            void StateMutator(Sale sale, SaleState newState) => sale.State = newState;

            const SaleState toState = SaleState.ChangeDue;

            Assert.Throws <ArgumentNullException>(() => new StateConfigurationBaseTester <Sale, SaleState, SaleEvent>(stateAccessor
                                                                                                                      , StateMutator
                                                                                                                      , toState));
        }
        public void UpdateData()
        {
            string text;

            if (!this.Entity.HasComponent <PaymentGiftComponent>())
            {
                this.giftLabel.SetActive(false);
            }
            else
            {
                PaymentGiftComponent component = this.Entity.GetComponent <PaymentGiftComponent>();
                Platform.Kernel.ECS.ClientEntitySystem.API.Entity marketItem = Flow.Current.EntityRegistry.GetEntity(component.Gift);
                this.giftPreview.SpriteUid = marketItem.GetComponent <ImageItemComponent>().SpriteUid;
                this.giftLabel.SetActive(true);
                this.giftPreview.GetComponent <TooltipShowBehaviour>().TipText = MarketItemNameLocalization.GetFullItemDescription(marketItem, (string)this._commonString, (string)this._rareString, (string)this._epicString, (string)this._legendaryString);
            }
            XCrystalsPackComponent component2 = this.Entity.GetComponent <XCrystalsPackComponent>();
            SaleState saleState = this.Entity.GetComponent <GoodsComponent>().SaleState;
            string    str       = "<b>  ";
            long      amount    = component2.Amount;
            long      num2      = (long)Math.Round((double)(component2.Amount * saleState.AmountMultiplier));
            long      bonus     = component2.Bonus;

            if (saleState.AmountMultiplier <= 1.0)
            {
                str = str + amount.ToStringSeparatedByThousands();
                object[] objArray2 = new object[] { ((long)(amount + bonus)).ToStringSeparatedByThousands(), "<sprite=", this.xCrySpriteIndex, ">" };
                this.totalAmount.text = string.Concat(objArray2);
            }
            else
            {
                str = str + num2.ToStringSeparatedByThousands() + $" <s><#{this.greyColor.Color.ToHexString()}>{amount.ToStringSeparatedByThousands()}</color></s>";
                this.totalAmount.text = ((long)(num2 + bonus)).ToStringSeparatedByThousands();
                this.totalAmount.text = this.totalAmount.text + $" <s><#{this.greyColor.Color.ToHexString()}>{((long) (amount + bonus)).ToStringSeparatedByThousands()}</color></s>";
                text = this.totalAmount.text;
                object[] objArray1 = new object[] { text, "<sprite=", this.xCrySpriteIndex, ">" };
                this.totalAmount.text = string.Concat(objArray1);
            }
            text = str;
            object[] objArray3 = new object[] { text, "</b><sprite=", this.xCrySpriteIndex, ">\n" };
            str = string.Concat(objArray3);
            str = (bonus <= 0L) ? (str + "\n") : (str + string.Format("<size=17><#{2}>+{0} {1}<sprite=" + this.xCrySpriteIndex + "></color>", bonus.ToStringSeparatedByThousands(), this.forFree.Value, this.greyColor.Color.ToHexString()));
            this.amount.text = str;
            GoodsPriceComponent component4 = this.Entity.GetComponent <GoodsPriceComponent>();

            str = component4.Round(this.Entity.GetComponent <GoodsComponent>().SaleState.PriceMultiplier *component4.Price).ToStringSeparatedByThousands();
            if (saleState.PriceMultiplier < 1.0)
            {
                str = str + $" <s><#{this.greyColor.Color.ToHexString()}>{component4.Price.ToStringSeparatedByThousands()}</color></s>";
            }
            str             = str + " " + component4.Currency;
            this.price.text = str;
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SaleState saleState = db.SaleStates.Find(id);

            if (saleState == null)
            {
                return(HttpNotFound());
            }
            return(View(saleState));
        }
Exemple #22
0
        public void Constructor_sets_properties()
        {
            SaleState StateAccessor(Sale sale) => sale.State;
            void StateMutator(Sale sale, SaleState newState) => sale.State = newState;

            const SaleState toState = SaleState.ChangeDue;

            var sut = new StateConfigurationBaseTester <Sale, SaleState, SaleEvent>(StateAccessor
                                                                                    , StateMutator
                                                                                    , toState);

            Assert.Equal(StateAccessor, sut.StateAccessor);
            Assert.Equal(StateMutator, sut.StateMutator);
            Assert.Equal(toState, sut.State);
        }
        public void Execute_throws_ArgumentException_if_Request_is_wrong_type()
        {
            const SaleState startState = SaleState.Open;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };
            var sut = new StateTransitionAutoForwardParameterized <Sale, SaleState, SaleEvent, string>(
                GetStateMachine()
                , SaleState.Complete
                , SaleState.Open
                , condition: (_, stringParam) => true
                , name: "test"
                , priority: 1);

            var executionParams = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request: 1);

            Assert.Throws <ArgumentException>(() => sut.Execute(executionParams, GetDummyResult()));
        }
Exemple #24
0
    public void PlayerWin()
    {
        StopAllCoroutines();
        guitarHeroGame.ClearAllNotes();
        gameUi.Hide();
        gameUi.Victory();
        saleState = SaleState.End;
        StopAllCoroutines();
        PlayerManager.Instance.playerCash += currentPlayerCash;
        currentPlayerCash = 0;
        // ADRIEN
        SoundManager.StopSFX(conv);
        AudioClip sfx;

        sfx = Resources.Load("Sounds/Victory") as AudioClip;
        SoundManager.PlaySFX(sfx);
        door.SetTrigger("DoorLose");
        Invoke("Contract", 1f);
        UiManager.Instance.LoadTargetScene(1, 3f);
    }
Exemple #25
0
        private void ValidateStateChange(SaleState destinationState, bool isInitialStateChange)
        {
            if (isInitialStateChange)
            {
                if (destinationState == SaleState.FundsReserved)
                {
                    return;
                }
                else
                {
                    throw new BaristaException("invalid_sale_state_transition", $"Only the {nameof(SaleState.FundsReserved)} state can be accepted as initial");
                }
            }

            switch (destinationState)
            {
            case SaleState.FundsReserved:
                throw new BaristaException("invalid_sale_state_transition", $"Sale cannot transition into {nameof(SaleState.FundsReserved)}, this state is exclusively initial");

            case SaleState.Cancelled:
                break;

            case SaleState.Confirmed:
                if (State == SaleState.FundsReserved)
                {
                    break;
                }
                else
                {
                    throw new BaristaException("invalid_sale_state_transition", $"Sale can only transition into {nameof(SaleState.Confirmed)} from the {nameof(SaleState.FundsReserved)} state");
                }

            default:
                throw new NotSupportedException($"State transition restrictions not supported for state {destinationState}");
            }

            if (State == destinationState)
            {
                throw new BaristaException("invalid_sale_state_transition", $"The sale is already in state {destinationState}");
            }
        }
Exemple #26
0
        public async Task ExecuteAsync_doesnt_change_state_if_condition_not_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionParameterizedAsync <Sale, SaleState, SaleEvent, string>(
                stateAccessor: saleToUpdate => saleToUpdate.State
                , stateMutator: (saleToUpdate, newState) => saleToUpdate.State = newState
                , toState: endState
                , conditionAsync: (_, stringParam, inCancelToken) => Task.FromResult(result: false)
                , name: "test"
                , priority: 1);

            var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request : "notUsed"));

            Assert.Equal(startState, sale.State);
        }
Exemple #27
0
        public void Execute_doesnt_change_state_if_condition_not_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransition <Sale, SaleState, SaleEvent>(
                stateAccessor: saleToUpdate => saleToUpdate.State
                , stateMutator: (saleToUpdate, newState) => saleToUpdate.State = newState
                , toState: endState
                , condition: (_) => false
                , name: "test"
                , priority: 1);

            var result = sut.Execute(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale));

            Assert.False(result.WasTransitioned);
            Assert.Equal(startState, sale.State);
        }
        public void Execute_doesnt_change_state_if_condition_not_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAutoFallback <Sale, SaleState, SaleEvent>(
                GetStateMachine()
                , startState
                , toState: endState
                , condition: (_) => false
                , triggerState: startState
                , name: "test"
                , priority: 1);

            sut.Execute(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale), GetDummyResult());

            Assert.Equal(startState, sale.State);
        }
Exemple #29
0
        public async Task ExecuteAsync_changes_state_if_condition_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAsync <Sale, SaleState, SaleEvent>(
                stateAccessor: saleToUpdate => saleToUpdate.State
                , stateMutator: (saleToUpdate, newState) => saleToUpdate.State = newState
                , toState: endState
                , conditionAsync: (_, inCancelToken) => Task.FromResult(result: true)
                , name: "test"
                , priority: 1);

            var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale));

            Assert.True(result.WasTransitioned);
            Assert.Equal(endState, sale.State);
        }
Exemple #30
0
        public async Task ExecuteAsync_changes_state_if_condition_met()
        {
            const SaleState startState = SaleState.Open;
            const SaleState endState   = SaleState.Complete;
            var             sale       = new Sale(saleID: 66)
            {
                State = startState
            };

            var sut = new StateTransitionAutoForwardParameterizedAsync <Sale, SaleState, SaleEvent, string>(
                GetStateMachine()
                , toState: endState
                , triggerState: startState
                , conditionAsync: (_, stringParam, inCancelToken) => Task.FromResult(result: true)
                , name: "test"
                , priority: 1);

            var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, request : "notUsed"), GetDummyResult());

            Assert.True(result.WasTransitioned);
            Assert.Equal(endState, sale.State);
        }