示例#1
0
        public void TestDeleteDerived()
        {
            // should allow deleting derived resource
            var publicId = GetUniquePublicId();

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                EagerTransforms = new List <Transformation>()
                {
                    m_simpleTransformation
                },
                PublicId = publicId,
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(1, resource.Derived.Length);

            DelDerivedResResult delDerivedResult = m_cloudinary.DeleteDerivedResources(resource.Derived[0].Id);

            Assert.AreEqual(1, delDerivedResult.Deleted.Values.Count);

            resource = m_cloudinary.GetResource(publicId);
            Assert.IsFalse(String.IsNullOrEmpty(resource.PublicId));
        }
        public void TestDelete()
        {
            // should allow deleting resources
            var publicId            = GetUniquePublicId();
            var nonExistingPublicId = GetUniquePublicId();

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = publicId,
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(publicId, resource.PublicId);

            DelResResult delResult = m_cloudinary.DeleteResources(
                nonExistingPublicId, publicId);

            Assert.AreEqual("not_found", delResult.Deleted[nonExistingPublicId]);
            Assert.AreEqual("deleted", delResult.Deleted[publicId]);

            resource = m_cloudinary.GetResource(publicId);

            Assert.IsTrue(String.IsNullOrEmpty(resource.PublicId));
        }
        public void TestGetResource()
        {
            // should allow get resource details
            var publicId = GetUniquePublicId();
            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                EagerTransforms = new List <Transformation>()
                {
                    m_simpleTransformation
                },
                PublicId = publicId,
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult getResult = m_cloudinary.GetResource(
                new GetResourceParams(publicId)
            {
                Phash = true
            });

            Assert.IsNotNull(getResult);
            Assert.AreEqual(publicId, getResult.PublicId);
            Assert.AreEqual(1920, getResult.Width);
            Assert.AreEqual(1200, getResult.Height);
            Assert.AreEqual(FILE_FORMAT_JPG, getResult.Format);
            Assert.AreEqual(1, getResult.Derived.Length);
            Assert.Null(getResult.ImageMetadata);
            Assert.NotNull(getResult.Phash);
        }
        public void TestDeleteByTag()
        {
            // should allow deleting resources

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = "api_test4",
                Tags     = "api_test_tag_for_delete"
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource(
                "api_test4");

            Assert.IsNotNull(resource);
            Assert.AreEqual("api_test4", resource.PublicId);

            DelResResult delResult = m_cloudinary.DeleteResourcesByTag(
                "api_test_tag_for_delete");

            resource = m_cloudinary.GetResource("api_test4");

            Assert.IsTrue(String.IsNullOrEmpty(resource.PublicId));
        }
        public void TestDeleteDerived()
        {
            // should allow deleting derived resource

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                EagerTransforms = new List <Transformation>()
                {
                    new Transformation().Width(101).Crop("scale")
                },
                PublicId = "testdeletederived"
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource("testdeletederived");

            Assert.IsNotNull(resource);
            Assert.AreEqual(1, resource.Derived.Length);

            DelDerivedResResult delDerivedResult =
                m_cloudinary.DeleteDerivedResources(resource.Derived[0].Id);

            Assert.AreEqual(1, delDerivedResult.Deleted.Values.Count);

            resource = m_cloudinary.GetResource("testdeletederived");

            Assert.IsFalse(String.IsNullOrEmpty(resource.PublicId));
        }
        public void TestDelete()
        {
            // should allow deleting resources

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = "testdelete"
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource("testdelete");

            Assert.IsNotNull(resource);
            Assert.AreEqual("testdelete", resource.PublicId);

            DelResResult delResult = m_cloudinary.DeleteResources(
                "randomstringopa", "testdeletederived", "testdelete");

            Assert.AreEqual("not_found", delResult.Deleted["randomstringopa"]);
            Assert.AreEqual("deleted", delResult.Deleted["testdelete"]);

            resource = m_cloudinary.GetResource("testdelete");

            Assert.IsTrue(String.IsNullOrEmpty(resource.PublicId));
        }
        public void TestGetResource()
        {
            // should allow get resource metadata

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                EagerTransforms = new List <Transformation>()
                {
                    new Transformation().Crop("scale").Width(2.0)
                },
                PublicId = "testgetresource"
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult getResult = m_cloudinary.GetResource("testgetresource");

            Assert.IsNotNull(getResult);
            Assert.AreEqual("testgetresource", getResult.PublicId);
            Assert.AreEqual(759100, getResult.Length);
            Assert.AreEqual(1920, getResult.Width);
            Assert.AreEqual(1200, getResult.Height);
            Assert.AreEqual("jpg", getResult.Format);
            Assert.AreEqual(1, getResult.Derived.Length);
            Assert.Null(getResult.Metadata);
        }
        public void TestGetResourceWithMetadata()
        {
            // should allow get resource metadata
            var publicId = GetUniquePublicId();

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                EagerTransforms = new List <Transformation>()
                {
                    m_simpleTransformation
                },
                PublicId = publicId,
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult getResult = m_cloudinary.GetResource(
                new GetResourceParams(publicId)
            {
                ImageMetadata = true
            });

            Assert.IsNotNull(getResult);
            Assert.AreEqual(publicId, getResult.PublicId);
            Assert.NotNull(getResult.ImageMetadata);
        }
        public void TestGetPdfResourceWithNumberOfPages()
        {
            var uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(m_testPdfPath),
                Tags = m_apiTag
            };

            var uploadResult = m_cloudinary.Upload(uploadParams);

            Assert.AreEqual(FILE_FORMAT_PDF, uploadResult.Format);
            Assert.AreEqual(TEST_PDF_PAGES_COUNT, uploadResult.Pages);

            GetResourceResult getResult = m_cloudinary.GetResource(
                new GetResourceParams(uploadResult.PublicId)
            {
                ImageMetadata = true,
                Pages         = true
            });

            Assert.IsNotNull(getResult);
            Assert.AreEqual(uploadResult.PublicId, getResult.PublicId);
            Assert.NotNull(getResult.ImageMetadata);
            Assert.AreEqual(uploadResult.Pages, getResult.Pages);
            Assert.AreEqual(getResult.Pages, TEST_PDF_PAGES_COUNT);
        }
