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

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

Run JustMockLite automation tests on LambdaTest cloud grid

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

EventsFixture.cs

Source: EventsFixture.cs Github

copy
1/*
2 JustMock Lite
3 Copyright © 2010-2015 Telerik EAD
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.Collections.Generic;
19using Telerik.JustMock.Tests.EventFixureDependencies;
20using NUnit.Framework;
21
22
23namespace Telerik.JustMock.Tests
24{
25	[TestFixture]
26	public class EventsFixtureNUnit
27	{
28		private ProjectNavigatorViewModel viewModel;
29		private ISolutionService solutionService;
30
31		[SetUp]
32		public void Initialize()
33		{
34			this.solutionService = Mock.Create<ISolutionService>();
35			this.viewModel = new ProjectNavigatorViewModel(this.solutionService);
36		}
37
38		[Test, Category("Lite"), Category("Events")]
39		[TestCaseSource("DummyTestCaseSource")]
40		public void ShouldRaiseEventsOnDataDrivenTests(object _)
41		{
42			Mock.Raise(() => this.solutionService.ProjectAdded += null, new ProjectEventArgs(null));
43		}
44
45		private static IEnumerable<TestCaseData> DummyTestCaseSource = new[] { new TestCaseData(null), new TestCaseData(null) };
46	}
47}
48
Full Screen

ArgumentMatchingTests.cs

Source: ArgumentMatchingTests.cs Github

copy
1/**
2 * Copyright 2015 Marc Rufer, d-fens GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16using Microsoft.VisualStudio.TestTools.UnitTesting;
17using System;
18using Telerik.JustMock;
19using Telerik.JustMock.Core;
20
21namespace biz.dfch.CS.JustMock.Examples.Tests
22{
23    [TestClass]
24    public class ArgumentMatchingTests
25    {
26        private Boolean _called;
27
28        [TestInitialize]
29        public void TestInitialize()
30        {
31            _called = false;
32        }
33
34        /**
35         * For more details consult the Wiki
36         * https://github.com/dfensgmbh/biz.dfch.CS.JustMock.Examples/wiki/ArgumentMatchingTests#matching-specific-argument
37         **/
38        [TestMethod]
39        public void MockedConsoleWriteLineGettingCalledWithMatchingArgument()
40        {
41            // Arrange
42            Mock.SetupStatic(typeof(Console), StaticConstructor.Mocked);
43            Mock.Arrange(() => Console.WriteLine("Test"))
44                .DoInstead(() => { _called = true; })
45                .OccursOnce();
46
47            // Act
48            Console.WriteLine("Test");
49
50            // Assert
51            Assert.IsTrue(_called);
52
53            Mock.Assert(() => Console.WriteLine("Test"));
54        }
55
56        [TestMethod]
57        public void MockedConsoleWriteLineNotGettingCalledWithSpecificArgument()
58        {
59            // Arrange
60            Mock.SetupStatic(typeof(Console), StaticConstructor.Mocked);
61            Mock.Arrange(() => Console.WriteLine("Test"))
62                .DoInstead(() => { _called = true; })
63                .OccursNever();
64
65            // Act
66            Console.WriteLine("Something");
67
68            // Assert
69            Assert.IsFalse(_called);
70
71            Mock.Assert(() => Console.WriteLine("Test"));
72        }
73
74        /**
75         * For more details consult the Wiki
76         * https://github.com/dfensgmbh/biz.dfch.CS.JustMock.Examples/wiki/ArgumentMatchingTests#matching-any-argument-of-type
77         **/
78        [TestMethod]
79        public void MockedCDummyGettingCalledWithArgumentOfSpecificType()
80        {
81            // Arrange
82            var mock = Mock.Create<MockSamplesHelper>();
83            Mock.Arrange(() => mock.Dummy(Arg.AnyString))
84                .OccursOnce();
85
86            // Act
87            mock.Dummy("Something");
88
89            // Assert
90            Mock.Assert(mock);
91        }
92
93        [TestMethod]
94        public void MockedDummyGettingCalledWithNullAsArgument()
95        {
96            // Arrange
97            var mock = Mock.Create<MockSamplesHelper>();
98            Mock.Arrange(() => mock.Dummy(Arg.AnyString))
99                .OccursOnce();
100
101            // Act
102            mock.Dummy(null);
103
104            // Assert
105            Mock.Assert(mock);
106        }
107
108        [TestMethod]
109        public void MockedDummyGettingCalledWithNullAsArgument2()
110        {
111            // Arrange
112            var mock = Mock.Create<MockSamplesHelper>();
113            Mock.Arrange(() => mock.Dummy(Arg.IsAny<String>()))
114                .OccursOnce();
115
116            // Act
117            mock.Dummy(null);
118
119            // Assert
120            Mock.Assert(mock);
121        }
122
123        [TestMethod]
124        public void MockedDummySetsCalled()
125        {
126            //Arrange
127            MockSamplesHelper mock = new MockSamplesHelper();
128            Mock.Arrange(() => mock.Dummy(""))
129                .DoInstead(() => _called = true)
130                .OccursOnce();
131            
132            //Act
133            mock.Dummy("");
134           
135            //Assert
136            Assert.IsTrue(_called);
137
138            Mock.Assert(mock);
139        }
140
141        [TestMethod]
142        public void MockedAddReturns4()
143        {
144            //Arrange
145            int result = 0;
146            MockSamplesHelper mock = new MockSamplesHelper();
147            Mock.Arrange(() => mock.Add(Arg.IsAny<int>(), Arg.IsAny<int>()))
148                .DoInstead(() => result = 4)
149                .OccursOnce();
150            
151            //Act
152            mock.Add(3, 3);
153            
154            //Assert
155            Assert.AreEqual(result, 4);
156
157            Mock.Assert(mock);
158        }
159
160        [TestMethod]
161        [ExpectedException(typeof (ArgumentException))]
162        public void MockedAddThrowsArgumentException()
163        {
164            //Arrange
165            MockSamplesHelper mock = new MockSamplesHelper();
166            Mock.Arrange(() => mock.Add(Arg.IsAny<int>(), Arg.IsAny<int>()))
167                .Throws(new ArgumentException())
168                .OccursOnce();
169            
170            //Act
171            mock.Add(2, 2);
172
173            // Assert
174            Mock.Assert(mock);
175        }
176
177        [TestMethod]
178        public void MockedAddArgumentsAreInRangeFrom20To30()
179        {
180            //Arrange
181            MockSamplesHelper mock = new MockSamplesHelper();
182            Mock.Arrange(
183                () => mock.Add(Arg.IsInRange(20, 30, RangeKind.Inclusive), Arg.IsInRange(20, 30, RangeKind.Inclusive)))
184                .Returns(2)
185                .OccursOnce();
186           
187            //Act
188            var result = mock.Add(29, 27);
189            
190            //Assert
191            Assert.AreEqual(2,result);
192            Mock.Assert(mock);
193        }
194
195        [TestMethod]
196        public void MockedDummyGetsCalledFromAdd()
197        {
198            //Arrange
199            MockSamplesHelper mock = new MockSamplesHelper();
200            Mock.Arrange(() => mock.Dummy(Arg.AnyString))
201                .OccursOnce();
202            
203            //Act
204            mock.Add(4, 3);
205            
206            //Assert
207            Mock.Assert(mock);
208        }
209
210        [TestMethod]
211        public void MockedAddReturns7IfCalledWithArguments1And1()
212        {
213            //Arrange
214            MockSamplesHelper mock = new MockSamplesHelper();
215            Mock.Arrange(() => mock.Add(1, 1))
216                .Returns(7)
217                .OccursOnce();
218            
219            //Act
220            var result = mock.Add(1, 1);
221            
222            //Assert
223            Assert.AreEqual(7,result);
224
225            Mock.Assert(mock);
226        }
227
228        [TestMethod]
229        [ExpectedException(typeof (StrictMockException))]
230        public void MockedSomePropertyThrowsWhenSetToSomewhatNotEqualTheMock()
231        {
232            //Arrange
233            var mock = Mock.Create<MockSamplesHelper>(Behavior.Strict);
234            Mock.ArrangeSet(() => mock.SomeProperty = false);
235            
236            //Act
237            mock.SomeProperty = true;
238            
239            //Assert
240            Mock.Assert(mock);
241        }
242    }
243}
244
Full Screen

