OnTransitioned must be called before OnEntry

This is a behavior fix for the ordering of events that are fired by the StateMachine during a state transition.

Description: In the previous version, if the action/lambda that is called as part of the OnEntry event results in a state transition (recursively), the state transitions events fired using the OnTransitioned method are captured in the reverse (wrong) order. The fix for this is to raise the OnTransitioned event as soon as the state transition occurs (before the OnEntry event).

Added unit test to verify new behavior.