예제 #1
0
        public void PutPhoto_IfUserPhotosNotContainsPhoto_ShouldReturnNotFoundResult()
        {
            var mockService     = new Mock <IPhotoService>();
            var fakeUserManager = new FakeUserManagerBuilder()
                                  .Build();
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "test1"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim("custom-claim", "example claim value"),
            }, "mock"));

            fakeUserManager.Setup(u => u.FindByNameAsync("test1")).Returns(Task.FromResult(new User  {
                Id = "1", UserName = "******"
            }));
            var controller = new PhotoController(mockService.Object, _mapper, fakeUserManager.Object);
            var context    = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = user
                }
            };

            controller.ControllerContext = context;

            var result = controller.PutPhoto(new Photo()).Result as NotFoundObjectResult;

            Assert.IsInstanceOf <NotFoundObjectResult>(result);
            mockService.Verify(service => service.UpdatePhoto(It.IsAny <Photo>()), Times.Never());
        }
예제 #2
0
        public void Test_DisplayByTitle_Return_Null()
        {
            //This test checks that the PhotoController DisplayByTitle action returns
            //HttpNotFound when you request a title that doesn't exist
            var context = new FakePhotoSharingContext();

            context.Photos = new[] {
                new Photo {
                    PhotoID = 1, Title = "Photo1"
                },
                new Photo {
                    PhotoID = 2, Title = "Photo2"
                },
                new Photo {
                    PhotoID = 3, Title = "Photo3"
                },
                new Photo {
                    PhotoID = 4, Title = "Photo4"
                }
            }.AsQueryable();

            var controller = new PhotoController(context);
            var result     = controller.DisplayByTitle("NonExistentTitle");

            Assert.AreEqual(typeof(HttpNotFoundResult), result.GetType());
        }
예제 #3
0
        public void Test_DisplayByTitle_Return_Photo()
        {
            //This test checks that the PhotoController DisplayByTitle action returns the right photo
            var context = new FakePhotoSharingContext();

            context.Photos = new[] {
                new Photo {
                    PhotoID = 1, Title = "Photo1"
                },
                new Photo {
                    PhotoID = 2, Title = "Photo2"
                },
                new Photo {
                    PhotoID = 3, Title = "Photo3"
                },
                new Photo {
                    PhotoID = 4, Title = "Photo4"
                }
            }.AsQueryable();

            var controller  = new PhotoController(context);
            var result      = controller.DisplayByTitle("Photo2") as ViewResult;
            var resultPhoto = (Photo)result.Model;

            Assert.AreEqual(2, resultPhoto.PhotoID);
        }
예제 #4
0
        public void Test_Index_Return_View()
        {
            var controller = new PhotoController(new FakePhotoSharingContext());
            var view       = controller.Index() as ViewResult;

            Assert.AreEqual(view.ViewName, "Index");
        }
예제 #5
0
        public void Cannot_Edit_Nonexistent_Photo()
        {
            // Организация - создание имитированного хранилища данных
            Mock <IPhotoRepository> mock = new Mock <IPhotoRepository>();

            mock.Setup(m => m.Photos).Returns(new List <Photo>
            {
                new Photo {
                    PhotoId = 1, Name = "Фото1"
                },
                new Photo {
                    PhotoId = 2, Name = "Фото2"
                },
                new Photo {
                    PhotoId = 3, Name = "Фото3"
                },
                new Photo {
                    PhotoId = 4, Name = "Фото4"
                },
                new Photo {
                    PhotoId = 5, Name = "Фото5"
                }
            });

            // Организация - создание контроллера
            PhotoController controller = new PhotoController(mock.Object);

            // Действие
            Photo result = controller.Edit(6).ViewData.Model as Photo;

            // Assert
        }
예제 #6
0
 void InterfacePhotoController.Delete(int id)
 {
     using (var service = new PhotoController())
     {
         service.Delete(id);
     }
 }
예제 #7
0
        public void Can_Retrieve_Image_Data()
        {
            // Организация - создание объекта Photo с данными изображения
            Photo photo = new Photo
            {
                PhotoId       = 2,
                Name          = "Фото2",
                ImageData     = new byte[] { },
                ImageMimeType = "image/png"
            };

            // Организация - создание имитированного хранилища
            Mock <IPhotoRepository> mock = new Mock <IPhotoRepository>();

            mock.Setup(m => m.Photos).Returns(new List <Photo> {
                new Photo {
                    PhotoId = 1, Name = "Фото1"
                },
                photo,
                new Photo {
                    PhotoId = 3, Name = "Фото3"
                }
            }.AsQueryable());

            // Организация - создание контроллера
            PhotoController controller = new PhotoController(mock.Object);

            // Действие - вызов метода действия GetImage()
            ActionResult result = controller.GetImage(2);

            // Утверждение
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(photo.ImageMimeType, ((FileResult)result).ContentType);
        }
