예제 #1
0
        public void Helper_Amazon_GetAmazonS3Client()
        {
            //Arrange

            //Act
            var result = AH.GetAmazonS3Client() as IAmazonS3;

            //Assert
            Assert.IsNotNull(result);
        }
예제 #2
0
        public void Helper_Amazon_GetS3ObjectUrl()
        {
            //Arrange
            string bucketName = "sampleBucketName";
            string objectName = "sampleObjectName";
            //Act
            var result = AH.GetS3Object(bucketName, objectName) as string;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(AH.s3PrefixUrl + "sampleBucketName/sampleObjectName", result);
        }
예제 #3
0
        public void Helper_Amazon_GetAmazonS3ObjectPresignedUrl()
        {
            //Arrange
            string bucketName  = "sampleBucketName";
            string objectName  = "sampleObjectName";
            string expectedUrl = "https://s3.ap-south-1.amazonaws.com/sampleBucketName/sampleObjectName?X-Amz-Expires=300&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIUAYVIL7A7I6XECA/ap-south-1/s3/aws4_request&X-Amz-Date=";
            //Act
            var result = AH.GetAmazonS3Object(bucketName, objectName) as string;
            //Get the substring from the result removing the date  and amazon signed signatures as it varies every time
            var subString = result.Split('=')[0] + "=" + result.Split('=')[1] + "=" + result.Split('=')[2] + "=" + (result.Split('=')[3]).Split('/')[0] + "/" + (result.Split('=')[3]).Split('/')[2] + "/" + (result.Split('=')[3]).Split('/')[3] + "/" + result.Split('=')[3].Substring(result.Split('=')[3].LastIndexOf('/') + 1) + "=";

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedUrl, subString);
        }
        public async Task <ActionResult> Get(string productFor, string productType)
        {
            try
            {
                var collection = _db.GetCollection <Product>("Product");
                var filter     = Builders <Product> .Filter.Eq("ProductFor", productFor) & Builders <Product> .Filter.Eq("ProductType", productType);

                IAsyncCursor <Product> cursor = await collection.FindAsync(filter);

                var products = cursor.ToList();
                if (products.Count > 0)
                {
                    foreach (var product in products)
                    {
                        string objectName = product.ProductSKU + ".jpg";
                        //product.MinioObject_URL = WH.GetMinioObject("arthurclive-products", objectName).Result;
                        //product.MinioObject_URL = AH.GetAmazonS3Object("arthurclive-products", objectName);
                        product.MinioObject_URL = AH.GetS3Object("arthurclive-products", objectName);
                    }
                    return(Ok(new ResponseData
                    {
                        Code = "200",
                        Message = "Success",
                        Data = products
                    }));
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "404",
                        Message = "No products found",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("SubCategoryController", "Get", "Get Subcategories", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }