public void JustMock_Has_Reflection_Helper_Methods_To_Set_Fields_Of_Static_Classes() { var configurationHolderAccessor = PrivateAccessor.ForType(typeof(StaticClassWithGetterOnly)); configurationHolderAccessor.SetField("_value", "Geänderter Wert"); StaticClassWithGetterOnly.Value.Should().Be("Geänderter Wert"); }
public void PrivateAccessor_ShouldCallPrivateStaticMethod() { // ACT // Wrapping the instance holding the private method by type. var inst = PrivateAccessor.ForType(typeof(ClassWithNonPublicMembers)); // Calling the non-public static method by giving its exact name. var actual = inst.CallMethod("MeStaticPrivate"); // ASSERT Assert.AreEqual(2000, actual); }
public void ShouldCallArrangedStaticPrivateMethod() { // ARRANGE // Setup your class under test for static mocking. // You can also use original instance object and perform partial mocking. Mock.SetupStatic(typeof(ClassWithNonPublicMembers)); // Arranging: When the private MeStaticPrivate is called from an instance of type ClassWithNonPublicMembers, it should return 5. Mock.NonPublic.Arrange <int>(typeof(ClassWithNonPublicMembers), "MeStaticPrivate").Returns(5); // ACT // Wrapping the mocked instance by type. var inst = PrivateAccessor.ForType(typeof(ClassWithNonPublicMembers)); // Calling the non-public static method by giving its exact name. var actual = inst.CallMethod("MeStaticPrivate"); // ASSERT - No matter the mock is wrapped, it should keep its arrangements. Assert.AreEqual(5, actual); }
public PrivateAccessor MakeStaticPrivateAccessor(Type type) { return(PrivateAccessor.ForType(type)); }