Skip to content

Commit

Permalink
add loaded events to IExtension method Loaded(..) for Sync SM
Browse files Browse the repository at this point in the history
  • Loading branch information
wtjerry committed Oct 3, 2019
1 parent 25ff0fc commit 6bf0099
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ public void SetsCurrentStateOnLoadingFromPersistedState(string dummyName, Func<S
.Matches(currentState =>
currentState.IsInitialized
&& currentState.ExtractOrThrow() == States.C),
A<IReadOnlyDictionary<States, States>>.Ignored))
A<IReadOnlyDictionary<States, States>>.Ignored,
A<IReadOnlyCollection<EventInformation<Events>>>.Ignored))
.MustHaveHappenedOnceExactly();
}

Expand Down Expand Up @@ -393,6 +394,7 @@ public void SetsHistoryStatesOnLoadingFromPersistedState()
public void SetsEventsOnLoadingFromPersistedState(string dummyName, Func<StateMachineDefinition<States, Events>, IStateMachine<States, Events>> createStateMachine)
{
var enteredB = false;
var extension = A.Fake<IExtension<States, Events>>();

var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder<States, Events>();
stateMachineDefinitionBuilder
Expand All @@ -406,18 +408,30 @@ public void SetsEventsOnLoadingFromPersistedState(string dummyName, Func<StateMa
.WithInitialState(States.A)
.Build();
var testee = createStateMachine(stateMachineDefinition);
testee.AddExtension(extension);

var loader = A.Fake<IStateMachineLoader<States, Events>>();

var eventInformation = new EventInformation<Events>(Events.E, null);
A.CallTo(() => loader.LoadEvents())
.Returns(new List<EventInformation<Events>> { new EventInformation<Events>(Events.E, null) });
.Returns(new List<EventInformation<Events>> { eventInformation });
A.CallTo(() => loader.LoadCurrentState())
.Returns(Initializable<States>.UnInitialized());

testee.Load(loader);

A.CallTo(() => extension.Loaded(
A<IStateMachineInformation<States, Events>>.Ignored,
A<Initializable<States>>.Ignored,
A<IReadOnlyDictionary<States, States>>.Ignored,
A<IReadOnlyCollection<EventInformation<Events>>>
.That
.Matches(c =>
c.Count == 1
&& c.Contains(eventInformation))))
.MustHaveHappenedOnceExactly();

var signal = new AutoResetEvent(false);
var extension = A.Fake<IExtension<States, Events>>();
A.CallTo(() =>
extension.EnteredInitialState(
A<IStateMachineInformation<States, Events>>.Ignored,
Expand Down
3 changes: 2 additions & 1 deletion source/Appccelerate.StateMachine.Specs/Sync/Persisting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ public class FakeExtension : ExtensionBase<State, Event>
public override void Loaded(
IStateMachineInformation<State, Event> stateMachineInformation,
IInitializable<State> loadedCurrentState,
IReadOnlyDictionary<State, State> loadedHistoryStates)
IReadOnlyDictionary<State, State> loadedHistoryStates,
IReadOnlyCollection<EventInformation<Event>> events)
{
this.LoadedCurrentState.Add(loadedCurrentState);
}
Expand Down
3 changes: 2 additions & 1 deletion source/Appccelerate.StateMachine/ActiveStateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ void NotifyExtensions()
this.stateContainer.Extensions.ForEach(
extension => extension.Loaded(
loadedCurrentState,
historyStates));
historyStates,
events));
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/Appccelerate.StateMachine/Extensions/ExtensionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ public virtual void EnteringState(
public virtual void Loaded(
IStateMachineInformation<TState, TEvent> stateMachineInformation,
IInitializable<TState> loadedCurrentState,
IReadOnlyDictionary<TState, TState> loadedHistoryStates)
IReadOnlyDictionary<TState, TState> loadedHistoryStates,
IReadOnlyCollection<EventInformation<TEvent>> events)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ public void ExecutedTransition(

public void Loaded(
IInitializable<TState> loadedCurrentState,
IReadOnlyDictionary<TState, TState> loadedHistoryStates)
IReadOnlyDictionary<TState, TState> loadedHistoryStates,
IReadOnlyCollection<EventInformation<TEvent>> events)
{
this.apiExtension.Loaded(this.stateMachineInformation, loadedCurrentState, loadedHistoryStates);
this.apiExtension.Loaded(this.stateMachineInformation, loadedCurrentState, loadedHistoryStates, events);
}

public void EnteringState(IStateDefinition<TState, TEvent> stateDefinition, ITransitionContext<TState, TEvent> context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public virtual void ExecutedTransition(

public virtual void Loaded(
IInitializable<TState> loadedCurrentState,
IReadOnlyDictionary<TState, TState> loadedHistoryStates)
IReadOnlyDictionary<TState, TState> loadedHistoryStates,
IReadOnlyCollection<EventInformation<TEvent>> events)
{
}

Expand Down
3 changes: 2 additions & 1 deletion source/Appccelerate.StateMachine/Machine/IExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void EnteringState(
void Loaded(
IStateMachineInformation<TState, TEvent> stateMachineInformation,
IInitializable<TState> loadedCurrentState,
IReadOnlyDictionary<TState, TState> loadedHistoryStates);
IReadOnlyDictionary<TState, TState> loadedHistoryStates,
IReadOnlyCollection<EventInformation<TEvent>> events);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void ExecutedTransition(

void Loaded(
IInitializable<TState> loadedCurrentState,
IReadOnlyDictionary<TState, TState> loadedHistoryStates);
IReadOnlyDictionary<TState, TState> loadedHistoryStates,
IReadOnlyCollection<EventInformation<TEvent>> events);

void EnteringState(
IStateDefinition<TState, TEvent> stateDefinition,
Expand Down
3 changes: 2 additions & 1 deletion source/Appccelerate.StateMachine/PassiveStateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ void NotifyExtensions()
this.stateContainer.Extensions.ForEach(
extension => extension.Loaded(
loadedCurrentState,
historyStates));
historyStates,
events));
}
}

Expand Down

0 comments on commit 6bf0099

Please sign in to comment.