示例#10
0
        public void TestDeleteByTag()
        {
            // should allow deleting resources
            var publicId = GetUniquePublicId();
            var tag      = GetMethodTag();

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = publicId,
                Tags     = $"{tag},{m_apiTag}"
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(publicId, resource.PublicId);

            DelResResult delResult = m_cloudinary.DeleteResourcesByTag(tag);

            resource = m_cloudinary.GetResource(publicId);
            Assert.IsTrue(String.IsNullOrEmpty(resource.PublicId));
        }
示例#11
0
        public void TestRestoreNoBackup()
        {
            string publicId = GetUniquePublicId();

            ImageUploadParams uploadParams_nobackup = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = publicId,
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams_nobackup);
            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(publicId, resource.PublicId);

            DelResResult delResult = m_cloudinary.DeleteResources(publicId);

            Assert.AreEqual("deleted", delResult.Deleted[publicId]);

            resource = m_cloudinary.GetResource(publicId);
            Assert.IsTrue(string.IsNullOrEmpty(resource.PublicId));

            RestoreResult rResult = m_cloudinary.Restore(publicId);

            Assert.IsNotNull(rResult.JsonObj[publicId], string.Format("Should contain key \"{0}\". ", publicId));
            Assert.AreEqual("no_backup", rResult.JsonObj[publicId]["error"].ToString());
        }
示例#12
0
        public GetResourceResult <Note> GetActiveNoteById(int noteId)
        {
            var note = _notesRepository.Find(noteId);

            return(note.ExpirationDate > DateTime.UtcNow || !note.ExpirationDate.HasValue
                ? GetResourceResult <Note> .Success(note)
                : GetResourceResult <Note> .ResourceNotFound);
        }
        public string Get(string id)
        {
            GetResourceResult getResourceResult = cloudinaryService.GetFile(id);

            return(getResourceResult.StatusCode == HttpStatusCode.OK
                ? getResourceResult.SecureUrl
                : null);
        }
