Пример #1
0
        public async void TestListKeys()
        {
            var rootPath = $"/unittests/listkeys_{new Random().Next()}";

            const string originalFileContents = "test-data-please-ignore";
            var          s3Key1 = $"{rootPath}/Upload-test-s3Key" + DateTime.Now.Ticks + Guid.NewGuid();
            var          s3Key2 = $"{rootPath}/Upload-test-s3Key" + DateTime.Now.Ticks + Guid.NewGuid();
            var          result = TimeSpan.FromHours(1);

            var mockStore = new Mock <IConfigurationStore>();

            mockStore.Setup(x => x.GetValueString("AWS_TEMPORARY_BUCKET_NAME")).Returns("vss-unittests-local");
            mockStore.Setup(x => x.GetValueTimeSpan("AWS_PRESIGNED_URL_EXPIRY")).Returns(result);

            var transferProxy = new LocalTransferProxy(mockStore.Object, new NullLogger <LocalTransferProxy>(), "AWS_TEMPORARY_BUCKET_NAME");

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(originalFileContents)))
            {
                transferProxy.Upload(ms, s3Key1);
                transferProxy.Upload(ms, s3Key2);
            }

            var(resultKeys, nextContinuationToken) = await transferProxy.ListKeys(rootPath, 1000, "");

            Assert.True(resultKeys.Length == 2);
            Assert.True(string.IsNullOrEmpty(nextContinuationToken));
        }
Пример #2
0
        public void TestUpload()
        {
            const string originalFileContents = "test-data-please-ignore";
            var          s3Key     = "/unittests/Upload-test-s3Key" + DateTime.Now.Ticks + Guid.NewGuid();
            var          result    = TimeSpan.FromHours(1);
            var          mockStore = new Mock <IConfigurationStore>();

            mockStore.Setup(x => x.GetValueString("AWS_TEMPORARY_BUCKET_NAME")).Returns("vss-unittests-local");
            mockStore.Setup(x => x.GetValueTimeSpan("AWS_PRESIGNED_URL_EXPIRY")).Returns(result);

            var transferProxy = new LocalTransferProxy(mockStore.Object, new NullLogger <LocalTransferProxy>(), "AWS_TEMPORARY_BUCKET_NAME");

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(originalFileContents)))
            {
                transferProxy.Upload(ms, s3Key);
            }

            var s3ResultStream     = transferProxy.Download(s3Key).Result.FileStream;
            var resultMemoryStream = new MemoryStream();

            s3ResultStream.CopyTo(resultMemoryStream);

            resultMemoryStream.Seek(0, SeekOrigin.Begin);

            var text = Encoding.UTF8.GetString(resultMemoryStream.ToArray());

            Assert.Equal(originalFileContents, text);
        }