Exemple #1
0
        public void CanUploadImage_should_throw_exception_if_name_not_valid()
        {
            var command = new UploadAppImage();

            ValidationAssert.Throws(() => GuardApp.CanUploadImage(command),
                                    new ValidationError("File is required.", "File"));
        }
Exemple #2
0
        public void CanUploadImage_should_not_throw_exception_if_app_name_is_valid()
        {
            var command = new UploadAppImage {
                File = new AssetFile("file.png", "image/png", 100, () => new MemoryStream())
            };

            GuardApp.CanUploadImage(command);
        }
Exemple #3
0
        public void CanUploadImage_should_not_throw_exception_if_app_name_is_valid()
        {
            var command = new UploadAppImage {
                File = new NoopAssetFile()
            };

            GuardApp.CanUploadImage(command);
        }
Exemple #4
0
        public static void CanUploadImage(UploadAppImage command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(e =>
            {
                if (command.File == null)
                {
                    e(Not.Defined(nameof(command.File)), nameof(command.File));
                }
            });
        }
Exemple #5
0
        public static void CanUploadImage(UploadAppImage command)
        {
            Guard.NotNull(command);

            Validate.It(() => "Cannot upload image.", e =>
            {
                if (command.File == null)
                {
                    e(Not.Defined("File"), nameof(command.File));
                }
            });
        }
Exemple #6
0
        private async Task UploadAsync(UploadAppImage uploadImage)
        {
            var file = uploadImage.File;

            var image = await assetThumbnailGenerator.GetImageInfoAsync(file.OpenRead());

            if (image == null)
            {
                throw new ValidationException("File is not an image.");
            }

            await assetStore.UploadAsync(uploadImage.AppId.ToString(), file.OpenRead(), true);
        }
Exemple #7
0
        private async Task UploadAsync(UploadAppImage uploadImage)
        {
            var file = uploadImage.File;

            using (var uploadStream = file.OpenRead())
            {
                var image = await assetThumbnailGenerator.GetImageInfoAsync(uploadStream);

                if (image == null)
                {
                    throw new ValidationException(T.Get("apps.notImage"));
                }
            }

            using (var uploadStream = file.OpenRead())
            {
                await appImageStore.UploadAsync(uploadImage.AppId.Id, uploadStream);
            }
        }
        public async Task UploadImage_should_create_events_and_update_state()
        {
            var command = new UploadAppImage {
                File = new AssetFile("image.png", "image/png", 100, () => new MemoryStream())
            };

            await ExecuteCreateAsync();

            var result = await sut.ExecuteAsync(CreateCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal("image/png", sut.Snapshot.Image !.MimeType);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new AppImageUploaded {
                Image = sut.Snapshot.Image
            })
                );
        }
        public async Task UploadImage_should_create_events_and_update_image()
        {
            var command = new UploadAppImage {
                File = new NoopAssetFile()
            };

            await ExecuteCreateAsync();

            var result = await PublishAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal("image/png", sut.Snapshot.Image !.MimeType);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new AppImageUploaded {
                Image = sut.Snapshot.Image
            })
                );
        }
 private void UploadImage(UploadAppImage command)
 {
     Raise(command, new AppImageUploaded {
         Image = new AppImage(command.File.MimeType)
     });
 }
Exemple #11
0
 public void UploadImage(UploadAppImage command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AppImageUploaded {
         Image = new AppImage(command.File.MimeType)
     }));
 }
Exemple #12
0
 public static void CanUploadImage(UploadAppImage command)
 {
     Guard.NotNull(command, nameof(command));
 }
Exemple #13
0
 public void UploadImage(UploadAppImage command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AppImageUploaded()));
 }