How to use OnFinal method of Microsoft.Coyote.Actors.Tests.StateMachines.PushPopStateTests class

Best Coyote code snippet using Microsoft.Coyote.Actors.Tests.StateMachines.PushPopStateTests.OnFinal

PushPopStateTests.cs

Source:PushPopStateTests.cs Github

copy

Full Screen

...35 {36 this.Trace("InitOnEntry");37 this.RaisePushStateEvent<Final>();38 }39 [OnEntry(nameof(OnFinal))]40 private class Final : State41 {42 }43 private void OnFinal()44 {45 this.Trace("OnFinal");46 this.OnFinalEvent();47 }48 }49 [Fact(Timeout = 5000)]50 public void TestPushStateTransition()51 {52 this.Test(async (IActorRuntime runtime) =>53 {54 var op = new EventGroupList();55 runtime.CreateActor(typeof(M1), null, op);56 await this.GetResultAsync(op.Task);57 var actual = op.ToString();58 Assert.Equal("InitOnEntry, CurrentState=Final, OnFinal", actual);59 });60 }61 private class M2 : TraceableStateMachine62 {63 [Start]64 [OnEntry(nameof(InitOnEntry))]65 [OnEventPushState(typeof(E1), typeof(Final))]66 private class Init : State67 {68 }69 private void InitOnEntry()70 {71 this.TraceOp.AddItem("InitOnEntry");72 }73 [OnEntry(nameof(OnFinal))]74 private class Final : State75 {76 }77 private void OnFinal()78 {79 this.TraceOp.AddItem("OnFinal");80 this.OnFinalEvent();81 }82 }83 [Fact(Timeout = 5000)]84 public void TestPushStateTransitionAfterSend()85 {86 this.Test(async (IActorRuntime runtime) =>87 {88 var op = new EventGroupList();89 var id = runtime.CreateActor(typeof(M2), null, op);90 runtime.SendEvent(id, new E1());91 await this.GetResultAsync(op.Task);92 var actual = op.ToString();93 Assert.Equal("InitOnEntry, CurrentState=Final, OnFinal", actual);94 });95 }96 private class M3 : TraceableStateMachine97 {98 [Start]99 [OnEntry(nameof(InitOnEntry))]100 [OnEventPushState(typeof(E1), typeof(Final))]101 private class Init : State102 {103 }104 private void InitOnEntry()105 {106 this.Trace("InitOnEntry");107 this.Trace("RaiseEvent");108 this.RaiseEvent(new E1());109 }110 [OnEntry(nameof(OnFinal))]111 private class Final : State112 {113 }114 private void OnFinal()115 {116 this.Trace("OnFinal");117 this.OnFinalEvent();118 }119 }120 [Fact(Timeout = 5000)]121 public void TestPushStateTransitionAfterRaise()122 {123 this.Test(async (IActorRuntime runtime) =>124 {125 var op = new EventGroupList();126 var id = runtime.CreateActor(typeof(M3), null, op);127 await this.GetResultAsync(op.Task);128 var actual = op.ToString();129 Assert.Equal("InitOnEntry, RaiseEvent, CurrentState=Final, OnFinal", actual);130 });131 }132 private class M4 : TraceableStateMachine133 {134 [Start]135 [OnEntry(nameof(InitOnEntry))]136 [OnEventPushState(typeof(E1), typeof(Final))]137 private class Init : State138 {139 }140 private void InitOnEntry()141 {142 this.Trace("InitOnEntry");143 }144 [OnEventDoAction(typeof(E2), nameof(Pop))]145 private class Final : State146 {147 }148 private void Pop()149 {150 this.Trace("Pop");151 this.RaisePopStateEvent();152 this.OnFinalEvent();153 }154 }155 [Fact(Timeout = 5000)]156 public void TestPushPopTransition()157 {158 this.Test(async (IActorRuntime runtime) =>159 {160 var op = new EventGroupList();161 var id = runtime.CreateActor(typeof(M4), null, op);162 runtime.SendEvent(id, new E1());163 runtime.SendEvent(id, new E2());164 await this.GetResultAsync(op.Task);165 var actual = op.ToString();166 // the CurrentState=Init that happens as a result of Pop is timing sensitive and167 // there is no state machine call back to tell us when this happens, so we just use168 // a Contains test here to deal with that non-determinism.169 Assert.Contains("InitOnEntry, CurrentState=Final, Pop", actual);170 });171 }172 /// <summary>173 /// Test that Defer, Ignore and DoAction can be inherited.174 /// </summary>175 private class M5 : TraceableStateMachine176 {177 [Start]178 [OnEventPushState(typeof(E1), typeof(Final))]179 [DeferEvents(typeof(E2))]180 [IgnoreEvents(typeof(E3))]181 [OnEventDoAction(typeof(E4), nameof(FinalEvent))]182 private class Init : State183 {184 }185 [OnEventDoAction(typeof(E2), nameof(HandleEvent))]186 private class Final : State187 {188 }189 private void HandleEvent()190 {191 this.Trace("HandleEvent");192 }193 private void FinalEvent()194 {195 this.Trace("FinalEvent");196 this.OnFinalEvent();197 }198 }199 [Fact(Timeout = 5000)]200 public void TestPushStateInheritance()201 {202 this.Test(async (IActorRuntime runtime) =>203 {204 var op = new EventGroupList();205 var id = runtime.CreateActor(typeof(M5), null, op);206 runtime.SendEvent(id, new E2()); // should be deferred207 runtime.SendEvent(id, new E1()); // push208 runtime.SendEvent(id, new E3()); // ignored209 runtime.SendEvent(id, new E4()); // inherited handler210 await this.GetResultAsync(op.Task);211 var actual = op.ToString();212 Assert.Equal("CurrentState=Final, HandleEvent, FinalEvent", actual);213 });214 }215 /// <summary>216 /// Test you cannot have duplicated handlers for the same event.217 /// </summary>218 private class M6 : StateMachine219 {220 public List<string> Log = new List<string>();221 [Start]222 [DeferEvents(typeof(E2))]223 [IgnoreEvents(typeof(E2))]224 private class Init : State225 {226 }227 }228 [Fact(Timeout = 5000)]229 public void TestDuplicateHandler()230 {231 this.TestWithError((IActorRuntime runtime) =>232 {233 runtime.CreateActor(typeof(M6));234 },235 expectedError: "M6(0) declared multiple handlers for event 'E2' in state 'M6+Init'.");236 }237 /// <summary>238 /// Test you cannot have duplicated handlers for the same event.239 /// </summary>240 private class M7 : StateMachine241 {242 public List<string> Log = new List<string>();243 [Start]244 [DeferEvents(typeof(E2))]245 [OnEventGotoState(typeof(E2), typeof(Final))]246 private class Init : State247 {248 }249 private class Final : State250 {251 }252 }253 [Fact(Timeout = 5000)]254 public void TestDuplicateHandler2()255 {256 this.TestWithError((IActorRuntime runtime) =>257 {258 runtime.CreateActor(typeof(M7));259 },260 expectedError: "M7(0) declared multiple handlers for event 'E2' in state 'M7+Init'.");261 }262 /// <summary>263 /// Test if you have duplicate handlers for the same event on inherited State class then the264 /// most derrived handler wins.265 /// </summary>266 [DeferEvents(typeof(E1))]267 [IgnoreEvents(typeof(E2))]268 [OnEventGotoState(typeof(E3), typeof(StateMachine.State))]269 [OnEventPushState(typeof(E4), typeof(StateMachine.State))]270 private class BaseState : StateMachine.State271 {272 }273 private class M8 : StateMachine274 {275 public List<string> Log = new List<string>();276 [Start]277 [OnEventGotoState(typeof(E1), typeof(Final))]278 private class Init : BaseState279 {280 }281 [OnEventDoAction(typeof(E1), nameof(HandleEvent))]282 private class Final : State283 {284 }285 private void HandleEvent()286 {287 this.Assert(false, "HandleEvent not happen!");288 }289 }290 [Fact(Timeout = 5000)]291 public void TestInheritedDuplicateHandler()292 {293 this.TestWithError((IActorRuntime runtime) =>294 {295 runtime.CreateActor(typeof(M8));296 },297 expectedError: "M8(0) inherited multiple handlers for event 'E1' from state 'BaseState' in state 'M8+Init'.");298 }299 private class M9 : TraceableStateMachine300 {301 [Start]302 [DeferEvents(typeof(E1))]303 [IgnoreEvents(typeof(E2))]304 [OnEventGotoState(typeof(E3), typeof(Final))]305 private class Init : BaseState306 {307 }308 [OnEventDoAction(typeof(E1), nameof(HandleEvent))]309 private class Final : State310 {311 }312 private void HandleEvent(Event e)313 {314 this.Trace("HandleEvent:{0}", e.GetType().Name);315 this.OnFinalEvent();316 }317 }318 [Fact(Timeout = 5000)]319 public void TestInheritedDuplicateDeferHandler()320 {321 this.Test(async (IActorRuntime runtime) =>322 {323 var op = new EventGroupList();324 var id = runtime.CreateActor(typeof(M9), null, op);325 runtime.SendEvent(id, new E1()); // should be deferred326 runtime.SendEvent(id, new E2()); // should be ignored327 runtime.SendEvent(id, new E3()); // should trigger goto, where deferred E1 can be handled.328 await this.GetResultAsync(op.Task);329 var actual = op.ToString();...

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Actors.Timers;8using Microsoft.Coyote.SystematicTesting;9using Microsoft.Coyote.Specifications;10using Microsoft.Coyote.Tasks;11using Microsoft.Coyote;12using Microsoft.Coyote.Actors.SharedObjects;13using Microsoft.Coyote.Actors.BugFinding;14using Microsoft.Coyote.Actors.BugFinding.Strategies;15using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration;16using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph;17using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies;18using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration;19using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics;20using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding;21using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding.Strategies;22using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding.Strategies.Probabilistic;23using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding.Strategies.Probabilistic.Strategies;24using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding.Strategies.Probabilistic.Strategies.Probabilistic;25using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding.Strategies.Probabilistic.Strategies.Probabilistic.Strategies;26using Microsoft.Coyote.Actors.BugFinding.Strategies.StateExploration.Graph.Strategies.DFSExploration.Heuristics.BugFinding.Strategies.Probabilistic.Strategies.Probabilistic.Strategies.Probabilistic;

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote.Actors;4using Microsoft.Coyote.Actors.Timers;5using Microsoft.Coyote.TestingServices;6using Microsoft.Coyote.TestingServices.Runtime;7using Microsoft.Coyote.TestingServices.SchedulingStrategies;8using Microsoft.Coyote.TestingServices.Tracing.Schedule;9using Microsoft.Coyote.Tests.Common;10using Xunit;11using Xunit.Abstractions;12{13 {14 public PushPopStateTests(ITestOutputHelper output)15 : base(output)16 {17 }18 {19 public ActorId Id;20 public Config(ActorId id)21 {22 this.Id = id;23 }24 }25 {26 }27 {28 }29 {30 protected override Task OnInitializeAsync(Event initialEvent)31 {32 this.RaiseEvent(new E());33 return Task.CompletedTask;34 }35 [OnEventGotoState(typeof(E), typeof(S1))]36 [OnEventDoAction(typeof(Unit), nameof(DoNothing))]37 {38 }39 [OnEntry(nameof(Entry))]40 [OnExit(nameof(Exit))]41 {42 }43 private void Entry()44 {45 this.RaiseEvent(new Unit());46 }47 private void Exit()48 {49 this.RaiseEvent(new Unit());50 }51 private void DoNothing()52 {53 }54 }55 [Fact(Timeout = 5000)]56 public void TestPushPopState()57 {58 this.TestWithError(r =>59 {60 r.RegisterMonitor(typeof(Monitors.PushPopStateMonitor));61 r.CreateActor(typeof(M));62 },63 configuration: GetConfiguration().WithTestingIterations(100),64 replay: true);65 }66 }67}68using System;69using System.Collections.Generic;70using System.Linq;71using System.Text;72using System.Threading.Tasks;73using Microsoft.Coyote.Actors;74using Microsoft.Coyote.Actors.Timers;

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Actors.Timers;8using Microsoft.Coyote.Actors.BugFinding;9using Microsoft.Coyote.Actors.BugFinding.Services;10using Microsoft.Coyote.Actors.BugFinding.Strategies;11using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration;12using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic;13using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution;14using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions;15using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Integer;16using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Real;17using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.String;18using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Boolean;19using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Set;20using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Tuple;21using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Enum;22using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Struct;23using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Array;24using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Collection;25using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Dictionary;26using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Delegate;27using Microsoft.Coyote.Actors.BugFinding.Strategies.RandomExploration.Probabilistic.Distribution.Distributions.Task;

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Text;4using System.Threading.Tasks;5using Microsoft.Coyote;6using Microsoft.Coyote.Actors;7using Microsoft.Coyote.Testing;8using Microsoft.Coyote.TestingServices;9using Xunit;10using Xunit.Abstractions;11{12 {13 public PushPopStateTests(ITestOutputHelper output)14 : base(output)15 {16 }17 {18 public ActorId Id;19 public Config(ActorId id)20 {21 this.Id = id;22 }23 }24 {25 }26 {27 }28 {29 }30 {31 }32 {33 [OnEntry(nameof(InitOnEntry))]34 [OnEventDoAction(typeof(Unit), nameof(DoUnit))]35 [OnEventGotoState(typeof(Unit), typeof(S2))]36 {37 }38 private void InitOnEntry(Event e)39 {40 this.RaiseEvent(new Unit());41 }42 private void DoUnit()43 {44 this.PushState(typeof(S1));45 this.PushState(typeof(S2));46 this.PushState(typeof(S3));47 }48 }49 {50 [OnEntry(nameof(InitOnEntry))]51 [OnEventDoAction(typeof(Unit), nameof(DoUnit))]52 [OnEventGotoState(typeof(Unit), typeof(S2))]53 {54 }55 private void InitOnEntry(Event e)56 {57 this.RaiseEvent(new Unit());58 }59 private void DoUnit()60 {61 this.PushState(typeof(S2));62 this.PushState(typeof(S1));63 this.PushState(typeof(S3));64 }65 }66 {67 [OnEntry(nameof(InitOnEntry))]68 [OnEventDoAction(typeof(Unit), nameof(DoUnit))]69 [OnEventGotoState(typeof(Unit), typeof(S2))]70 {71 }72 private void InitOnEntry(Event e)

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.Actors.Tests;3using System;4using System.Collections.Generic;5using System.Text;6using System.Threading.Tasks;7using Xunit;8using Xunit.Abstractions;9{10 {11 public PushPopStateTests(ITestOutputHelper output)12 : base(output)13 {14 }15 [Fact(Timeout = 5000)]16 public void TestPushPopState()17 {18 this.Test(async r =>19 {

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests;2using Microsoft.Coyote.Actors;3using System;4using System.Threading.Tasks;5using Microsoft.Coyote;6using Microsoft.Coyote.TestingServices;7using Microsoft.Coyote.TestingServices.Runtime;8using Microsoft.Coyote.TestingServices.SchedulingStrategies;9using Microsoft.Coyote.TestingServices.Threading;10using Microsoft.Coyote.TestingServices.Tracing.Schedule;11using Microsoft.Coyote.TestingServices.Tracing.Schedule;12using System;13using System.Collections.Generic;14using System.Diagnostics;15using System.IO;16using System.Linq;17using System.Text;18using System.Threading;19using System.Threading.Tasks;20using Microsoft.Coyote.Actors;

Full Screen

Full Screen

OnFinal

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests;2using Microsoft.Coyote.Actors;3using Microsoft.Coyote.Actors.Timers;4using Microsoft.Coyote.Actors.SharedObjects;5using Microsoft.Coyote.Actors.SharedObjects.Unsafe;6using Microsoft.Coyote.Runtime;7using Microsoft.Coyote.Specifications;8using Microsoft.Coyote.Tasks;9using Microsoft.Coyote.Tasks.SharedObjects;10using Microsoft.Coyote.Tasks.SharedObjects.Unsafe;11using Microsoft.Coyote.TestingServices;12using Microsoft.Coyote.TestingServices.SchedulingStrategies;13using Microsoft.Coyote.TestingServices.SchedulingStrategies.DPOR;14using Microsoft.Coyote.TestingServices.SchedulingStrategies.Fuzzing;15using Microsoft.Coyote.TestingServices.SchedulingStrategies.ProbabilisticRandomExecution;16using Microsoft.Coyote.TestingServices.SchedulingStrategies.RandomExecution;17using Microsoft.Coyote.TestingServices.SchedulingStrategies.Unfair;18using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairDeterministic;19using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairProbabilistic;20using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairProbabilisticRandomExecution;21using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomExecution;22using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomSubset;23using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomSubsetDeterministic;24using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomSubsetProbabilistic;25using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomSubsetProbabilisticRandomExecution;26using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomSubsetRandomExecution;27using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomWalk;28using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomWalkDeterministic;29using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomWalkProbabilistic;30using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomWalkProbabilisticRandomExecution;31using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomWalkRandomExecution;32using Microsoft.Coyote.TestingServices.SchedulingStrategies.UnfairRandomWalkWithFairRandomSubset;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful