简体   繁体   中英

Derived public method in class

I'm trying to test with Microsoft Fakes code in a application which sort of the following construction in a library:

public static class C
{
   public A GetConfigurationFactory(Uri uri);
}

public class A : B
{
   public A(Uri uri)
   {
   }
}

public class B
{
    public void Authenticate()
    {
    }
}

I've created the following test for this in Visual Studio:

//Arrange
ShimA.ConstructorUri = (@this, value) => 
{ 
   var shim = new ShimA(@this); 
};        

ShimC.GetConfigurationFactory = (uri) => 
{ 
   var shim = new A(uri);
   return shim;
};

var uri1 = new Uri("http://test-url");

//Act
A.Authenticate()

I get a null pointer when I call the Authenticate method from instance A .

Does anyone how I can solve this? I already looked and there is no overloaded constructor.

Solved this problem with the following code:

ShimB.AllInstances.Authenticate = (someValue) => { return; }

This code ensures that when I call the Authenticate method from any class it will always return the specified value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM