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

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

Run JustMockLite automation tests on LambdaTest cloud grid

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

OutRefFixure.cs

Source: OutRefFixure.cs Github

copy
1/*
2 JustMock Lite
3 Copyright © 2010-2015 Progress Software Corporation
4
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8
9   http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16*/
17
18using System;
19
20
21#region JustMock Test Attributes
22#if NUNIT
23using NUnit.Framework;
24using TestCategory = NUnit.Framework.CategoryAttribute;
25using TestClass = NUnit.Framework.TestFixtureAttribute;
26using TestMethod = NUnit.Framework.TestAttribute;
27using TestInitialize = NUnit.Framework.SetUpAttribute;
28using TestCleanup = NUnit.Framework.TearDownAttribute;
29using AssertionException = NUnit.Framework.AssertionException;
30#elif XUNIT
31using Xunit;
32using Telerik.JustMock.XUnit.Test.Attributes;
33using TestCategory = Telerik.JustMock.XUnit.Test.Attributes.XUnitCategoryAttribute;
34using TestClass = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestClassAttribute;
35using TestMethod = Xunit.FactAttribute;
36using TestInitialize = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestInitializeAttribute;
37using TestCleanup = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestCleanupAttribute;
38using AssertionException = Telerik.JustMock.XUnit.AssertFailedException;
39#elif VSTEST_PORTABLE
40using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
41using AssertionException = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException;
42#else
43using Microsoft.VisualStudio.TestTools.UnitTesting;
44using AssertionException = Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException;
45#endif
46#endregion
47
48
49namespace Telerik.JustMock.Tests
50{
51	[TestClass]
52	public class OutRefFixure
53	{
54		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
55		public void ShouldExpectOutArgumets()
56		{
57			string expected = "ack";
58
59			var iFoo = Mock.Create<IFoo>();
60
61			Mock.Arrange(() => iFoo.Execute("ping", out expected)).Returns(true);
62
63			string original;
64
65			Assert.True(iFoo.Execute("ping", out original));
66			Assert.Equal(original, expected);
67		}
68
69		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
70		public void ShouldAssertRefArguments()
71		{
72			string strToReturn = "abc";
73
74			var iFoo = Mock.Create<IFoo>();
75
76			Mock.Arrange(() => iFoo.Execute(ref strToReturn)).DoNothing();
77
78			string original = string.Empty;
79
80			iFoo.Execute(ref original);
81
82			Assert.Equal(strToReturn, original);
83		}
84
85		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
86		public void ShouldAssertGuidAsOutArgument()
87		{
88			var iFoo = Mock.Create<IFoo>();
89
90			Guid expected = Guid.NewGuid();
91
92			Mock.Arrange(() => iFoo.GuidMethod(out expected)).Returns(true);
93
94			Guid original;
95
96			Assert.True(iFoo.GuidMethod(out original));
97			Assert.Equal(original, expected);
98		}
99
100		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
101		public void ShouldAssertIntRefArgument()
102		{
103			var foo = Mock.Create<IFoo>();
104
105			var expected = 10;
106
107			Mock.Arrange(() => foo.IntMethod(ref expected)).Returns(true);
108
109			var original = 0;
110
111			Assert.True(foo.IntMethod(ref original));
112			Assert.Equal(original, 10);
113		}
114
115		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
116		public void ShouldAssertWhenExpectedOutIsNull()
117		{
118			var foo = Mock.Create<Foo>(Behavior.CallOriginal);
119
120			Token expected;
121
122			Mock.Arrange(() => foo.Execute(Arg.AnyString, out expected)).Returns(true);
123
124			Assert.True(foo.Execute("xmas", out expected));
125		}
126
127		public class Token
128		{
129
130		}
131
132		public class Foo
133		{
134			public virtual bool Execute(string arg, out Token token)
135			{
136				token = new Token();
137				return false;
138			}
139		}
140
141		public interface IFoo
142		{
143			bool Execute(string arg1, out string arg2);
144			void Execute(ref string arg1);
145			bool GuidMethod(out Guid id);
146			bool IntMethod(ref int argument);
147		}
148
149		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
150		public void ShouldArrangeByRefValueMatcher()
151		{
152			var mock = Mock.Create<IFoo>();
153			Mock.Arrange(() => mock.IntMethod(ref Arg.Ref(100).Value)).Returns(true);
154
155			int value = 100;
156			var actual = mock.IntMethod(ref value);
157			Assert.Equal(true, actual);
158
159			value = 0;
160			actual = mock.IntMethod(ref value);
161			Assert.Equal(false, actual);
162		}
163
164		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
165		public void ShouldArrangeByRefPredicatedMatcher()
166		{
167			var mock = Mock.Create<IFoo>();
168			Mock.Arrange(() => mock.IntMethod(ref Arg.Ref(Arg.IsInRange(0, 1000, RangeKind.Inclusive)).Value)).Returns(true);
169
170			int value = 100;
171			var actual = mock.IntMethod(ref value);
172			Assert.Equal(true, actual);
173
174			value = -100;
175			actual = mock.IntMethod(ref value);
176			Assert.Equal(false, actual);
177
178			value = 10000;
179			actual = mock.IntMethod(ref value);
180			Assert.Equal(false, actual);
181		}
182
183		public interface IMixRefs
184		{
185			int Do(ref int a, ref int b);
186		}
187
188		[TestMethod, TestCategory("Lite"), TestCategory("OutRef")]
189		public void ShouldMatcherRefsCoexistWithReturnRefs()
190		{
191			var mock = Mock.Create<IMixRefs>();
192
193			int arrange_a = 100;
194			Mock.Arrange(() => mock.Do(ref arrange_a, ref Arg.Ref(500).Value)).Returns(10);
195
196			int a = 0;
197			int b = 500;
198			mock.Do(ref a, ref b);
199
200			Assert.Equal(100, a);
201			Assert.Equal(500, b);
202
203			int a2 = 0;
204			int c = 100;
205			mock.Do(ref a2, ref c);
206			Assert.Equal(0, a2);
207			Assert.Equal(100, c);
208		}
209	}
210}
211
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

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)