-
Notifications
You must be signed in to change notification settings - Fork 5
1. Private method test
Md. Kamruzzaman edited this page Apr 2, 2023
·
2 revisions
We can use PrivateAccessor class Example. Where GetNumberOfPeople is private method
//Arrange
IManual manual = new Mock<IManual>().Object;
Order order = new Order { NumberOfPeople = 100, NumberOfPeopleNotInterest = 50 };
var target = new PrivateAccessor(new JuiceBuilder(manual)); //<---
//Act
var original = target.CallMethod("GetNumberOfPeople", order); //<---
// var private_property = target.GetProperty("_property_name"); //<-- for private property
// Assert.Equal("private property value", private_property.ToString());
// var responsesData = (ValueTuple<string, string, string>)target.CallMethod("MethodThatReturnTuple"); //<-- If function return value Tuple
// Assert.Equal("value for first item", responsesData.Item1);
// Assert.Equal("value for second item", responsesData.Item2);
//Assert
Assert.AreEqual(original, 50);