Skip to content

Instantly share code, notes, and snippets.

@CopperStarSystems
Last active January 15, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CopperStarSystems/06a8a6b1a59ebebd82b01612300a5d37 to your computer and use it in GitHub Desktop.
Save CopperStarSystems/06a8a6b1a59ebebd82b01612300a5d37 to your computer and use it in GitHub Desktop.
Abstracting SomeOtherDependency so we can test the ReallyHardToTest constructor
// This is an example class illustrating some common patterns
// that negatively impact testability
//
// In this round, we are introducing an abstraction
// for SomeOtherDependency
public class ReallyHardToTest{
SomeModel model;
IPathWrapper pathWrapper;
public ReallyHardToTest(ISomeOtherDependency otherDependency, IPathWrapper pathWrapper){
this.pathWrapper = pathWrapper;
model = new SomeModel();
otherDependency.DoSomething();
}
public void SetFilename(string fileName){
model.Filename = pathWrapper.GetFileName(fileName);
}
}
public class SomeModel{
public string Filename{get;set;}
}
public interface ISomeOtherDependency{
void DoSomething();
}
public class SomeOtherDependency : ISomeOtherDependency {
public void DoSomething(){
// Just here for illustration
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment