Questions tagged [privateobject.invoke]
13 questions
14
votes
5 answers
Test private static method throws MissingMethodException
I have this class:
public class MyClass
{
private static int GetMonthsDateDiff(DateTime d1, DateTime d2)
{
// implementatio
}
}
Now I am implementing unit test for it.
Since the method is private, I have following code:
MyClass…

YAKOVM
- 9,805
- 31
- 116
- 217
4
votes
5 answers
How to unit test private method in .Net Core application which does not support "PrivateObject"
My application is a .NET Core application.
I have a public method as shown below which has two private methods.
public bool CallService(JObject requestJsonObj, out Status status)
{
bool provisioningSuccess = false;
var…

kudlatiger
- 3,028
- 8
- 48
- 98
2
votes
1 answer
Unit Test Private Method Using PrivateObject With Multiple Parameters in C#
I have a class ClassA with private method DoSomething like this
private bool DoSomething(string id, string name, string location
, DataSet ds, int max, ref int counter)
The parameters are of different types and the last parameter is a ref…

pixel
- 9,653
- 16
- 82
- 149
2
votes
3 answers
Is Moq incompatible with PrivateObject?
I'm trying to test a private method on a mocked object. Please, calm down, I know you're getting your pitchforks out.
I'm well aware everything about to say can be answered by yelling REFACTOR at me. I just need a straight answer. Someone look me in…

friggle
- 3,362
- 3
- 35
- 47
1
vote
1 answer
Private Object Invoke Array of complex type
I am trying to test a private the following private methods
public class Test
{
private bool PVTMethod1(Guid[] Parameter1)
{
return true;
}
private bool PVTMethod2(RandomClass[] Parameter2)
…

Lord Darth Vader
- 1,895
- 1
- 17
- 26
1
vote
0 answers
PrivateObject get argument modified inside a method
I'm developing a C# library with .NET Framework 4.7.1 and Visual Studio 2017.
I want to test this method:
private void AddProductionRule(
string bnfLine,
Dictionary productionRules)
{
if (productionRules == null)
…

VansFannel
- 45,055
- 107
- 359
- 626
1
vote
1 answer
How to mock PrivateObject in C#
I have this code:
[TestMethod]
public void TestMethod()
{
TextBox txtBox= new TextBox() { Text = "Test" };
PrivateObject privateObj= new PrivateObject(someObject);
var mockObj = new Mock();
…

Alex
- 63
- 1
- 10
0
votes
2 answers
Using PrivateObject.Invoke to call a static conversion function do not compile in C#
I have a test method where I call an private function that converts a kind of to another kind.
This static function have the following signature:
private static Destiny[] Array2Array (Origin[] OriginVector)
Since it's a private…

Fabricio Araujo
- 3,810
- 3
- 28
- 43
0
votes
1 answer
Private Object "Attempted to access a missing member" exception
I am trying to invoke a private method of an object using private method. This method takes three arguments. Both signature of method i am trying to invoke and the code invoking this method are shown below
Signature of private method:
Public Class…

Rahul Lodha
- 3,601
- 7
- 25
- 34
0
votes
1 answer
Using PrivateObject.Invoke to call a static conversion function is not working in Unit test
Method:
private static HipKvp[] GetRequestParameterArray(CaptchaRequestModel request){}
Unit Test:
HipKvp[] input = (HipKvp[])privObj.Invoke("GetRequestParameterArray", new CaptchaRequestModel[] { result });
Exception:
MissingMethodException…

user2163594
- 1
- 1
0
votes
1 answer
How can I use a PrivateObject for accesing or modifying the variable of a method in a class
I'm new to writing unit tests.
I have used PrivateObject to access and modify the private member of a class to use it while testing.
However, if I want to access a private variable of the method that I'm testing, how can I do that. I'll not be…

Sailoosha
- 193
- 1
- 3
- 14
-1
votes
1 answer
PrivateObject NullReferenceException on invocation of method with string[] as parameter
I am trying to write unit tests for a private method with a string[] as parameter. Invoking a private method works with the PrivateObject class, however it did not when I tried invoking it with string[].
The test returns…

oddRaven
- 672
- 1
- 7
- 20
-5
votes
2 answers
How to create type safety on a PrivateObject in C#
I have discovered a fantastic way to unit test private methods.
This is great except I don't like how the method name is typed in as a string. Is there a way to create a "safety net?" I want to type the method name so that the compiler can throw a…

Maderas
- 231
- 2
- 14