파일의 단위 테스트 저장을 시도하고 있습니다. 문서를 정의하는 인터페이스가 있고 저장 메서드에 해당 인터페이스를 구현하는 구체적인 개체를 전달하고 실제로 작동하지만 단색 테스트를 통해 항상 작동하는지 확인하려고합니다. 필자는 '위기 시간'이후 단위 테스트를 따라 잡기 위해 필사적으로 노력했다).조롱 된 인터페이스가 여전히 파일에 직렬화됩니까?
public Boolean SaveDocument(IDocument document)
{
BinaryFormatter bFormatter = new BinaryFormatter();
FileStream fs = null;
try
{
if (!Directory.Exists(folderName))
Directory.CreateDirectory(folderName);
String path = Path.Combine(Path.Combine(folderName, document.FileName), document.Extension);
using (fs = new FileStream(path, FileMode.OpenOrCreate))
{
bFormatter.Serialize(fs, document);
}
}
catch (IOException ioex)
{
LOG.Write(ioex.Message);
return false;
}
return true;
}
내 시험은 다음과 같습니다 :
[Test]
public void can_save_a_document()
{
String testDirectory = "C:\\Test\\";
m_DocumentHandler = new DocumentHandler(testDirectory);
DynamicMock mock = new DynamicMock(typeof(IDocument));
mock.ExpectAndReturn("get_FileName", "Test_File");
mock.ExpectAndReturn("get_Extension", ".TST");
m_DocumentHandler.SaveDocument(mock.MockInstance as IDocument);
try
{
Assert.IsTrue(Directory.Exists(testDirectory), "Directory was not created");
String[] filesInTestDir = Directory.GetFiles(testDirectory);
Assert.AreEqual(1, filesInTestDir.Length, "there is " + filesInTestDir.Length.ToString() + " files in the folder, instead of 1");
Assert.AreEqual(Path.GetFileName(filesInTestDir[0]), "Test_File.TST");
}
finally
{
Directory.Delete(testDirectory);
Assert.IsFalse(Directory.Exists(testDirectory), "folder was not cleaned up");
}
}
내가 인터페이스 preserves the concrete data를 직렬화 것을 알고 있어요,하지만 인터페이스를 조롱 할 방법을 저장 내
는 그렇게처럼 작동, 아주 간단합니다 직렬화할까요?