private void AddEdge(XElement graph, TransitionDictionary <TState, TEvent> .TransitionInfo transition) { string actions = CreateActionsDescription(transition); string guard = CreateGuardDescription(transition); string arrow; string lineStyle; string targetId; if (transition.Target != null) { arrow = "standard"; lineStyle = "line"; targetId = transition.Target.Id.ToString(); } else { arrow = "plain"; lineStyle = "dashed"; targetId = transition.Source.Id.ToString(); } var edge = new XElement( n + "edge", new XAttribute("id", transition.EventId + (this.edgeId++).ToString(CultureInfo.InvariantCulture)), new XAttribute("source", transition.Source.Id), new XAttribute("target", targetId)); edge.Add(new XElement( n + "data", new XAttribute("key", "d10"), new XElement(y + "PolyLineEdge", new XElement(y + "LineStyle", new XAttribute("type", lineStyle)), new XElement(y + "Arrows", new XAttribute("source", "none"), new XAttribute("target", arrow)), new XElement(y + "EdgeLabel", guard + transition.EventId + actions)))); graph.Add(edge); }
/// <summary> /// Initializes a new instance of the <see cref="StateDefinition{TState,TEvent}"/> class. /// </summary> /// <param name="id">The unique id of this state.</param> public StateDefinition(TState id) { this.Id = id; this.level = 1; this.transitions = new TransitionDictionary <TState, TEvent>(this); }
public void GetTransitionsReturnsOneAddedTransition() { var testee = new TransitionDictionary <States, Events>(A.Fake <StateDefinition <States, Events> >()); var fakeAction = A.Fake <IActionHolder>(); var fakeGuard = A.Fake <IGuardHolder>(); var fakeSource = A.Fake <StateDefinition <States, Events> >(); var fakeTarget = A.Fake <StateDefinition <States, Events> >(); var transition = new TransitionDefinition <States, Events>(); testee.Add(Events.A, transition); transition.ActionsModifiable.Add(fakeAction); transition.Guard = fakeGuard; transition.Source = fakeSource; transition.Target = fakeTarget; var transitionInfos = testee.GetTransitions().ToList(); transitionInfos.Should().HaveCount(1); var transitionInfo = transitionInfos.Single(); transitionInfo.EventId.Should().Be(Events.A); transitionInfo.Actions.Should().ContainSingle(x => x == fakeAction); transitionInfo.Guard.Should().BeSameAs(fakeGuard); transitionInfo.Source.Should().BeSameAs(fakeSource); transitionInfo.Target.Should().BeSameAs(fakeTarget); }
public EventStateMachine(DeltaFunction <S, A> deltaFunction, ICollection <S> startStates) : base(deltaFunction, startStates) { stateActions = new StateDictionary <S, ActionInfo>(deltaFunction.States); transitionActions = new TransitionDictionary <S, A, ActionInfo>(deltaFunction.States, deltaFunction.Alphabet); invokeEnterActionsOnJump = true; invokeExitActionsOnJump = true; }
/// <summary> /// Initializes a new instance of the <see cref="State<TState, TEvent>"/> class. /// </summary> /// <param name="id">The unique id of this state.</param> /// <param name="stateMachineInformation">The state machine information.</param> /// <param name="extensionHost">The extension host.</param> public State(TState id, IStateMachineInformation <TState, TEvent> stateMachineInformation, IExtensionHost <TState, TEvent> extensionHost) { this.Id = id; this.level = 1; this.stateMachineInformation = stateMachineInformation; this.extensionHost = extensionHost; this.subStates = new List <IState <TState, TEvent> >(); this.transitions = new TransitionDictionary <TState, TEvent>(this); this.EntryActions = new List <IActionHolder>(); this.ExitActions = new List <IActionHolder>(); }
/// <summary> /// Initializes a new instance of the <see cref="State<TState, TEvent>"/> class. /// </summary> /// <param name="id">The unique id of this state.</param> /// <param name="notifier"></param> public State(TState id, INotifier <TState, TEvent> notifier) { this.Id = id; this.level = 1; this.notifier = notifier; this.regions = new List <IRegion <TState, TEvent> >(); this.transitions = new TransitionDictionary <TState, TEvent>(this); this.completionTransitions = new List <ITransition <TState, TEvent> >(); this.entryActions = new List <IActionHolder>(); this.doActions = new List <IDoActionHolder>(); this.exitActions = new List <IActionHolder>(); }
public void GetTransitionsReturnsAllAddedTransitions() { var testee = new TransitionDictionary <States, Events>(A.Fake <StateDefinition <States, Events> >()); var transitionA = A.Fake <TransitionDefinition <States, Events> >(); var transitionB = A.Fake <TransitionDefinition <States, Events> >(); var transitionC = A.Fake <TransitionDefinition <States, Events> >(); testee.Add(Events.A, transitionA); testee.Add(Events.B, transitionB); testee.Add(Events.C, transitionC); testee.GetTransitions().Should().HaveCount(3); }
public void TransitionWhenTransitionIsAlreadyUsedForAnotherStateThenThrowException() { var testee = new TransitionDictionary <States, Events>(A.Fake <StateDefinition <States, Events> >()); var transition = A.Fake <TransitionDefinition <States, Events> >(); transition.Source = null; testee.Add(Events.A, transition); Action action = () => testee.Add(Events.B, transition); action .Should().Throw <InvalidOperationException>() .WithMessage(TransitionsExceptionMessages.TransitionDoesAlreadyExist(transition, A.Fake <StateDefinition <States, Events> >())); }
private void ReportTransition(TransitionDictionary <TState, TEvent> .TransitionInfo transition) { string source = transition.Source.ToString(); string target = transition.Target != null?transition.Target.Id.ToString() : "internal transition"; string eventId = transition.EventId.ToString(); string guard = transition.Guard != null?transition.Guard.Describe() : string.Empty; string actions = FormatHelper.ConvertToString(transition.Actions.Select(action => action.Describe()), ", "); this.writer.WriteLine( "{0};{1};{2};{3};{4}", source, eventId, guard, target, actions); }
public TransitionDictionaryTest() { this.state = A.Fake<IState<States, Events>>(); this.testee = new TransitionDictionary<States, Events>(this.state); }
private static string CreateActionsDescription(TransitionDictionary <TState, TEvent> .TransitionInfo transition) { return(transition.Actions.Any() ? (transition.Actions.Aggregate("(", (aggregate, action) => (aggregate.Length > 1 ? aggregate + ", " : aggregate) + action.Describe()) + ")") : string.Empty); }
private static string CreateGuardDescription(TransitionDictionary <TState, TEvent> .TransitionInfo transition) { return(transition.Guard != null ? "[" + transition.Guard.Describe() + "]" : string.Empty); }
public TransitionDictionaryTest() { this.stateMock = new Mock<IState<States, Events>>(); this.testee = new TransitionDictionary<States, Events>(this.stateMock.Object); }
/// <summary> /// Reports the transition. /// </summary> /// <param name="report">The report.</param> /// <param name="indentation">The indentation.</param> /// <param name="transition">The transition.</param> private static void ReportTransition(StringBuilder report, string indentation, TransitionDictionary <TState, TEvent> .TransitionInfo transition) { report.AppendFormat( CultureInfo.InvariantCulture, "{0}{1} -> {2} actions: {3} guard: {4}{5}", indentation, transition.EventId, transition.Target != null ? transition.Target.ToString() : "internal", FormatHelper.ConvertToString(transition.Actions.Select(action => action.Describe()), ", "), transition.Guard != null ? transition.Guard.Describe() : string.Empty, Environment.NewLine); }
public TransitionDictionaryTest() { dict = new TransitionDictionary <int, int> { { (0, 1), 1 },