public void GetSingleFile_FileExits_BlobItem()
        {
            //arrange
            BlobItemManager model = new BlobItemManager();

            //act
            BlobItem result = model.GetSingleFile(7);

            //assert
            Assert.IsInstanceOfType(result, typeof(BlobItem));
        }
        public void GetSingleFile_FileNotExits_Null()
        {
            //arrange
            BlobItemManager model = new BlobItemManager();

            //act
            BlobItem result = model.GetSingleFile(99999999);

            //assert
            Assert.IsNull(result);
        }
コード例 #3
0
        // PATCH tables/Car/48D68C86-6EA6-4C25-AA33-223FC9A27959
        /// <summary>
        /// Patches the cars.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="patch">The patch.</param>
        /// <returns>Task&lt;Car&gt;.</returns>
        public async Task <Car> PatchCar(string id, Delta <Car> patch)
        {
            var item = patch.GetEntity();

            if (!_context.Exist <Car>(id))
            {
                throw new ArgumentException("The customer not exist.");
            }
            if (string.IsNullOrEmpty(item.Name))
            {
                throw new ArgumentException("Your data is not correct.");
            }
            BlobItem blobItem           = null;
            var      urlToDelete        = item.Url;
            string   storageAccountName = string.Empty;
            string   storageAccountKey  = string.Empty;

            // the ImageName helps to know that a new image will be uploaded
            // this way, the last image will be delete and a new one will be created
            // the url is not reuse to avoid issue when apps has images in cache
            if (item.BlobItem != null && !string.IsNullOrEmpty(item.BlobItem.ImageName))
            {
                if (!(Services.Settings.TryGetValue("STORAGE_ACCOUNT_NAME", out storageAccountName) | Services.Settings.TryGetValue("STORAGE_ACCOUNT_ACCESS_KEY", out storageAccountKey)))
                {
                    throw new NullReferenceException(Message);
                }
                blobItem = await BlobItemManager.DefineAsync("CarPhoto", storageAccountName, storageAccountKey);

                blobItem.ImageName = item.BlobItem.ImageName;
                item.Url           = blobItem.ImageUrl;
            }

            var current = await UpdateAsync(id, patch);

            if (string.IsNullOrEmpty(urlToDelete))
            {
                BlobItemManager.DeleteAsync(urlToDelete, storageAccountName, storageAccountKey);
            }
            current.BlobItem = blobItem;
            return(current);
        }
コード例 #4
0
        // POST tables/Car
        /// <summary>
        /// Posts the cars.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>Task&lt;IHttpActionResult&gt;.</returns>
        public async Task <IHttpActionResult> PostCar(Car item)
        {
            // In this case is considered a imagem will be uploaded, each time a car is created
            if (string.IsNullOrEmpty(item.Name))
            {
                return(BadRequest("Your data is not correct."));
            }
            string storageAccountName;
            string storageAccountKey;

            // Try to get the Azure storage account token from app settings.
            if (!(Services.Settings.TryGetValue("STORAGE_ACCOUNT_NAME", out storageAccountName) | Services.Settings.TryGetValue("STORAGE_ACCOUNT_ACCESS_KEY", out storageAccountKey)))
            {
                throw new NullReferenceException(Message);
            }

            var blobItem = await BlobItemManager.DefineAsync("CarPhoto", storageAccountName, storageAccountKey);

            item.Url = blobItem.ImageUrl;
            var current = await InsertAsync(item);

            current.BlobItem = blobItem;
            return(CreatedAtRoute("Tables", new { id = current.Id }, current));
        }
 public BlobFileHandler()
 {
     model = new BlobItemManager();
 }
 public FolderModel()
 {
     _context  = new woefiedatabaseContext();
     blobModel = new BlobItemManager();
 }