Beispiel #1
0
        public void AddPhoto_PassValidData_CallsAddAndSaves()
        {
            var photoBll   = new UserPhotoBLL();
            var unitOfWork = new Mock <IPhotoUnitOfWork>();

            var userProfile = new UserProfile
            {
                Photos = new List <UserPhoto> {
                    new UserPhoto()
                }
            };

            unitOfWork.Setup(u => u.UserRepository.Get(It.IsAny <string>()))
            .Returns(userProfile);
            unitOfWork.Setup(u => u.UserRepository.Find(It.IsAny <Expression <Func <UserProfile, bool> > >()))
            .Returns(new List <UserProfile> {
                new UserProfile()
            });
            unitOfWork.Setup(u => u.Photos.Add(It.IsAny <UserPhoto>()))
            .Callback <UserPhoto>(t => userProfile.Photos.Add(t));


            // Act

            var photoService = new PhotoService(unitOfWork.Object);

            photoService.AddPhoto(photoBll);

            // Assert

            unitOfWork.Verify(u => u.Photos.Add(It.IsAny <UserPhoto>()), Times.Once());
            unitOfWork.Verify(u => u.SaveAsync(), Times.Once());
            Assert.IsTrue(userProfile.Photos.Count == 2);
        }
Beispiel #2
0
        public void RemoveAll(UserPhotoBLL userPhotoBll)
        {
            var photos   = _db.Photos.Find(p => p.Id == userPhotoBll.Id);
            var likes    = _db.Likes.Find(p => p.Photo.Id == userPhotoBll.Id);
            var comments = _db.Comments.Find(p => p.Photo.Id == userPhotoBll.Id);

            _db.Comments.RemoveRange(comments);
            _db.Likes.RemoveRange(likes);
            _db.Photos.RemoveRange(photos);
        }
Beispiel #3
0
        public void RemovePhoto(UserPhotoBLL userPhotoBll)
        {
            if (userPhotoBll == null)
            {
                throw new ArgumentNullException("Object cannot be null");
            }
            var photo    = _db.Photos.Find(p => p.Id == userPhotoBll.Id).Single();
            var likes    = _db.Likes.Find(p => p.Photo.Id == userPhotoBll.Id);
            var comments = _db.Comments.Find(p => p.Photo.Id == userPhotoBll.Id);

            _db.Comments.RemoveRange(comments);
            _db.Likes.RemoveRange(likes);
            _db.Photos.Remove(photo);
            _db.Save();
        }
Beispiel #4
0
        public void EditPhoto(UserPhotoBLL userPhotoBll)
        {
            if (userPhotoBll == null)
            {
                throw new ArgumentNullException("Object cannot be null");
            }

            var photo = _db.Photos.Find(p => p.Id == userPhotoBll.Id).Single();

            photo.Id          = userPhotoBll.Id;
            photo.IsAvatar    = userPhotoBll.IsAvatar;
            photo.IsBlocked   = userPhotoBll.IsBlocked;
            photo.Description = userPhotoBll.Description;

            _db.Photos.Update(photo);
            _db.Save();
        }
Beispiel #5
0
        public void AddPhoto(UserPhotoBLL userPhotoBll)
        {
            if (userPhotoBll == null)
            {
                throw new ArgumentNullException("Object cannot be null");
            }
            _db.Photos.Add(new UserPhoto()
            {
                Id           = Guid.NewGuid().ToString(),
                PhotoAddress = userPhotoBll.PhotoAddress,
                IsBlocked    = userPhotoBll.IsBlocked,
                User         = _db.UserRepository.Find(p => p.Id == userPhotoBll.UserId).Single(),
                Description  = userPhotoBll.Description,
                Date         = DateTime.Now
            });

            _db.SaveAsync();
        }