How to use Config1 method of Microsoft.Coyote.Actors.Tests.SendAndExecuteTests class

Best Coyote code snippet using Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config1

SendAndExecuteTests.cs

Source:SendAndExecuteTests.cs Github

copy

Full Screen

...13 public SendAndExecuteTests(ITestOutputHelper output)14 : base(output)15 {16 }17 private class Config1 : Event18 {19 public TaskCompletionSource<bool> Tcs;20 public Config1(TaskCompletionSource<bool> tcs)21 {22 this.Tcs = tcs;23 }24 }25 private class Config2 : Event26 {27 public bool HandleException;28 public TaskCompletionSource<bool> Tcs;29 public Config2(bool handleEx, TaskCompletionSource<bool> tcs)30 {31 this.HandleException = handleEx;32 this.Tcs = tcs;33 }34 }35 private class E1 : Event36 {37 public int Value;38 public E1()39 {40 this.Value = 0;41 }42 }43 private class E2 : Event44 {45 public ActorId Id;46 public E2(ActorId id)47 {48 this.Id = id;49 }50 }51 private class E3 : Event52 {53 }54 private class MHalts : Event55 {56 }57 private class SEReturns : Event58 {59 }60 private class M1 : StateMachine61 {62 [Start]63 [OnEntry(nameof(InitOnEntry))]64 private class Init : State65 {66 }67 private async SystemTasks.Task InitOnEntry(Event e)68 {69 var tcs = (e as Config1).Tcs;70 var e1 = new E1();71 var m = await this.Context.CreateActorAndExecuteAsync(typeof(N1));72 await this.Context.SendEventAndExecuteAsync(m, e1);73 this.Assert(e1.Value is 1);74 tcs.SetResult(true);75 }76 }77 private class N1 : StateMachine78 {79 private bool LEHandled = false;80 [Start]81 [OnEntry(nameof(InitOnEntry))]82 [OnEventDoAction(typeof(E1), nameof(HandleEventE))]83 [OnEventDoAction(typeof(E3), nameof(HandleEventLE))]84 private class Init : State85 {86 }87 private void InitOnEntry()88 {89 this.SendEvent(this.Id, new E3());90 }91 private void HandleEventLE()92 {93 this.LEHandled = true;94 }95 private void HandleEventE(Event e)96 {97 this.Assert(this.LEHandled);98 (e as E1).Value = 1;99 }100 }101 [Fact(Timeout = 5000)]102 public async SystemTasks.Task TestSyncSendBlocks()103 {104 await this.RunAsync(async r =>105 {106 var failed = false;107 var tcs = TaskCompletionSource.Create<bool>();108 r.OnFailure += (ex) =>109 {110 failed = true;111 tcs.SetResult(true);112 };113 r.CreateActor(typeof(M1), new Config1(tcs));114 await this.WaitAsync(tcs.Task);115 Assert.False(failed);116 },117 handleFailures: false);118 }119 private class M2 : StateMachine120 {121 [Start]122 [OnEntry(nameof(InitOnEntry))]123 [IgnoreEvents(typeof(E3))]124 private class Init : State125 {126 }127 private async SystemTasks.Task InitOnEntry(Event e)128 {129 var tcs = (e as Config1).Tcs;130 var m = await this.Context.CreateActorAndExecuteAsync(typeof(N2), new E2(this.Id));131 var handled = await this.Context.SendEventAndExecuteAsync(m, new E3());132 this.Assert(handled);133 tcs.SetResult(true);134 }135 }136 private class N2 : StateMachine137 {138 [Start]139 [OnEntry(nameof(InitOnEntry))]140 [IgnoreEvents(typeof(E3))]141 private class Init : State142 {143 }144 private async SystemTasks.Task InitOnEntry(Event e)145 {146 var creator = (e as E2).Id;147#pragma warning disable CS0618 // Type or member is obsolete148 var handled = await this.Id.Runtime.SendEventAndExecuteAsync(creator, new E3());149#pragma warning restore CS0618 // Type or member is obsolete150 this.Assert(!handled);151 }152 }153 [Fact(Timeout = 5000)]154 public async SystemTasks.Task TestSendCycleDoesNotDeadlock()155 {156 await this.RunAsync(async r =>157 {158 var failed = false;159 var tcs = TaskCompletionSource.Create<bool>();160 r.OnFailure += (ex) =>161 {162 failed = true;163 tcs.SetResult(false);164 };165 r.CreateActor(typeof(M2), new Config1(tcs));166 await this.WaitAsync(tcs.Task);167 Assert.False(failed);168 },169 handleFailures: false);170 }171 private class M3 : StateMachine172 {173 [Start]174 [OnEntry(nameof(InitOnEntry))]175 private class Init : State176 {177 }178 private async SystemTasks.Task InitOnEntry(Event e)179 {180 var tcs = (e as Config1).Tcs;181 var m = await this.Context.CreateActorAndExecuteAsync(typeof(N3));182 var handled = await this.Context.SendEventAndExecuteAsync(m, new E3());183 this.Monitor<SafetyMonitor>(new SEReturns());184 this.Assert(handled);185 tcs.TrySetResult(true);186 }187 }188 private class N3 : StateMachine189 {190 [Start]191 [OnEventDoAction(typeof(E3), nameof(HandleE))]192 private class Init : State193 {194 }195 private void HandleE() => this.RaiseHaltEvent();196 protected override SystemTasks.Task OnHaltAsync(Event e)197 {198 this.Monitor<SafetyMonitor>(new MHalts());199 return SystemTasks.Task.CompletedTask;200 }201 }202 private class SafetyMonitor : Monitor203 {204 private bool MHalted = false;205 private bool SEReturned = false;206 [Start]207 [Hot]208 [OnEventDoAction(typeof(MHalts), nameof(OnMHalts))]209 [OnEventDoAction(typeof(SEReturns), nameof(OnSEReturns))]210 private class Init : State211 {212 }213 [Cold]214 private class Done : State215 {216 }217 private void OnMHalts()218 {219 this.Assert(this.SEReturned is false);220 this.MHalted = true;221 }222 private void OnSEReturns()223 {224 this.Assert(this.MHalted);225 this.SEReturned = true;226 this.RaiseGotoStateEvent<Done>();227 }228 }229 [Fact(Timeout = 5000)]230 public async SystemTasks.Task TestMachineHaltsOnSendExec()231 {232 var config = GetConfiguration();233 config.IsMonitoringEnabledInInProduction = true;234 await this.RunAsync(async r =>235 {236 var failed = false;237 var tcs = TaskCompletionSource.Create<bool>();238 r.OnFailure += (ex) =>239 {240 failed = true;241 tcs.SetResult(false);242 };243 r.RegisterMonitor<SafetyMonitor>();244 r.CreateActor(typeof(M3), new Config1(tcs));245 await this.WaitAsync(tcs.Task);246 Assert.False(failed);247 }, config, handleFailures: false);248 }249 private class M4 : StateMachine250 {251 [Start]252 [OnEntry(nameof(InitOnEntry))]253 private class Init : State254 {255 }256 private async SystemTasks.Task InitOnEntry(Event e)257 {258 var tcs = (e as Config2).Tcs;259 var m = await this.Context.CreateActorAndExecuteAsync(typeof(N4), e);260 var handled = await this.Context.SendEventAndExecuteAsync(m, new E3());261 this.Assert(handled);262 tcs.TrySetResult(true);263 }264 protected override OnExceptionOutcome OnException(Exception ex, string methodName, Event e)265 {266 this.Assert(false);267 return OnExceptionOutcome.ThrowException;268 }269 }270 private class N4 : StateMachine271 {272 private bool HandleException = false;273 [Start]274 [OnEntry(nameof(InitOnEntry))]275 [OnEventDoAction(typeof(E3), nameof(HandleE))]276 private class Init : State277 {278 }279 private void InitOnEntry(Event e)280 {281 this.HandleException = (e as Config2).HandleException;282 }283#pragma warning disable CA1822 // Mark members as static284 private void HandleE() => throw new Exception();285#pragma warning restore CA1822 // Mark members as static286 protected override OnExceptionOutcome OnException(Exception ex, string methodName, Event e)287 {288 if (this.HandleException)289 {290 return OnExceptionOutcome.HandledException;291 }292 return OnExceptionOutcome.ThrowException;293 }294 }295 [Fact(Timeout = 5000)]296 public async SystemTasks.Task TestHandledExceptionOnSendExec()297 {298 await this.RunAsync(async r =>299 {300 var failed = false;301 var tcs = TaskCompletionSource.Create<bool>();302 r.OnFailure += (ex) =>303 {304 failed = true;305 tcs.SetResult(false);306 };307 r.CreateActor(typeof(M4), new Config2(true, tcs));308 await this.WaitAsync(tcs.Task);309 Assert.False(failed);310 },311 handleFailures: false);312 }313 [Fact(Timeout = 5000)]314 public async SystemTasks.Task TestUnHandledExceptionOnSendExec()315 {316 await this.RunAsync(async r =>317 {318 var failed = false;319 var tcs = TaskCompletionSource.Create<bool>();320 var message = string.Empty;321 r.OnFailure += (ex) =>322 {323 if (!failed)324 {325 message = (ex is ActionExceptionFilterException) ? ex.InnerException.Message : ex.Message;326 failed = true;327 tcs.TrySetResult(false);328 }329 };330 r.CreateActor(typeof(M4), new Config2(false, tcs));331 await this.WaitAsync(tcs.Task);332 Assert.True(failed);333 Assert.StartsWith("Exception of type 'System.Exception' was thrown", message);334 },335 handleFailures: false);336 }337 private class M5 : StateMachine338 {339 [Start]340 [OnEntry(nameof(InitOnEntry))]341 private class Init : State342 {343 }344 private async SystemTasks.Task InitOnEntry(Event e)345 {346 var tcs = (e as Config1).Tcs;347 var m = await this.Context.CreateActorAndExecuteAsync(typeof(N5));348 var handled = await this.Context.SendEventAndExecuteAsync(m, new E3());349 this.Assert(handled);350 tcs.TrySetResult(true);351 }352 }353 private class N5 : StateMachine354 {355 [Start]356 private class Init : State357 {358 }359 }360 [Fact(Timeout = 5000)]361 public async SystemTasks.Task TestUnhandledEventOnSendExec()362 {363 await this.RunAsync(async r =>364 {365 var failed = false;366 var tcs = TaskCompletionSource.Create<bool>();367 var message = string.Empty;368 r.OnFailure += (ex) =>369 {370 if (!failed)371 {372 message = (ex is ActionExceptionFilterException) ? ex.InnerException.Message : ex.Message;373 failed = true;374 tcs.TrySetResult(false);375 }376 };377 r.CreateActor(typeof(M5), new Config1(tcs));378 await this.WaitAsync(tcs.Task);379 Assert.True(failed);380 var className = this.GetType().FullName;381 var expected = string.Format("{0}+N5(1) received event '{0}+E3' that cannot be handled.", className);382 Assert.Equal(expected, message);383 },384 handleFailures: false);385 }386 }387}...

Full Screen

Full Screen

Config1

Using AI Code Generation

copy

Full Screen

1Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config1();2Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config2();3Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config3();4Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config4();5Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config5();6Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config6();7Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config7();8Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config8();9Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config9();10Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config10();11Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config11();12Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config12();

Full Screen

Full Screen

Config1

Using AI Code Generation

copy

Full Screen

1var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();2test.Config1();3var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();4test.Config2();5var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();6test.Config3();7var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();8test.Config4();9var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();10test.Config5();11var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();12test.Config6();13var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();14test.Config7();15var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();16test.Config8();17var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();18test.Config9();19var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();20test.Config10();21var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();

Full Screen

Full Screen

Config1

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors;2using Microsoft.Coyote.Actors.Tests;3using Microsoft.Coyote.SystematicTesting;4using Microsoft.Coyote.SystematicTesting.Tests;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 public void Config1()13 {14 this.Test(r =>15 {16 r.RegisterMonitor(typeof(Monitor));17 r.CreateActor(typeof(M));18 r.CreateActor(typeof(A));19 });20 }21 }22}23using Microsoft.Coyote.Actors;24using Microsoft.Coyote.Actors.Tests;25using Microsoft.Coyote.SystematicTesting;26using Microsoft.Coyote.SystematicTesting.Tests;27using System;28using System.Collections.Generic;29using System.Linq;30using System.Text;31using System.Threading.Tasks;32{33 {34 public void Config2()35 {36 this.Test(r =>37 {38 r.RegisterMonitor(typeof(Monitor));39 r.CreateActor(typeof(M));40 r.CreateActor(typeof(A));41 },42 configuration: GetConfiguration().WithTestingIterations(100));43 }44 }45}46using Microsoft.Coyote.Actors;47using Microsoft.Coyote.Actors.Tests;48using Microsoft.Coyote.SystematicTesting;49using Microsoft.Coyote.SystematicTesting.Tests;50using System;51using System.Collections.Generic;52using System.Linq;53using System.Text;54using System.Threading.Tasks;55{56 {57 public void Config3()58 {59 this.TestWithError(r =>60 {61 r.RegisterMonitor(typeof(Monitor));62 r.CreateActor(typeof(M));63 r.CreateActor(typeof(A));64 },65 configuration: GetConfiguration().WithTestingIterations(100),66 replay: true);67 }68 }69}

