Exemplo n.º 1
0
        public async Task Basic_Post_Get_Delete_Image()
        {
            using var stream = File.OpenRead("Assets/test.png");
            var imageFile = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name));

            var postResult = await _controller.PostImage(imageFile, "Media", "example_id");

            Assert.IsType <CreatedAtActionResult>(postResult.Result);

            var createdResult = postResult.Result as CreatedAtActionResult;
            var createdImage  = createdResult.Value as Image;

            var getResult = await _controller.GetImage(createdImage.Id);

            Assert.Equal(createdImage, getResult.Value);

            Assert.Equal(createdImage.ImageFile.Path, getResult.Value.ImageFile.Path);

            var deleteResult = await _controller.DeleteImage(createdImage.Id);

            Assert.Equal(createdImage, deleteResult.Value);

            getResult = await _controller.GetImage(createdImage.Id);

            Assert.Equal(Status.Deleted, getResult.Value.IsDeletedStatus);
        }
Exemplo n.º 2
0
        public async Task DeleteImageTest()
        {
            var ImageDeleteResult = await ImagesController.DeleteImage(1);

            var   DeletedImage = ImageDeleteResult.Value as ImageDTO;
            Image oldImage     = db.GetDbContext().Images.Find(1);

            Assert.IsNotNull(DeletedImage);
            Assert.AreEqual(DeletedImage.ImageId, 1);
            Assert.AreEqual(DeletedImage.ByteImage, Convert.ToBase64String(DbContent[0].ByteImage));
        }
Exemplo n.º 3
0
        public async Task DeleteImageReturns503WhenStorageIsDown()
        {
            var imageStoreMock = new Mock <IImageStore>();

            imageStoreMock.Setup(store => store.Delete(_testImageUpload.ImageId)).ThrowsAsync(new StorageErrorException());

            var           loggerStub = new ImagesControllerLoggerStub();
            var           controller = new ImagesController(imageStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.DeleteImage(_testImageUpload.ImageId);

            AssertUtils.HasStatusCode(HttpStatusCode.ServiceUnavailable, result);
            Assert.Contains(LogLevel.Warning, loggerStub.LogEntries.Select(entry => entry.Level));
        }
Exemplo n.º 4
0
        public async Task DeleteImageReturns500WhenExceptionIsNotKnown()
        {
            var imageStoreMock = new Mock <IImageStore>();

            imageStoreMock.Setup(store => store.Delete(_testImageUpload.ImageId)).ThrowsAsync(new Exception("Test Exception"));

            var           loggerStub = new ImagesControllerLoggerStub();
            var           controller = new ImagesController(imageStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.DeleteImage(_testImageUpload.ImageId);

            AssertUtils.HasStatusCode(HttpStatusCode.InternalServerError, result);
            Assert.Contains(LogLevel.Error, loggerStub.LogEntries.Select(entry => entry.Level));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var exhaust = await _context.Exhausts.FindAsync(id);

            _context.Exhausts.Remove(exhaust);

            var image = new ImagesController(_context, _hostingEnv);

            image.DeleteImage(id);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("DiameterInches,DegreeBend,Material,BrandID,ProductTypeID,ProductName,ProductDescription,VehicleModel,ProductCode,Price,InStock")] Exhaust exhaust, IFormFile file)
        {
            if (id != exhaust.ProductID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(exhaust);
                    await _context.SaveChangesAsync();

                    // tlannigan
                    if (file != null)
                    {
                        var image = new ImagesController(_context, _hostingEnv);
                        image.DeleteImage(id);
                        image.SaveImage(id, file);
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExhaustExists(exhaust.ProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandID"]       = new SelectList(_context.Brands, "BrandID", "BrandName", exhaust.BrandID);
            ViewData["ProductTypeID"] = new SelectList(_context.ProductTypes, "ProductTypeID", "ProductTypeName", exhaust.ProductTypeID);
            return(View(exhaust));
        }