私は単体テスト/ moq が初めてで、これをどのように行うことができるか疑問に思っていました。ファイルをs3からローカルにダウンロードする機能があります。実際に transferUtility を使用して s3 から何かをダウンロードしないように、これをモックするにはどうすればよいですか?
bool downloadFileFromS3(string localPathToSave, string filenameToDownloadAs, string bucketName, string objectKey)
{
try
{
string accessKey = "xxx";
string secretKey = "xxx";
// do stuff before
TransferUtility transferUtility = new TransferUtility(accessKey, secretKey);
transferUtility.Download( Path.Combine(localPathToSave, filenameToDownloadAs), bucketName, objectKey );
// do stuff after
return true;
}
catch (Exception e)
{
// stuff
}
}
モックを作成しましたが、作成した関数をテストするためにそれを使用する方法がわかりません。
[Test]
public void testDownloadFromS3()
{
string filePath = null;
string bucketName = null;
string key = null;
Mock<Amazon.S3.Transfer.TransferUtility> mock = new Mock<Amazon.S3.Transfer.TransferUtility>();
//mock.Setup(x => x.Download(filePath, bucketName, key)).Verifiable();
//Mock.Verify();
}