Full Screen

Full Screen

Config1

Using AI Code Generation

copy

Full Screen

1var c = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();2var r = c.Config1();3Assert.True(r);4var c = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();5var r = c.Config2();6Assert.True(r);7var c = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();8var r = c.Config3();9Assert.True(r);10var c = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();11var r = c.Config4();12Assert.True(r);

Full Screen

Full Screen

Config1

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Coyote;4using Microsoft.Coyote.Actors;5using Microsoft.Coyote.Actors.Tests;6using Microsoft.Coyote.TestingServices;7using Microsoft.Coyote.TestingServices.Coverage;8using Microsoft.Coyote.TestingServices.Runtime;9using Microsoft.Coyote.TestingServices.SchedulingStrategies;10using Microsoft.Coyote.TestingServices.Tracing.Schedule;11using Microsoft.Coyote.Tests.Common;12using Microsoft.Coyote.Tests.Common.TestingServices;13using Microsoft.Coyote.Tests.Common.Utilities;14using Microsoft.Coyote.Tests.Common.Utilities.Storage;15using Microsoft.Coyote.Tests.Common.Utilities.Storage.Logging;16using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders;17using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.InMemory;18using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk;19using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging;20using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters;21using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Json;22using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Text;23using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Xml;24using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Yaml;25using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Zipped;26using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Zipped.Json;27using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Zipped.Text;28using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Zipped.Xml;29using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Logging.Formatters.Zipped.Yaml;30using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Storage;31using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Storage.Formatters;32using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Storage.Formatters.Json;33using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Storage.Formatters.Text;34using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Storage.Formatters.Xml;35using Microsoft.Coyote.Tests.Common.Utilities.Storage.StorageProviders.OnDisk.Storage.Formatters.Yaml;

