public void get_all_photos() { var photos = PhotoService.GetAll(); Assert.IsNotNull(photos); Assert.IsTrue(photos.Any()); }
public void Get_All_Photos_Count() { var tableRepository = new TableRepository(); var blobRepository = new BlobRepository(); var visionService = new VisionService(); var photoService = new PhotoService(tableRepository, blobRepository, visionService); var photos = photoService.GetAll(); Assert.IsTrue(photos.Count > 0); }
public HttpResponseMessage GetAll([FromUri] int PageNumber = 0, [FromUri] int PageSize = 10) { ResponseProperties properties = new ResponseProperties() { pageNumber = PageNumber, pageSize = PageSize }; List <Photo> photos = _service.GetAll(properties); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, photos); return(response); }
public void GetAllPhotosFromDbSetWrapper() { // Arrange var dbSetWrapperMock = new Mock <IEfDbSetWrapper <Photo> >(); IQueryable <Photo> expectedPhotos = new List <Photo>() { new Photo(), new Photo() }.AsQueryable(); dbSetWrapperMock.Setup(x => x.All).Returns(expectedPhotos); PhotoService service = new PhotoService(dbSetWrapperMock.Object); // Act IQueryable <Photo> actualPhotos = service.GetAll(); // Assert CollectionAssert.AreEquivalent(expectedPhotos, actualPhotos); }
public void Test_PhotoService() { var tableRepository = new TableRepository(); var blobRepository = new BlobRepository(); var visionService = new VisionService(); var photoService = new PhotoService(tableRepository, blobRepository, visionService); //Photo const string fileName = @"Desert.jpg"; var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Images\\{fileName}"); if (!File.Exists(filePath)) { throw new ArgumentNullException(nameof(filePath)); } //Photo Entity var partitionKey = Guid.NewGuid(); var entity = new PhotoEntity(partitionKey.ToString(), Rowkey) { ID = partitionKey, Title = "Desert", Owner = Owner, }; using (Stream file = File.OpenRead(filePath)) { photoService.Create(entity, file); } var photos = photoService.GetAll(); Assert.IsNotNull(photos); Assert.IsTrue(photos.Count > 0); var singleOrDefault = photos.SingleOrDefault(p => p.ID.Equals(entity.ID)); Assert.IsNotNull(singleOrDefault); Assert.AreEqual("Desert", singleOrDefault.Title); }
public async Task <IActionResult> SetMainPhoto(int userId, int id) { try { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var photoFromRepo = await _photoService.GetAsync(id); if (photoFromRepo == null) { return(NotFound()); } if (photoFromRepo.IsMain) { return(BadRequest("This photo is already main photo")); } var userMainPhoto = _photoService.GetAll().Where(x => x.UserId == userId).FirstOrDefault(x => x.IsMain == true && !x.IsDelete); if (userMainPhoto == null) { userMainPhoto.IsMain = false; } photoFromRepo.IsMain = true; await _photoService.SaveAsync(); return(NoContent()); } catch (System.Exception ex) { return(BadRequest("Could not set the main photo, error is :" + ex)); } }
// GET: Photos public ActionResult Index() { var photos = _photoService.GetAll(User.Identity.GetUserId()); return(View(photos)); }