public IActionResult Edit(MonumentEditViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(base.RedirectToAction("Edit", new { monumentId = model.Id }));
            }

            this.monumentsService.Update(model);

            return(base.RedirectToAction("Details", new { monumentId = model.Id }));
        }
Ejemplo n.º 2
0
        public void Update_DoNotChangeMonumentPhotoIfDoNotHaveGivenPhoto()
        {
            int oblastId = 1;
            int monumentId = 2;
            string imageUrl = "testImageUrl";
            this.dbContext.Oblasts.Add(new Oblast { Id = oblastId });
            this.dbContext.Monuments.Add(new Monument { Id = monumentId, ImageUrl = imageUrl });
            this.dbContext.SaveChanges();

            var model = new MonumentEditViewModel { Id = monumentId, SelectedOblastId = oblastId };
            this.monumentsService.Update(model);

            string result = this.dbContext.Monuments.First().ImageUrl;
            result.ShouldBe(imageUrl);
        }
Ejemplo n.º 3
0
        public void Update_UpdateGivenMonumentCorrectly()
        {
            int monumentId = 3;
            this.dbContext.Monuments.Add(new Monument { Id = monumentId });
            this.dbContext.SaveChanges();

            int oblastId = 1;
            this.dbContext.Oblasts.Add(new Oblast { Id = oblastId });
            this.dbContext.SaveChanges();

            string description = "testDescription";
            string name = "testName";
            IFormFile photo = new Mock<IFormFile>().Object;

            var model = new MonumentEditViewModel
            {
                Id = monumentId,
                Description = description,
                Name = name,
                Photo = photo,
                SelectedOblastId = oblastId,
            };

            string imageUrl = "testUrl";
            string imagesDirectory = "wwwroot/images/monuments/";
            string imagesFolderName = "monuments";
            var mockedImagesUploader = new Mock<ImagesUploader>(null);
            mockedImagesUploader
                .Setup(x => x.Upload(photo, imagesDirectory, imagesFolderName))
                .Returns(imageUrl);

            typeof(MonumentsService)
                .GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
                .First(x => x.FieldType == typeof(ImagesUploader))
                .SetValue(this.monumentsService, mockedImagesUploader.Object);

            this.monumentsService.Update(model);

            Monument result = this.dbContext.Monuments.First();
            result.ShouldSatisfyAllConditions
            (
                () => result.Description.ShouldBe(description),
                () => result.Name.ShouldBe(name),
                () => result.OblastId.ShouldBe(oblastId),
                () => result.ImageUrl.ShouldBe(imageUrl)
            );
        }
Ejemplo n.º 4
0
        public void Update(MonumentEditViewModel model)
        {
            if (!this.oblastsService.CheckExistById(model.SelectedOblastId))
            {
                throw new OblastNullException();
            }

            Monument monument = this.GetById(model.Id);

            monument.Name        = model.Name;
            monument.Description = model.Description;
            monument.OblastId    = model.SelectedOblastId;

            if (model.Photo != null)
            {
                monument.ImageUrl = this.imagesUploader.Upload(model.Photo, ImagesDirectory, ImagesFolderName);
            }

            this.dbContext.SaveChanges();
        }
Ejemplo n.º 5
0
 public void Update_ThrowExceptionIfOblastWithGivenIdDoNotExist()
 {
     var model = new MonumentEditViewModel { SelectedOblastId = 1 };
     Action testCode = () => this.monumentsService.Update(model);
     testCode.ShouldThrow<OblastNullException>();
 }