コード例 #1
0
        public void UpdatePicture_Should_Return_Valid_Data()
        {
            //Arrange
            var mock      = new Mock <IPictureRepository>();
            var myPicture = new PictureDTO
            {
                Id = 1,
                IsProfilePicture = true,
                Resto            = new RestoDTO(),
                Url = "www.myurl.com"
            };

            mock.Setup(x => x.Update(myPicture)).Returns(
                new PictureDTO
            {
                Id = 1,
                IsProfilePicture = false,
                Resto            = new RestoDTO(),
                Url = "www.myurl.com"
            }
                );
            PictureUC target = new PictureUC(mock.Object);

            //Act
            var result = target.UpdatePicture(new PictureBTO
            {
                Id = 1,
                IsProfilePicture = false,
                Resto            = new RestoBTO(),
                Url = "www.myurl.com"
            });

            //Assert
            mock.Verify(u => u.Update(It.IsAny <PictureDTO>()), Times.Once());
        }
コード例 #2
0
        public void UpdatePicture_Should_Return_Null_If_No_Result_Found_In_Db()
        {
            //Arrange
            var mock      = new Mock <IPictureRepository>();
            var myPicture = new PictureDTO
            {
                Id = 1,
                IsProfilePicture = true,
                Resto            = new RestoDTO(),
                Url = "www.myurl.com"
            };

            mock.Setup(x => x.Update(myPicture));
            PictureUC target = new PictureUC(mock.Object);

            //Act
            var result = target.UpdatePicture(new PictureBTO
            {
                Id = 1,
                IsProfilePicture = true,
                Resto            = new RestoBTO(),
                Url = "www.myurl.com"
            });

            //Assert
            Assert.IsNull(result);
        }
コード例 #3
0
        public IActionResult EditPicture(PictureBTO pictureBto)
        {
            int idToReturn = pictureBto.RestaurantId;

            //Check if there is already a profile picture for this restaurant
            if (!ModelState.IsValid)
            {
                return(View(pictureBto));
            }
            if (pictureBto.IsProfilePicture)
            {
                var profilePicture = pictureUC.GetProfilePicture(pictureBto.RestaurantId);
                if (profilePicture != null)
                {
                    ViewData["Error"] = "You can't do that : You already have a profile picture for your restaurant";
                    return(View(pictureBto));
                }
            }

            var result = pictureUC.UpdatePicture(pictureBto);

            if (result == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "We can't update this picture, please contact support" }));
            }
            if (User.IsInRole("Administrators"))
            {
                return(RedirectToAction("GetAllPictures"));
            }
            else
            {
                return(RedirectToAction("GetAllPicturesByRestoId", new { Id = idToReturn }));
            }
        }