示例#1
0
        public async Task ReleaseLockAsync_removes_file_if_exists([Frozen] S3ConcurrencyServiceOptions options, [Frozen] IAmazonS3 s3, S3ConcurrencyService sut, string token)
        {
            Mock.Get(s3)
            .Setup(p => p.GetObjectMetadataAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetObjectMetadataResponse {
                HttpStatusCode = HttpStatusCode.OK
            });

            await sut.ReleaseLockAsync(token);

            Mock.Get(s3).Verify(p => p.DeleteObjectAsync(options.BucketName, ObjectName(options.FilePrefix, token), It.IsAny <CancellationToken>()));
        }
示例#2
0
        public async Task TryAcquireLockAsync_creates_file_if_not_exists([Frozen] S3ConcurrencyServiceOptions options, [Frozen] IAmazonS3 s3, S3ConcurrencyService sut, string token)
        {
            Mock.Get(s3)
            .Setup(p => p.GetObjectMetadataAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ThrowsAsync(new AmazonS3Exception("NotFound")
            {
                StatusCode = HttpStatusCode.NotFound
            });

            await sut.TryAcquireLockAsync(token);

            Mock.Get(s3).Verify(p => p.PutObjectAsync(PutRequest(options, token), It.IsAny <CancellationToken>()));
        }
示例#3
0
 public static PutObjectRequest PutRequest(S3ConcurrencyServiceOptions options, string token) => Match.Create <PutObjectRequest>(r => r.BucketName == options.BucketName && r.Key.StartsWith(options.FilePrefix) && r.Key.EndsWith(token) && r.ContentBody == string.Empty);