BasicStaticMockingTests.cs

Source: BasicStaticMockingTests.cs Github

copy
1/**
2 * Copyright 2015 Marc Rufer, d-fens GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16using System;
17using Microsoft.VisualStudio.TestTools.UnitTesting;
18using Telerik.JustMock;
19
20namespace biz.dfch.CS.JustMock.Examples.Tests
21{
22    [TestClass]
23    public class BasicStaticMockingTests
24    {
25        /**
26         * For more details consult the Wiki
27         * https://github.com/dfensgmbh/biz.dfch.CS.JustMock.Examples/wiki/BasicStaticMockingTests#mocking-datetimeoffsetutcnow
28         **/
29        [TestMethod]
30        public void MockedDateTimeOffsetReturnsExpectedDateTimeOffset()
31        {
32            // Arrange
33            Mock.SetupStatic(typeof(DateTimeOffset), Behavior.CallOriginal, StaticConstructor.Mocked);
34            Mock.Arrange(() => DateTimeOffset.UtcNow)
35                .Returns(new DateTimeOffset(2015, 1, 1, 3, 10, 7, new TimeSpan()))
36                .MustBeCalled();
37
38            // Act & Assert
39            Assert.AreEqual(new DateTimeOffset(2015, 1, 1, 3, 10, 7, new TimeSpan()), DateTimeOffset.UtcNow);
40
41            // Assert Occurence
42            Mock.Assert(() => DateTimeOffset.UtcNow);
43        }
44
45        [TestMethod]
46        public void MockedConsoleShouldReturn9()
47        {
48            //Arrange
49            Mock.SetupStatic(typeof(Dummy),Behavior.Strict);
50
51            Mock.Arrange(() => Dummy.Get7())
52                .Returns(9)
53                .OccursOnce();
54
55            //Act
56            int mockedResult = Dummy.Get7();
57
58            //Assert
59            Assert.AreEqual(9,mockedResult);
60            Mock.Assert(typeof(Dummy));
61        }
62
63        [TestMethod]
64        public void MockedConsoleWillSetCalledOnTrue()
65        {
66            //Arrange
67            Mock.SetupStatic(typeof(Console),Behavior.Strict);
68
69            bool _called = false;
70
71            Mock.Arrange(() => Console.Clear())
72                .DoInstead(() =>{ _called = true;})
73                .OccursOnce();
74
75            //Act
76            Console.Clear();
77
78            //Assert
79            Assert.AreEqual(true,_called);
80            Mock.Assert(typeof (Console));
81        }
82    }
83}
84
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)