How to use MeStaticPrivate method of JustMock.NonElevatedExamples.AdvancedUsage.PrivateAccessorNamespace.ClassWithNonPublicMembers class

Best JustMockLite code snippet using JustMock.NonElevatedExamples.AdvancedUsage.PrivateAccessorNamespace.ClassWithNonPublicMembers.MeStaticPrivate

Run JustMockLite automation tests on LambdaTest cloud grid

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

PrivateAccessor.cs

Source: PrivateAccessor.cs Github

copy
1/*
2 JustMock Lite
3 Copyright © 2010-2014 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;
19using Microsoft.VisualStudio.TestTools.UnitTesting;
20using Telerik.JustMock;
21
22namespace JustMock.NonElevatedExamples.AdvancedUsage.PrivateAccessorNamespace
23{
24    /// <summary>
25    /// The Telerik JustMock PrivateAccessor allows you to call non-public members of the tested code right in your unit tests. 
26    /// See http://www.telerik.com/help/justmock/advanced-usage-private-accessor.html for full documentation of the feature.
27    /// </summary>
28    [TestClass]
29    public class PrivateAccessor_Tests
30    {
31        [TestMethod]
32        public void PrivateAccessor_ShouldCallPrivateMethod()
33        {
34            // ACT
35            // Wrapping the instance holding the private method.
36            var inst = new PrivateAccessor(new ClassWithNonPublicMembers());
37            // Calling the non-public method by giving its exact name.
38            var actual = inst.CallMethod("MePrivate");
39
40            // ASSERT
41            Assert.AreEqual(1000, actual);
42        }
43
44        [TestMethod]
45        public void PrivateAccessor_ShouldCallPrivateStaticMethod()
46        {
47            // ACT
48            // Wrapping the instance holding the private method by type.
49            var inst = PrivateAccessor.ForType(typeof(ClassWithNonPublicMembers));
50            // Calling the non-public static method by giving its exact name.
51            var actual = inst.CallMethod("MeStaticPrivate");
52
53            // ASSERT
54            Assert.AreEqual(2000, actual);
55        }
56
57        [TestMethod]
58        public void PrivateAccessor_ShouldGetSetProperty()
59        {
60            // ACT
61            // Wrapping the instance holding the private property.
62            var inst = new PrivateAccessor(new ClassWithNonPublicMembers());
63            // Setting the value of the private property.
64            inst.SetProperty("Prop", 555);
65
66            // ASSERT - Asserting with getting the value of the private property.
67            Assert.AreEqual(555, inst.GetProperty("Prop"));
68        } 
69    }
70
71    #region SUT
72    public class ClassWithNonPublicMembers
73    {
74        private int Prop { get; set; }
75
76        private int MePrivate()
77        {
78            return 1000;
79        }
80
81        private static int MeStaticPrivate()
82        {
83            return 2000;
84        }
85    } 
86    #endregion
87}
88
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 method in ClassWithNonPublicMembers

Trigger MeStaticPrivate code on LambdaTest Cloud Grid

Execute automation tests with MeStaticPrivate on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

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)