예제 #8
0
 public void UpdatePhoto(PhotoModel photo)
 {
     using (var service = new PhotoController())
     {
         service.Update(photo.GetData());
     }
 }
예제 #9
0
 ICollection <PhotoModel> InterfacePhotoController.SearchPhotoByName(string name)
 {
     using (var service = new PhotoController())
     {
         return(service.SearchByName(name).ToList().Select(a => a.GetModel()).ToList());
     }
 }
예제 #10
0
 List <PhotoModel> InterfacePhotoController.GetVideos()
 {
     using (var service = new PhotoController())
     {
         return(service.GetVideos().ToList().Select(a => a.GetModel()).ToList());
     }
 }
예제 #11
0
 PhotoModel InterfacePhotoController.GetPhotoByID(int id)
 {
     using (var service = new PhotoController())
     {
         return(service.GetPhotoById(id).GetModel());
     }
 }
예제 #12
0
 public int CreatePhoto(PhotoModel photo)
 {
     using (var service = new PhotoController())
     {
         return(service.Create(photo.GetData()));
     }
 }
예제 #13
0
        private async Task PersistCustomerPhoto(CustomerPhoto customerPhoto)
        {
            await PhotoController.SaveAsync(customerPhoto);

            _personRegistrationInfo.Photos.Add(customerPhoto);
            this.RefreshList();
        }
예제 #14
0
        public void GetCurrentLoggedUser_ShouldReturnCurrentLoggedUser()
        {
            var mockService     = new Mock <IPhotoService>();
            var fakeUserManager = new FakeUserManagerBuilder()
                                  .Build();
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "test1"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim("custom-claim", "example claim value"),
            }, "mock"));

            fakeUserManager.Setup(u => u.FindByNameAsync("test1")).Returns(Task.FromResult(new User()));
            var controller = new PhotoController(mockService.Object, _mapper, fakeUserManager.Object);
            var context    = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = user
                }
            };

            controller.ControllerContext = context;

            var result = controller.GetCurrentLoggedUser();

            Assert.IsInstanceOf <User>(result.Result);
        }
        public void Test_GetImage_Return_Type()
        {
            var controller = new PhotoController();
            var result     = controller.GetImage(1) as ActionResult;

            Assert.AreEqual(typeof(FileContentResult), result.GetType());
        }
예제 #16
0
 ICollection <PhotoModel> InterfacePhotoController.SearchByLocation(string location)
 {
     using (var service = new PhotoController())
     {
         return(service.SearchByLocation(location).ToList().Select(a => a.GetModel()).ToList());
     }
 }
예제 #17
0
 public int Create(Photos photo)
 {
     using (var service = new PhotoController())
     {
         return(service.Create(photo));
     }
 }
예제 #18
0
 ICollection <PhotoModel> InterfacePhotoController.SearchByCreationDate(string date)
 {
     using (var service = new PhotoController())
     {
         return(service.SearchByCreationDate(date).ToList().Select(a => a.GetModel()).ToList());
     }
 }
예제 #19
0
    private void UpdateText()
    {
        this.SetHidden(false);

        while (this.photos.Count < this.comics.Length)
        {
            PhotoController photo = Instantiate <PhotoController>(this.photoPrefab, this.photoParent);
            this.photos.Add(photo);
        }

        for (int i = 0; i < this.photos.Count; i++)
        {
            PhotoController photo = this.photos[i];

            if (i < this.comics.Length)
            {
                photo.image = Resources.Load <Sprite>("images/" + comics[this.comics.Length - 1 - i].image);
            }
            else
            {
                photo.Hide();
            }
        }

        this.current      = 0;
        this.paper.sprite = Resources.Load <Sprite>(this.paperImage);
        this.text.font    = Resources.Load <Font>(this.font);
    }
        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));
        }
예제 #21
0
        public CreateShould()
        {
            fixture = new SetupFixture();

            env = new Mock <IHostEnvironment>();
            imageUploadWrapper = new Mock <IImageUploadWrapper>();
            env.Setup(m => m.EnvironmentName).Returns("Hosting:UnitTestEnvironment");
            sut = new PhotoController(fixture.Logger.Object,
                                      fixture.repositoryWrapper.Object,
                                      fixture.mapper.Object,
                                      env.Object,
                                      imageUploadWrapper.Object);

            photo = new Photo()
            {
                Id = 1, ImageLink = "dgfdfgdf"
            };
            photoDTO = new PhotoDTO()
            {
                Id = 1, ImageLink = string.Empty, File = It.IsAny <IFormFile>()
            };


            fixture.repositoryWrapper
            .Setup(x => x.Photo.GetPhotoByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(It.IsAny <Photo>);
            fixture.repositoryWrapper.Setup(x => x.Photo.GetAllPhotosAsync()).ReturnsAsync(new List <Photo>()
            {
                photo
            });
            fixture.mapper.Setup(x => x.Map <PhotoDTO>(It.IsAny <Photo>())).Returns(new PhotoDTO());
            imageUploadWrapper.Setup(x => x.Upload(It.IsAny <IFormFile>(), It.IsAny <IHostEnvironment>()))
            .Returns("imageurl");
        }
예제 #22
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));
        }
