コード例 #1
0
        public ReadModelResult GetImageAsync(Guid imageId)
        {
            if (imageId == Guid.Empty)
            {
                return(new ReadModelResult(ResultStatus.Failed, "ImageId is not valid."));
            }

            var modelResult = new ReadModelResult(imageId);

            try
            {
                var getPreSignedUrlRequest = new GetPreSignedUrlRequest
                {
                    BucketName = _configuration.GetSection("S3Buckets")["Images"],
                    Key        = imageId.ToString(),
                    Expires    = DateTime.MaxValue
                };

                var preSignedUrl = _amazonS3Client.GetPreSignedURL(getPreSignedUrlRequest);

                var imageLocation = new UriBuilder(preSignedUrl)
                {
                    Scheme = HttpScheme.Http.ToString()
                };

                modelResult.Locations = new[] { imageLocation.Uri.AbsoluteUri };
            }
            catch (Exception ex)
            {
                return(new ReadModelResult(ResultStatus.Failed, ex.Message));
            }

            return(modelResult);
        }
コード例 #2
0
        public GetTests()
        {
            _imageId         = Guid.NewGuid();
            _readModelResult = new ReadModelResult(_imageId)
            {
                Locations = new[] { "https://someimagelocation.com" }
            };

            var imageRepository = Substitute.For <IImageRepository>();

            imageRepository
            .GetImageAsync(Guid.Empty)
            .Returns(new ReadModelResult(ResultStatus.Failed));
            imageRepository
            .GetImageAsync(_imageId)
            .Returns(_readModelResult);

            _controller = new ImagesController(imageRepository);
        }