Hi,
I have a Class “SystemManager” having constructor with three argument ServerName, UserName and Password. This SystemManager is derived from another Class “ConfigurationManager”. This ConfigurationManager created an instance of the “ConfigurationManagerConnection” class which will connect to a Server with Username/Password provided.
The class structure is as below.
Public Class SystemManager : ConfigurationManager
{
Public SystemManager(string serverName, string username, string password)
:base(serverName, username, password)
{
}
}
Public class ConfigurationManager
{
Private ConfigurationManagerConnection configurationManagerConnection;
Public ConfigurationManager(string serverName, string username, string password)
{
configurationManagerConnection = new ConfigurationManagerConnection(serverName, userName, siteCode);
}
}
Internal class ConfigurationManagerConnection
{
Public ConfigurationManagerConnection (string serverName, string username, string password)
{
//Code to connect to sccm server
}
}
Here in this case I want to Mock the ConfigurationManagerConnection class to avoid connection to the Sccm server.
var configurationManager = Isolate.Fake.Instance<ConfigurationManager>(Members.ReturnRecursiveFakes, ConstructorWillBe.Ignored);
Isolate.Swap.NextInstance<ConfigurationManager>().With(configurationManager);
SystemManager target = new SystemManager(TestVariables.ServerName, TestVariables.UserName, TestVariables.Password);
I tried using the above lines of code but it still trying to connect to the Sccm server.
Anything which I missed?