コード例 #1
0
ファイル: CreateShould.cs プロジェクト: CopperBeardy/SEPUNI
        public void ReturnCreateView()
        {
            var result = sut.CreatePhoto();
            var vr     = Assert.IsType <ViewResult>(result);

            Assert.Equal("CreatePhoto", vr.ViewName);
        }
コード例 #2
0
        public ActionResult Edit([Bind(Include = "ProPhotoId,Title,Description,ProductionsList")] ProductionPhotos productionPhotos, HttpPostedFileBase file)
        {
            int productionID = Convert.ToInt32(Request.Form["ProductionsList"]);


            if (ModelState.IsValid)
            {
                var currentProPhoto = db.ProductionPhotos.Find(productionPhotos.ProPhotoId);
                currentProPhoto.Title       = productionPhotos.Title;
                currentProPhoto.Description = productionPhotos.Description;


                var production = db.Productions.Find(productionID);
                currentProPhoto.Production = production;

                if (file != null && file.ContentLength > 0)
                {
                    currentProPhoto.PhotoId = PhotoController.CreatePhoto(file, currentProPhoto.Title);
                }
                else
                {
                    currentProPhoto.PhotoId = currentProPhoto.PhotoId;
                }

                db.Entry(currentProPhoto.Production).State = EntityState.Modified;
                db.SaveChanges();
                db.Entry(currentProPhoto).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(productionPhotos));
        }
        public ActionResult Create([Bind(Include = "Title,Description")] ProductionPhotos productionPhotos, HttpPostedFileBase file)
        {
            int productionID = Convert.ToInt32(Request.Form["Production"]);

            productionPhotos.PhotoId = PhotoController.CreatePhoto(file, productionPhotos.Title);

            if (ModelState.IsValid)
            {
                Production production = db.Productions.Find(productionID);
                productionPhotos.Production = production;

                if (production.DefaultPhoto == null)
                {
                    production.DefaultPhoto = productionPhotos;
                }

                db.ProductionPhotos.Add(productionPhotos);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewData["Productions"] = new SelectList(db.Productions.ToList(), "ProductionId", "Title");

            return(View(productionPhotos));
        }
コード例 #4
0
        public async Task CreatePhotoExceptionCatch()
        {
            // Arrange
            var id = 45;

            var photo = new Photo()
            {
                Id      = id,
                StateId = 69
            };

            mockRepo.Setup(x => x.Photo).Returns(_photoRepoMock.Object);
            _photoRepoMock.Setup(x => x.CreatePhoto(photo)).Throws(new Exception());

            // Act
            var result = await _sut.CreatePhoto(new PhotoForCreationDto());

            // Assert
            mockLogger.Verify(x => x.LogError("Something went wrong inside CreatePhoto(photoForCreationDto) action: Object reference not set to an instance of an object."), Times.Once);
            Assert.IsType <ObjectResult>(result);
        }
コード例 #5
0
        public void CreatePhoto_Returns201Created_WhenValidObjectSubmitted()
        {
            mockRepo.Setup(repo =>
                           repo.GetPhotosByFamilyMember(1)).Returns(new Photo {
                Id       = 1,
                PhotoUrl = "www.superhero.com/terra-doesnt-remember.jpg"
            });

            var controller = new PhotoController(mockRepo.Object, mapper);

            var result = controller.CreatePhoto(new PhotoCreateDto {
            });

            Assert.IsType <CreatedAtRouteResult>(result.Result);
        }