Ejemplo n.º 1
0
        public void FileNameWithImageExtensionShouldNotReturnNull()
        {
            //Arrange
            var converter    = new ImageStreamConverter();
            var httpFileStub = GetStubbedPostedFileWithImage("someImage.jpg");

            //Act
            var result = converter.GetBitmapFromPostedFile(httpFileStub);

            //Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 2
0
        public void FileNameWithoutImageExtensionAndLotsOfPeriodsShouldNotBeValidAndReturnNull()
        {
            //Arrange
            var converter = new ImageStreamConverter();

            var httpFileStub = GetStubbedPostedFile("some.File.that.isnt.an.image.txt");

            //Act
            var result = converter.GetBitmapFromPostedFile(httpFileStub);

            //Assert
            Assert.IsNull(result);
        }
Ejemplo n.º 3
0
        public ActionResult Index(HttpPostedFileBase image)
        {
            if (image == null)
            {
                return(Index("Where's the beef?"));
            }
            var imageStreamConverter = new ImageStreamConverter();
            var bitmap = imageStreamConverter.GetBitmapFromPostedFile(image);

            if (bitmap == null)
            {
                return(Index("That's not an image, homie..."));
            }


            var serviceBusConnectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            var blobConnectionString       = CloudConfigurationManager.GetSetting("BlobStorage.ConnectionString");

            var storageAccount = CloudStorageAccount.Parse(blobConnectionString);
            var blobClient     = storageAccount.CreateCloudBlobClient();
            var container      = blobClient.GetContainerReference("images");

            container.CreateIfNotExists();

            var blockReference = container.GetBlockBlobReference(image.FileName);
            var converter      = new ImageConverter();
            var bitmapBytes    = (byte[])converter.ConvertTo(bitmap, typeof(byte[]));

            blockReference.UploadFromByteArray(bitmapBytes, 0, bitmapBytes.Length);

            var namespaceManager = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);

            if (!namespaceManager.QueueExists("ImageProcessing"))
            {
                namespaceManager.CreateQueue("ImageProcessing");
            }

            var client  = QueueClient.CreateFromConnectionString(serviceBusConnectionString, "ImageProcessing");
            var message = new BrokeredMessage(new ImageMessage {
                BlobBlockName = blockReference.Name
            });

            client.Send(message);
            return(Index());
        }