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

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

Run JustMockLite automation tests on LambdaTest cloud grid

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

ConstructorFixture.cs

Source: ConstructorFixture.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#region JustMock Test Attributes
21#if NUNIT
22using NUnit.Framework;
23using TestCategory = NUnit.Framework.CategoryAttribute;
24using TestClass = NUnit.Framework.TestFixtureAttribute;
25using TestMethod = NUnit.Framework.TestAttribute;
26using TestInitialize = NUnit.Framework.SetUpAttribute;
27using TestCleanup = NUnit.Framework.TearDownAttribute;
28using AssertionException = NUnit.Framework.AssertionException;
29#elif XUNIT
30using Xunit;
31using Telerik.JustMock.XUnit.Test.Attributes;
32using TestCategory = Telerik.JustMock.XUnit.Test.Attributes.XUnitCategoryAttribute;
33using TestClass = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestClassAttribute;
34using TestMethod = Xunit.FactAttribute;
35using TestInitialize = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestInitializeAttribute;
36using TestCleanup = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestCleanupAttribute;
37using AssertionException = Telerik.JustMock.XUnit.AssertFailedException;
38#elif VSTEST_PORTABLE
39using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
40using AssertionException = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException;
41#else
42using Microsoft.VisualStudio.TestTools.UnitTesting;
43using AssertionException = Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException;
44#endif
45#endregion
46
47namespace Telerik.JustMock.Tests
48{
49	[TestClass]
50	public class ConstructorFixture
51	{
52		[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
53		public void ShouldCallBaseCtorWhenNotMocked()
54		{
55			Assert.Throws<ArgumentException>(() =>
56			{
57				Mock.Create<Foo>(Constructor.NotMocked);
58			});
59		}
60
61#if !(COREFX && LITE_EDITION)
62		[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
63#if SILVERLIGHT
64		[Ignore, Description("SL instance constructor mocking not implemented")]
65#endif
66		public void ShouldSkipBaseConstructorWhenMocked()
67		{
68			Assert.NotNull(Mock.Create<Foo>());
69		}
70
71		[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
72#if SILVERLIGHT
73		[Ignore, Description("SL instance constructor mocking not implemented")]
74#endif
75		public void ShouldSkipBaseConstructorOfAbstractClassWhenMocked()
76		{
77			Assert.NotNull(Mock.Create<AbstractFoo>());
78		}
79#endif
80
81#if !LITE_EDITION
82		[TestMethod, TestCategory("Elevated"), TestCategory("Constructor")]
83		public void ShouldCreateMockForFrameWorkClassWithInternalCtor()
84		{
85			var downloadDateCompleted = Mock.Create<System.IO.IsolatedStorage.IsolatedStorageFile>();
86			Assert.NotNull(downloadDateCompleted != null);
87		}
88
89		[TestMethod, TestCategory("Elevated"), TestCategory("Constructor")]
90		public void ShouldFutureMockConstructorWithArg()
91		{
92			long? arg = null;
93			Mock.Arrange(() => new CtorLongArg(Arg.AnyLong)).DoInstead<long>(x => arg = x);
94
95			new CtorLongArg(100);
96			Assert.True(arg.Value == 100);
97		}
98
99#endif
100
101		public class Foo
102		{
103			public Foo()
104			{
105				throw new ArgumentException("Failed");
106			}
107		}
108
109		public abstract class AbstractFoo
110		{
111			public AbstractFoo()
112			{
113				throw new ArgumentException("Failed");
114			}
115
116			public abstract int Id { get; set; }
117		}
118
119		[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
120		public void ShouldCallConstructorRequiringPrimitiveArgumentConversions()
121		{
122			Mock.Create<CtorLongArg>(Behavior.CallOriginal, 0);
123		}
124
125		public class CtorLongArg
126		{
127			public CtorLongArg(long l) { }
128		}
129
130		public class CallsCtor
131		{
132			public bool ok;
133
134			public CallsCtor()
135			{
136				ok = true;
137			}
138		}
139
140		[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
141		public void ShouldCallDefaultConstructorWhenExplicitlyGivenNoArguments()
142		{
143			var mock = Mock.Create<CallsCtor>(new object[0]);
144			Assert.True(mock.ok);
145		}
146	}
147}
148
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)