示例#14
0
        public async Task <GetResourceResult> UpdateResourceAsync(UpdateParams parameters)
        {
            var url = Api.ApiUrlV.ResourceType("resources").Add(Api.GetCloudinaryParam(parameters.ResourceType)).Add(parameters.Type).Add(parameters.PublicId).BuildUrl();

            using (var response = await Api.CallAsync(HttpMethod.Post, url, parameters.ToParamsDictionary(), null, null))
            {
                return(await GetResourceResult.Parse(response));
            }
        }
示例#15
0
 public async Task <GetResourceResult> GetResourceAsync(GetResourceParams parameters)
 {
     using (
         var response = await Api.CallAsync(HttpMethod.Get,
                                            new UrlBuilder(Api.ApiUrlV.ResourceType("resources").Add(Api.GetCloudinaryParam(parameters.ResourceType)).Add(parameters.Type).Add(parameters.PublicId).BuildUrl(),
                                                           parameters.ToParamsDictionary()).ToString(), null, null, null))
     {
         return(await GetResourceResult.Parse(response));
     }
 }
        public Blob GetBlob(string path)
        {
            String            publicId       = GetFilenameFromPath(path);
            GetResourceParams resourceParams = new GetResourceParams(publicId);
            GetResourceResult result         = cloudinary.GetResource(resourceParams);
            WebClient         webClient      = new WebClient();
            Blob blob = new Blob();

            blob.Bytes = webClient.DownloadData(result.Url);
            return(blob);
        }
 private void AssertUpdatedCustomCoordinates(GetResourceResult result, Core.Rectangle coordinates)
 {
     Assert.NotNull(result.Coordinates);
     Assert.NotNull(result.Coordinates.Custom);
     Assert.AreEqual(1, result.Coordinates.Custom.Length);
     Assert.AreEqual(4, result.Coordinates.Custom[0].Length);
     Assert.AreEqual(coordinates.X, result.Coordinates.Custom[0][0]);
     Assert.AreEqual(coordinates.Y, result.Coordinates.Custom[0][1]);
     Assert.AreEqual(coordinates.Width, result.Coordinates.Custom[0][2]);
     Assert.AreEqual(coordinates.Height, result.Coordinates.Custom[0][3]);
 }
示例#18
0
        public void TestDeleteByTagAndTransformation()
        {
            // should allow deleting resources
            string publicId = GetUniquePublicId();
            string tag      = GetMethodTag();

            var uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                PublicId        = publicId,
                Tags            = tag,
                EagerTransforms = new List <Transformation>()
                {
                    m_simpleTransformation,
                    m_simpleTransformationAngle,
                    m_explicitTransformation
                },
            };

            m_cloudinary.Upload(uploadParams);

            DelResResult delResult = m_cloudinary.DeleteResources(new DelResParams
            {
                Tag             = tag,
                Transformations = new List <Transformation> {
                    m_simpleTransformation
                }
            });

            Assert.NotNull(delResult.Deleted);
            Assert.AreEqual(delResult.Deleted.Count, 1);

            delResult = m_cloudinary.DeleteResources(new DelResParams
            {
                Tag             = tag,
                Transformations = new List <Transformation>()
                {
                    m_simpleTransformationAngle, m_explicitTransformation
                }
            });

            Assert.NotNull(delResult.Deleted);

            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(resource.Derived.Length, 0);
        }
示例#19
0
        public GetResourceResult UpdateResource(UpdateParams parameters)
        {
            UrlBuilder urlBuilder = new UrlBuilder(
                m_api.ApiUrlV.
                ResourceType("resources").
                Add(Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType)).
                Add(parameters.Type).Add(parameters.PublicId).
                BuildUrl(),
                parameters.ToParamsDictionary());

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.POST, urlBuilder.ToString(), null, null))
            {
                return(GetResourceResult.Parse(response));
            }
        }
