internal Outcome GetTrace(TraceGroup stateTrace, TestTransition incomingTransition) { //Trace for InternalState this.CurrentOutcome = this.ExpectedOutcome; Outcome outcome = this.ExpectedOutcome; if (!this.IsFinal) { outcome = this.GetTransitInTrace(stateTrace, incomingTransition); if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome; } if (outcome.DefaultPropogationState == OutcomeState.Completed) { if (this.HintTransition == null) { throw new InvalidOperationException(string.Format("TestStateMachineState '{0}' HintTransition is null", this.DisplayName)); } outcome = this.GetTransitOutTrace(stateTrace); if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome; } } } else { this.GetStartTrace(stateTrace); if (this.Entry != null) { outcome = this.Entry.GetTrace(stateTrace); } if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome; } if (CurrentOutcome.DefaultPropogationState == OutcomeState.Completed) { this.GetCloseTrace(stateTrace); } else if (CurrentOutcome.DefaultPropogationState == OutcomeState.Canceled) { this.GetCancelTrace(stateTrace); } else if (CurrentOutcome is CaughtExceptionOutcome) { this.GetFaultTrace(stateTrace); } } _iterationNumber++; return(outcome.Propogate()); }
private void AddTransition(TestTransition transition) { if (transition != null) { _productState.Transitions.Add(transition.ProductTransition); transition.Source = this; } }
protected void InsertTransition(int i, TestTransition t) { this.ProductState.Transitions.Insert(i, t.ProductTransition); t.Source = this; }
protected bool RemoveTransition(TestTransition t) { return(this.ProductState.Transitions.Remove(t.ProductTransition)); }
private Outcome GetTransitInTrace(TraceGroup stateTraceGroup, TestTransition incomingTransition) { HashSet <TestActivity> triggerHash = new HashSet <TestActivity>(); UnorderedTraces triggerTrace = new UnorderedTraces(); Outcome outcome = this.ExpectedOutcome; this.CurrentOutcome = this.ExpectedOutcome; this.GetStartTrace(stateTraceGroup); outcome = this.GetEntryTrace(stateTraceGroup); if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome; } if (outcome.DefaultPropogationState == OutcomeState.Completed) { stateTraceGroup.Steps.Add(triggerTrace); foreach (TestTransition t in this.Transitions) { // Shared trigger transitions if (triggerHash.Add(t.Trigger)) { outcome = t.GetTriggerTrace(triggerTrace); if (outcome.DefaultPropogationState == OutcomeState.Completed) { outcome = t.GetConditionTrace(triggerTrace); if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome.Propogate(); } } else if (outcome.DefaultPropogationState == OutcomeState.Faulted || outcome is UncaughtExceptionOutcome || outcome is CaughtExceptionOutcome) { if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome.Propogate(); } } // trigger cancel can mean two things: // 1. trigger is cancelled by another trigger. This is normal behavior. // 2. trigger is cancelled externally. In such case, Transition.ExpectedOutcome should be set to canceled. else if (outcome.DefaultPropogationState == OutcomeState.Canceled) { if (t.ExpectedOutcome.DefaultPropogationState == OutcomeState.Canceled) { if (this.CurrentOutcome.IsOverrideable) { this.CurrentOutcome = outcome.Propogate(); } } continue; } } else { outcome = t.GetConditionTrace(triggerTrace); if (outcome.DefaultPropogationState != OutcomeState.Completed) { if (CurrentOutcome.IsOverrideable) { CurrentOutcome = outcome.Propogate(); } } } } } if (this.CurrentOutcome.DefaultPropogationState == OutcomeState.Canceled) { this.GetCancelTrace(stateTraceGroup); } return(this.CurrentOutcome.Propogate()); }
protected override void GetActivitySpecificTrace(TraceGroup traceGroup) { // To support PartialTrust, StateMachineEventManagerFactory activity is used in Variable<StateMachineEventManager>.Default // The code below generates the expected trace for StateMachineEventManagerFactory activity new TestDummyTraceActivity("StateMachineEventManagerFactory").GetTrace(traceGroup); Stack <TestStateMachineState> stack = new Stack <TestStateMachineState>(); // get trace for initial state TestTransition fakeInitialTransition = new TestTransition("fakeinitial") { To = this.InitialState }; Outcome outcome = this.ExpectedOutcome; TraceGroup ordered = new OrderedTraces(); traceGroup.Steps.Add(ordered); TestStateMachineState currentState = null; TestTransition t = fakeInitialTransition; while (t != null && t.To != null && t.To.IsFinal != true) { TestTransition nextTransition = null; currentState = t.To; OrderedTraces stateTrace = new OrderedTraces(); ordered.Steps.Add(stateTrace); // keep HintTransition in nextTransition, because TestStateMachineState.GetTrace increases TestStateMachineState.iterationNumber nextTransition = currentState.HintTransition; outcome = currentState.GetTrace(stateTrace, t); if (CurrentOutcome.IsOverrideable) { CurrentOutcome = outcome.Propogate(); } if (CurrentOutcome.DefaultPropogationState != OutcomeState.Completed) { break; } t = nextTransition; } if (t == null || t.To == null) { throw new InvalidOperationException("Invalid HintTransition: null"); } else if (CurrentOutcome.DefaultPropogationState == OutcomeState.Completed) { if (t.To.IsFinal == true) { outcome = t.To.GetTrace(traceGroup, null); if (CurrentOutcome.IsOverrideable) { CurrentOutcome = outcome.Propogate(); } } else { throw new InvalidOperationException(string.Format("Invalid HintTransition: {0}", t.To.DisplayName)); } } // faulting and cancellation will be handled by TestActivity }