예제 #23
0
        public void Test_GetImage_Return_Type()
        {
            var context = new FakePhotoSharingContext {
                Photos = new[] {
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    },
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    },
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    },
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    }
                }.AsQueryable()
            };
            var controller = new PhotoController(context);
            var result     = controller.GetImage(1);

            Assert.AreEqual(
                result.GetType(),
                typeof(FileContentResult)
                );
        }
예제 #24
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                throw new ArgumentException("Must have at least one argument for album id");
            }

            try
            {
                var albumId = Convert.ToInt32(args[0]);

                var repo       = new PhotoAlbumRepository("https://jsonplaceholder.typicode.com/photos");
                var controller = new PhotoController(repo);

                var photos = controller.GetPhotosById(albumId).GetAwaiter().GetResult();

                foreach (var photo in photos)
                {
                    Console.WriteLine("[" + photo.Id + "] " + photo.Title);
                }

                Console.ReadLine();
            }
            catch (OverflowException)
            {
                Console.WriteLine("Argument " + args[0] + " must be an integer");
            }
        }
예제 #25
0
        public void Cannot_Save_Invalid_Changes()
        {
            // Организация - создание имитированного хранилища данных
            Mock <IPhotoRepository> mock = new Mock <IPhotoRepository>();

            // Организация - создание контроллера
            PhotoController controller = new PhotoController(mock.Object);

            // Организация - создание объекта Game
            Photo game = new Photo {
                Name = "Test"
            };

            // Организация - добавление ошибки в состояние модели
            controller.ModelState.AddModelError("error", "error");

            // Действие - попытка сохранения товара
            ActionResult result = controller.Edit(photo);

            // Утверждение - проверка того, что обращение к хранилищу НЕ производится
            mock.Verify(m => m.SavePhoto(It.IsAny <Photo>()), Times.Never());

            // Утверждение - проверка типа результата метода
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public void Test_Index_Return_View()
        {
            PhotoController controller = new PhotoController();
            var             result     = controller.Index()  as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
예제 #27
0
        public void Test_GetImage_Return_Type()
        {
            //This test checks that the PhotoController GetImage action returns a FileResult
            var context = new FakePhotoSharingContext();

            context.Photos = new[] {
                new Photo {
                    PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                }
            }.AsQueryable();

            var controller = new PhotoController(context);
            var result     = controller.GetImage(1) as ActionResult;

            Assert.AreEqual(typeof(FileContentResult), result.GetType());
        }
        public void Test_PhotoGallery_Model_Type()
        {
            var controller = new PhotoController();
            var result     = controller._PhotoGallery() as PartialViewResult;

            Assert.AreEqual(typeof(List <Photo>), result.Model.GetType());
        }
예제 #29
0
        public async Task GetReturnsPhotoDataTest()
        {
            var profileId = Guid.NewGuid();
            var photoId   = Guid.NewGuid();
            var buffer    = Model.Create <byte[]>();

            var query = Substitute.For <IPhotoQuery>();

            using (var data = new MemoryStream(buffer))
            {
                var photo = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.Data = data)
                            .Set(x => x.ContentType = "image/jpg");

                using (var tokenSource = new CancellationTokenSource())
                {
                    query.GetPhoto(profileId, photoId, tokenSource.Token).Returns(photo);

                    using (var target = new PhotoController(query))
                    {
                        var actual = await target.Get(profileId, photoId, tokenSource.Token).ConfigureAwait(false);

                        var result = actual.Should().BeOfType <FileStreamResult>().Which;

                        result.FileStream.Should().BeSameAs(data);
                        result.ContentType.Should().Be(photo.ContentType);
                    }
                }
            }
        }
예제 #30
0
        public void RemoveComment_IfPhotoIsNull_ShouldReturnNotFoundResult()
        {
            var mockService     = new Mock <IPhotoService>();
            var fakeUserManager = new FakeUserManagerBuilder()
                                  .Build();
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "test1"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim("custom-claim", "example claim value"),
            }, "mock"));

            fakeUserManager.Setup(u => u.FindByNameAsync("test1")).Returns(Task.FromResult(new User  {
                Id = "1", UserName = "******"
            }));
            var controller = new PhotoController(mockService.Object, _mapper, fakeUserManager.Object);
            var context    = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = user
                }
            };

            controller.ControllerContext = context;

            var result = controller.RemoveComment(1, new Comment {
                Id = 1
            });

            Assert.IsInstanceOf <NotFoundResult>(result);
        }