How would you write a proper unit test around this method?
public bool ValidateMemoryUnitPath(string path)
{
var isValidName = Regex.Matches(path, @"^[a-zA-Z0-9_\-:.,+$]").Count == path.Length;
var isValidFormat = DriveInfo.GetDrives()
.Any(d => d.DriveType == DriveType.Removable
&& d.Name == path
&& (d.DriveFormat == "FAT16" || d.DriveFormat == "FAT"));
return isValidName && isValidFormat;
}
Below I have listed a test method with a comment where my confusion is
[TestMethod]
public void ValidateMemoryUnitPathReturnsTrue()
{
// arrange
const string validPath = "MemoryUnitTest.txt";
var sut = new CardInitializer();
// WHAT IS THE CORRECT WAY TO DO THIS
var drive = Mock.Create<DriveInfo>();
drive.Arrange(x => x.Name).Returns(validPath);
drive.Arrange(x => x.DriveFormat).Returns("FAT16");
// assert
Assert.IsTrue(sut.ValidateMemoryUnitPath(validPath));
}
Aucun commentaire:
Enregistrer un commentaire