示例#20
0
        public GetResourceResult GetResource(GetResourceParams parameters)
        {
            UrlBuilder urlBuilder = new UrlBuilder(
                m_api.ApiUrlV.
                ResourceType("resources").
                Add(Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType)).
                Add(parameters.Type).Add(parameters.PublicId).
                BuildUrl());

            foreach (var param in parameters.ToParamsDictionary())
            {
                urlBuilder.QueryString[param.Key] = param.Value.ToString();
            }

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.GET, urlBuilder.ToString(), null, null))
            {
                GetResourceResult result = GetResourceResult.Parse(response);
                return(result);
            }
        }
示例#21
0
        public void TestDeleteByPrefixAndTransformation()
        {
            // should allow deleting resources
            var publicId        = GetUniquePublicId();
            var prefix          = publicId.Substring(0, publicId.Length - 1);
            var transformations = new List <Transformation>
            {
                m_simpleTransformation,
                m_simpleTransformationAngle,
                m_explicitTransformation
            };

            var uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                PublicId        = publicId,
                Tags            = m_apiTag,
                EagerTransforms = transformations
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(3, resource.Derived.Length);

            var delResult = m_cloudinary.DeleteResources(new DelResParams
            {
                Prefix          = prefix,
                Transformations = transformations
            });

            Assert.NotNull(delResult.Deleted);
            Assert.AreEqual(delResult.Deleted.Count, 1);

            resource = m_cloudinary.GetResource(publicId);
            Assert.IsNotNull(resource);
            Assert.AreEqual(resource.Derived.Length, 0);
        }
示例#22
0
        public void TestGetResourceWithMetadata()
        {
            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                EagerTransforms = new List <Transformation>()
                {
                    new Transformation().Crop("scale").Width(2.0)
                },
                PublicId = "testgetresource2"
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult getResult = m_cloudinary.GetResource(
                new GetResourceParams("testgetresource2")
            {
                Metadata = true
            });

            Assert.IsNotNull(getResult);
            Assert.AreEqual("testgetresource2", getResult.PublicId);
            Assert.NotNull(getResult.Metadata);
        }
示例#23
0
        public void TestDeleteByPrefix()
        {
            // should allow deleting resources
            var publicId = GetUniquePublicId();
            var prefix   = publicId.Substring(0, publicId.Length - 1);

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = publicId,
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            GetResourceResult resource = m_cloudinary.GetResource(publicId);

            Assert.IsNotNull(resource);
            Assert.AreEqual(publicId, resource.PublicId);

            m_cloudinary.DeleteResourcesByPrefix(prefix);
            resource = m_cloudinary.GetResource(publicId);
            Assert.IsTrue(String.IsNullOrEmpty(resource.PublicId));
        }
 private void AssertResourceDoesNotExist(GetResourceResult resource)
 {
     Assert.IsNotNull(resource);
     Assert.IsNull(resource.PublicId, resource.Error?.Message);
 }
示例#25
0
 private void AssertGetResourceResultAfterDeletionNoBackup(GetResourceResult resource)
 {
     Assert.IsTrue(string.IsNullOrEmpty(resource.PublicId));
 }
示例#26
0
 private void AssertGetResourceResultAfterRestore(GetResourceResult resource_backup)
 {
     Assert.IsFalse(string.IsNullOrEmpty(resource_backup.PublicId));
 }
示例#27
0
 private void AssertGetResourceResultAfterDeletion(GetResourceResult resource_backup)
 {
     Assert.AreEqual(0, resource_backup.Bytes);
 }
示例#28
0
 private void AssertGetResourceResultBeforeDeletion(GetResourceResult resource_backup, string publicId)
 {
     Assert.IsNotNull(resource_backup);
     Assert.AreEqual(publicId, resource_backup.PublicId);
 }
示例#29
0
 private void AssertResourceDoesNotExist(GetResourceResult resource)
 {
     Assert.IsNotNull(resource);
     Assert.IsNull(resource.PublicId);
 }
示例#30
0
 private void AssertResourceExists(GetResourceResult resource, string publicId)
 {
     Assert.IsNotNull(resource);
     Assert.AreEqual(publicId, resource.PublicId);
 }