What would be the best way to unit test if a file upload to a AWS S3 bucket succeeded?
Right now I am doing the following:
[Test]
public void UploadFileToAWS()
{
// Arrange
var bucket = "bucketName";
var keyName = "test_upload.txt";
var originalFile = new FileStream(@"C:\test.txt", FileMode.Open, FileAccess.Read);
// Act
var aws = new AmazonWebServicesUtility(bucket);
var awsUpload = aws.UploadFile(keyName,originalFile);
// Assert
Assert.AreEqual(true, awsUpload);
}
The method UploadFile() is taken from the AWS documentation using a FileStream to upload to AWS.
What I do not like about this approach is, that it needs a local file (C:\test.txt) - so this unit test won't work if shared through version control.
How could I modify this unit test so it doesn't rely on a local file?
Would it make sense to use System.IO.Path.GetTempPath()
to create a temporary text file that I upload and use as a comparison in the unit test?
I am fairly new to unit tests, so I am happy for any direction you can point me in :-)
Thank you very much!