Ejemplo n.º 1
0
 protected override void ProcessRecord()
 {
     try
     {
         var logger = new PsCmdletLogger(this);
         s3FileSystem = new S3FileSystem(logger, AccessKey, Secret, new AmazonS3Config());
         s3FileSystem.UploadFiles(new DirectoryInfoWrap(Folder), Recurse, Bucket, SetPublicRead);
     }
     catch (Exception e)
     {
         ThrowTerminatingError(
             new ErrorRecord(
                 e,
                 "Copy-FilesToS3",
                 ErrorCategory.NotSpecified,
                 this
                 )
             );
     }
 }
Ejemplo n.º 2
0
 public void TearDown()
 {
     S3FileSystem = null;
     DirectoryInfo = null;
     AmazonS3 = null;
 }
Ejemplo n.º 3
0
 protected override void EndProcessing()
 {
     s3FileSystem = null;
 }
Ejemplo n.º 4
0
        public void SetUp()
        {
            var file1 = new Mock<IFileInfoWrap>();
            file1.Setup(x => x.Name).Returns("File1.jpg");
            file1.Setup(x => x.FullName).Returns("c:\\files\\File1.jpg");

            var file2 = new Mock<IFileInfoWrap>();
            file2.Setup(x => x.Name).Returns("File2.jpg");
            file2.Setup(x => x.FullName).Returns("c:\\files\\File2.jpg");

            var file3 = new Mock<IFileInfoWrap>();
            file3.Setup(x => x.Name).Returns("File3.jpg");
            file3.Setup(x => x.FullName).Returns("c:\\files\\morefiles\\File3.jpg");

            var file4 = new Mock<IFileInfoWrap>();
            file4.Setup(x => x.Name).Returns("File4.jpg");
            file4.Setup(x => x.FullName).Returns("c:\\files\\morefiles\\File4.jpg");

            var file5 = new Mock<IFileInfoWrap>();
            file5.Setup(x => x.Name).Returns("File5.jpg");
            file5.Setup(x => x.FullName).Returns("c:\\files\\otherfiles\\File5.jpg");

            var moreFilesDirectory = new Mock<IDirectoryInfoWrap>();
            moreFilesDirectory.Setup(x => x.GetFiles()).Returns(() => new IFileInfoWrap[] { file3.Object, file4.Object });
            moreFilesDirectory.Setup(x => x.GetDirectories()).Returns(() => new IDirectoryInfoWrap[] { });
            moreFilesDirectory.Setup(x => x.Exists).Returns(() => true);
            moreFilesDirectory.Setup(x => x.Name).Returns(() => "morefiles");
            moreFilesDirectory.Setup(x => x.FullName).Returns(() => "c:\\files\\morefiles");

            var otherfilesDirectory = new Mock<IDirectoryInfoWrap>();
            otherfilesDirectory.Setup(x => x.GetFiles()).Returns(() => new IFileInfoWrap[] { file5.Object });
            otherfilesDirectory.Setup(x => x.GetDirectories()).Returns(() => new IDirectoryInfoWrap[] { });
            otherfilesDirectory.Setup(x => x.Exists).Returns(() => true);
            otherfilesDirectory.Setup(x => x.Name).Returns(() => "otherfiles");
            otherfilesDirectory.Setup(x => x.FullName).Returns(() => "c:\\files\\otherfiles");

            DirectoryInfo = new Mock<IDirectoryInfoWrap>();
            DirectoryInfo.Setup(x => x.GetFiles()).Returns(() => new IFileInfoWrap[] {file1.Object, file2.Object});
            DirectoryInfo.Setup(x => x.GetDirectories()).Returns(() => new IDirectoryInfoWrap[] { moreFilesDirectory.Object, otherfilesDirectory.Object });
            DirectoryInfo.Setup(x => x.Exists).Returns(() => true);
            DirectoryInfo.Setup(x => x.Name).Returns(() => "files");
            DirectoryInfo.Setup(x => x.FullName).Returns(() => "c:\\files");

            var notFoundException = new AmazonS3Exception("Key not found", HttpStatusCode.NotFound);

            AmazonS3 = new Mock<AmazonS3>();
            AmazonS3.Setup(x => x.PutObject(It.IsAny<PutObjectRequest>())).Returns(new PutObjectResponse()).Verifiable();
            AmazonS3.Setup(x => x.GetObjectMetadata(It.IsAny<GetObjectMetadataRequest>())).Throws(notFoundException);

            S3FileSystem = new S3FileSystem(AmazonS3.Object, GetFileStreamFromFile);
        }