Last active
December 12, 2015 07:58
-
-
Save Fodsuk/4740604 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
Write a test or tests to validate that the correct FubarData is passed to IFubarDataService.Validate(...) | |
from the Fubar that is passed to ValidateFubar. | |
e.g. did the Fubar.Name match the FubarData.Name | |
-- note: imagine there was 15+ properties on both Fubar and FubarData that needed validating | |
*/ | |
public class FubarValidator { | |
IFubarDataService _dataService; | |
public FubarValidator(IFubarDataService dataService) { | |
_dataService = dataService; | |
} | |
public bool ValidateFubar(Fubar fubar) { | |
FubarData data = new FubarData(); | |
data.Name = fubar.Name; | |
data.LocationId = fubar.LocationId; | |
data.ComputerAvailable = fubar.HasComputer ? "yes" : "no"; | |
data.FavoritePizza = fubar.FavoritePizza; | |
return _dataService.Validate(data); | |
} | |
} | |
//interfaces | |
public interface IFubarDataService { | |
bool Validate(FubarData data); | |
} | |
//pocos | |
public class Fubar { | |
public string Name { get; set; } | |
public int LocationId { get; set; } | |
public string FavoritePizza { get; set; } | |
public bool HasComputer { get; set; } | |
} | |
public class FubarData { | |
public string Name { get; set; } | |
public int LocationId { get; set; } | |
public string FavoritePizza { get; set; } | |
public bool ComputerAvailable { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment