How to use TestAsyncController class of Telerik.JustMock.Tests package

Best JustMockLite code snippet using Telerik.JustMock.Tests.TestAsyncController

Run JustMockLite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

AsyncFixture.cs

Source: AsyncFixture.cs Github

copy
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5#region JustMock Test Attributes
6#if NUNIT
7using NUnit.Framework;
8using TestCategory = NUnit.Framework.CategoryAttribute;
9using TestClass = NUnit.Framework.TestFixtureAttribute;
10using TestMethod = NUnit.Framework.TestAttribute;
11using TestInitialize = NUnit.Framework.SetUpAttribute;
12using TestCleanup = NUnit.Framework.TearDownAttribute;
13using AssertionException = NUnit.Framework.AssertionException;
14#elif XUNIT
15using Xunit;
16using Telerik.JustMock.XUnit.Test.Attributes;
17using TestCategory = Telerik.JustMock.XUnit.Test.Attributes.XUnitCategoryAttribute;
18using TestClass = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestClassAttribute;
19using TestMethod = Xunit.FactAttribute;
20using TestInitialize = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestInitializeAttribute;
21using TestCleanup = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestCleanupAttribute;
22using AssertionException = Telerik.JustMock.XUnit.AssertFailedException;
23#elif VSTEST_PORTABLE
24using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
25using AssertionException = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException;
26#else
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28using AssertionException = Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException;
29#endif
30#endregion
31
32namespace Telerik.JustMock.Tests
33{
34	[TestClass]
35	public class AsyncFixture
36	{
37		[TestMethod, TestCategory("Async"), TestCategory("Lite")]
38		public async Task ShouldRetainMockingContextInContinuation()
39		{
40			var model = Mock.Create<IAsyncModel>();
41			Mock.Arrange(() => model.GetData()).Returns(5);
42			var controller = new TestAsyncController();
43			await controller.DoStuff(model);
44			//no exception
45		}
46
47		[TestMethod, TestCategory("Async"), TestCategory("Lite")]
48		public void ShouldCreateRecursiveMockInConstructorOnAnotherThread()
49		{
50			Mock.Arrange(() => Arg.IsAny<ThreadCtor>().Assign()).CallOriginal();
51			var mock = Mock.Create<ThreadCtor>(Constructor.NotMocked, Behavior.RecursiveLoose);
52			Assert.NotNull(mock.TheItem);
53		}
54
55		public abstract class ThreadCtor
56		{
57			protected abstract IDisposable Item { get; }
58
59			public ThreadCtor()
60			{
61				var thread = new Thread(this.Assign);
62				thread.Start();
63				if (!thread.Join(TimeSpan.FromMilliseconds(1500)))
64					throw new TimeoutException();
65			}
66
67			public virtual void Assign()
68			{
69				TheItem = Item;
70			}
71
72			public IDisposable TheItem;
73		}
74	}
75
76	public interface IAsyncModel
77	{
78		int GetData();
79	}
80
81	public class TestAsyncController
82	{
83		public async Task DoStuff(IAsyncModel model)
84		{
85			await Task.Factory.StartNew(() => Thread.Sleep(5));
86			// continuation begins here
87			var result = model.GetData();
88			if (result != 5)
89			{
90				throw new Exception();
91			}
92		}
93	}
94}
95
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in TestAsyncController

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)