1

for the implementation of a unit test I need to setup a specific state of an object. As the state is implemented with a state machine, MDriven rejects the direct assignment of the state value to the attribute.

I could maybe trigger through the complete state machine until I reach the needed state but I assume that there is an easier way to set the state to a specific value that is rather hidden as it normlaly isn't supposed to work that way.

Does anybody know how this could be done?

2 Answers2

0

Yes - read details here https://wiki.mdriven.net/index.php/StateMachineForceMode

But basically you set the state machine for an attribute into ForceMode - after this you can freely change the state value:

self.stateMachineForceMode('State'); 
self.State:='State3'; 
Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15
0
        public void StateMachineForceState(string NewState)
    { //use with caution
        string ForceMode = "self.stateMachineForceMode('TheStateAttribute')";
        string close = "self.TheStateAttribute :='close'";
        string open = "self.TheStateAttribute='open'";
        Eco.Handles.DefaultEcoSpace es = this.AsIObject().ServiceProvider().GetEcoService<IEcoSpaceService>() as Eco.Handles.DefaultEcoSpace;
        switch (NewState)
        {
            case "close":
                es.ActionLanguage.Execute(this, ForceMode);
                es.ActionLanguage.Execute(this, close);
                break;
            case "open":
                es.ActionLanguage.Execute(this, ForceMode);
                es.ActionLanguage.Execute(this, open);
                break;
            default:
                break;
        }
    }
Steve.Au
  • 31
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 03 '22 at 15:44