Full Screen

Full Screen

Config1

Using AI Code Generation

copy

Full Screen

1using Microsoft.Coyote.Actors.Tests;2using Microsoft.Coyote.Actors;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8using Microsoft.Coyote.SystematicTesting;9using Microsoft.Coyote;10using System.Threading;11using System.Diagnostics;12{13 {14 static void Main(string[] args)15 {16 var config = Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config1();17 config.MaxSchedulingSteps = 1000;18 config.TestingIterations = 100;19 config.Verbose = 0;20 config.LogWriter = new LogWriter();21 config.SchedulingPolicy = SchedulingPolicy.FairPCT;22 config.TestReporters.Add(new TestReporters());23 var test = new Microsoft.Coyote.Actors.Tests.SendAndExecuteTests();24 test.TestInitialize(config);25 test.Test1();26 }27 }28 {29 public void Write(string message)30 {31 Console.WriteLine(message);32 }33 }34 {35 public void OnTestFailure(string error)36 {37 Console.WriteLine("Test failed with error: " + error);38 }39 public void OnTestSkipped(string reason)40 {41 Console.WriteLine("Test skipped: " + reason);42 }43 public void OnTestSucceeded()44 {45 Console.WriteLine("Test succeeded");46 }47 }48}49using Microsoft.Coyote.Actors.Tests;50using Microsoft.Coyote.Actors;51using System;52using System.Collections.Generic;53using System.Linq;54using System.Text;55using System.Threading.Tasks;56using Microsoft.Coyote.SystematicTesting;57using Microsoft.Coyote;58using System.Threading;59using System.Diagnostics;60{61 {62 static void Main(string[] args)63 {64 var config = Microsoft.Coyote.Actors.Tests.SendAndExecuteTests.Config2();65 config.MaxSchedulingSteps = 1000;66 config.TestingIterations = 100;67 config.Verbose = 0;68 config.LogWriter = new LogWriter();

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