Esempio n. 1
0
        public async Task AddPhotosAsync(Guid remarkId, string userId, params File[] photos)
        {
            if (photos == null || !photos.Any())
            {
                throw new ServiceException(OperationCodes.NoFiles,
                                           $"There are no photos to be added to the remark with id: '{remarkId}'.");
            }

            var user = await _userRepository.GetOrFailAsync(userId);

            Logger.Debug($"Adding {photos.Count()} photos to remark with id: '{remarkId}'.");
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            if (remark.Photos.GroupBy(x => x.Size).Count() + photos.Count() > _settings.PhotosLimit)
            {
                throw new ServiceException(OperationCodes.TooManyFiles,
                                           $"There are too many photos ({photos.Count()}) to be added to the remark with id: '{remarkId}'.");
            }
            var tasks = new List <Task>();

            foreach (var photo in photos)
            {
                var task = UploadImagesWithDifferentSizesAsync(remark, RemarkUser.Create(user), photo);
                tasks.Add(task);
            }
            await Task.WhenAll(tasks);

            await _remarkRepository.UpdateAsync(remark);

            Logger.Debug($"Added {photos.Count()} photos to remark with id: '{remarkId}'.");
        }
        protected static void Initialize()
        {
            RemarkRepositoryMock   = new Mock <IRemarkRepository>();
            UserRepositoryMock     = new Mock <IUserRepository>();
            RemarkPhotoServiceMock = new Mock <IRemarkPhotoService>();
            GeneralSettings        = new GeneralSettings
            {
                AllowedDistance = 15.0
            };

            RemarkStateService = new RemarkStateService(RemarkRepositoryMock.Object,
                                                        UserRepositoryMock.Object,
                                                        RemarkPhotoServiceMock.Object,
                                                        GeneralSettings);

            var user     = new User(UserId, "name", "user");
            var category = new Category("category");

            Description = "test";
            Remark      = new Remark(RemarkId, user, category, Location);
            Remark.AddPhoto(RemarkPhoto.Small(Guid.NewGuid(), "test.jpg", "http://my-test-image.com", RemarkUser.Create(user)));

            RemarkRepositoryMock.Setup(x => x.GetByIdAsync(Moq.It.IsAny <Guid>()))
            .ReturnsAsync(Remark);
            UserRepositoryMock.Setup(x => x.GetByUserIdAsync(Moq.It.IsAny <string>()))
            .ReturnsAsync(User);
        }
        protected static void Initialize()
        {
            FileHandlerMock              = new Mock <IFileHandler>();
            RemarkRepositoryMock         = new Mock <IRemarkRepository>();
            RemarkCategoryRepositoryMock = new Mock <ICategoryRepository>();
            TagRepositoryMock            = new Mock <ITagRepository>();
            UserRepositoryMock           = new Mock <IUserRepository>();
            CategoryRepositoryMock       = new Mock <ICategoryRepository>();
            GroupRepositoryMock          = new Mock <IGroupRepository>();
            ImageServiceMock             = new Mock <IImageService>();
            RemarkPhotoServiceMock       = new Mock <IRemarkPhotoService>();
            UniqueNumberGeneratorMock    = new Mock <IUniqueNumberGenerator>();
            GeneralSettings              = new GeneralSettings
            {
                AllowedDistance = 15.0
            };

            RemarkService = new RemarkService(RemarkRepositoryMock.Object,
                                              UserRepositoryMock.Object,
                                              CategoryRepositoryMock.Object,
                                              TagRepositoryMock.Object,
                                              GroupRepositoryMock.Object,
                                              RemarkPhotoServiceMock.Object,
                                              GeneralSettings);

            var user     = new User(UserId, "name", "user");
            var category = new Category("category");

            Remark = new Remark(RemarkId, user, category, Location);
            Remark.AddPhoto(RemarkPhoto.Small(Guid.NewGuid(), "test.jpg", "http://my-test-image.com", RemarkUser.Create(user)));

            RemarkRepositoryMock.Setup(x => x.GetByIdAsync(Moq.It.IsAny <Guid>()))
            .ReturnsAsync(Remark);
            UserRepositoryMock.Setup(x => x.GetByUserIdAsync(Moq.It.IsAny <string>()))
            .ReturnsAsync(User);
            ImageServiceMock.Setup(x => x.ProcessImage(Moq.It.IsAny <File>()))
            .Returns(new Dictionary <string, File>
            {
                { "small", File },
                { "medium", File },
                { "big", File }
            });
        }
Esempio n. 4
0
        public async Task UploadImagesWithDifferentSizesAsync(Remark remark, string userId, File originalPhoto, string metadata = null)
        {
            var user = await _userRepository.GetOrFailAsync(userId);

            await UploadImagesWithDifferentSizesAsync(remark, RemarkUser.Create(user), originalPhoto, metadata);
        }