ClusterMonitoring is created manually.
ClusterMonitoring monitoring = new ClusterMonitoring();
This means that its substitution is impossible. you need to introduce ClusterMonitoring as a controller dependency in order to be able to replace it during testing.
The first ClusterMonitoring abstraction behind the interface
public interface IClusterMonitoring { string GetNameNodeStatus(string hostName, Credential credential); }
and inherit this interface
public class ClusterMonitoring : IClusterMonitoring { public virtual string GetNameNodeStatus(string hostName, Credential credential) { ... } }
Update the controller to accept the dependency through the constructor
public class HomeController : Controller { private readonly IClusterMonitoring monitoring; public HomeController(IClusterMonitoring monitoring) { this.monitoring = monitoring; }
Now update the test to add dependency to the controller under test
[TestFixture] public class UnitTest1 { [Test] public void ValidateNameNodeStatus() {
Nkosi source share