-
-
Save vkhorikov/3f41419fa139a290058cecdca1885965 to your computer and use it in GitHub Desktop.
Code pollution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderRepository | |
{ | |
public void Save(Order order) | |
{ | |
/* ... */ | |
} | |
public Order GetById(long id) | |
{ | |
/* ... */ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void Some_integration_test() | |
{ | |
// Arrange | |
var repository = new OrderRepository(); | |
var service = new OrderService(repository); | |
long customerId = 42; | |
// Act | |
service.DoSomething(customerId); | |
// Assert | |
// ToDo : check there are 2 orders in the database for the customerId 42 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void Some_integration_test() | |
{ | |
// Arrange | |
var repository = new OrderRepository(); | |
var service = new OrderService(repository); | |
long customerId = 42; | |
// Act | |
service.DoSomething(customerId); | |
// Assert | |
IReadOnlyList<Order> orders = repository.GetByCustomerId(customerId); // Code added for the use in this unit test | |
/* validate orders */ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Logger | |
{ | |
public void Log(string text) | |
{ | |
/* Log the text */ | |
} | |
} | |
public class Controller | |
{ | |
public void SomeMethod(Logger logger) | |
{ | |
logger.Log("SomeMethod is called"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Logger | |
{ | |
private readonly bool _isTestEnvironment; | |
public Logger(bool isTestEnvironment) | |
{ | |
_isTestEnvironment = isTestEnvironment; | |
} | |
public void Log(string text) | |
{ | |
if (_isTestEnvironment) | |
return; | |
/* Log the text */ | |
} | |
} | |
public class Controller | |
{ | |
public void SomeMethod(Logger logger) | |
{ | |
logger.Log("SomeMethod is called"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void Some_test() | |
{ | |
// Arrange | |
var logger = new Logger(true); | |
var controller = new Controller(); | |
// Act | |
controller.SomeMethod(logger); | |
// Assert | |
/* ... */ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ILogger | |
{ | |
void Log(string text); | |
} | |
public class Logger : ILogger | |
{ | |
public void Log(string text) | |
{ | |
/* Log the text */ | |
} | |
} | |
public class FakeLogger : ILogger | |
{ | |
public void Log(string text) | |
{ | |
} | |
} | |
public class Controller | |
{ | |
public void SomeMethod(ILogger logger) | |
{ | |
logger.Log("SomeMethod is called"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void Some_test() | |
{ | |
// Arrange | |
ILogger logger = new FakeLogger(); // FakeLogger instead of Logger | |
var controller = new Controller(); | |
// Act | |
controller.SomeMethod(logger); | |
// Assert | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment