Ejemplo n.º 1
0
        public void Convert_test()
        {
            ImgTaskFactoryRegistry.Init(typeof(CoreModule).Assembly);

            var img      = File.OpenRead("img/0.png");
            var expected = File.OpenRead("img/0.converted.jpg");


            var creationParams = new ImgTaskCreationParams()
            {
                TaskName   = "convert",
                TaskParams = new Dictionary <string, string>()
                {
                    { "to", "jpg" }
                },
            };


            var groupId = _editTaskService.CreateEditTask(img, "png", new[] { creationParams });

            Guid taskId = new Guid();

            WaitForTaskProgress(groupId, progressGroup =>
            {
                progressGroup.GroupId.Should().Be(groupId);
                progressGroup.EditTasks.Length.Should().Be(1);
                progressGroup.EditTasks[0].GroupId.Should().Be(groupId);
                taskId = progressGroup.EditTasks[0].TaskId;
                return(progressGroup.EditTasks.Count(progress => progress.ImgTaskState == ImgTaskState.Completed)
                       == progressGroup.EditTasks.Length);
            });

            var result = WaitForTaskResult(groupId, taskId);

            Assert.NotNull(result);

            if (result.ImgStream.Length != expected.Length)
            {
                Assert.False(true);
            }

            while (result.ImgStream.Position < result.ImgStream.Length)
            {
                if (result.ImgStream.ReadByte() != expected.ReadByte())
                {
                    Assert.False(true, "Images aren't the same");
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult <ImgTaskResponseDto> ConvertImage([FromForm][Required] IFormFile img, [ModelBinder(BinderType = typeof(JsonModelBinder))][Required]
                                                              Dictionary <string, string> dict)
        {
            var creationParams = new ImgTaskCreationParams()
            {
                TaskName   = "convert",
                TaskParams = dict
            };

            var progressGroupId = _imgTaskService.CreateEditTask(img.OpenReadStream(), img.GetFileExtension(), new [] { creationParams });

            return(Ok(new ImgTaskResponseDto()
            {
                ProgressGroupId = progressGroupId
            }));
        }
Ejemplo n.º 3
0
        public void CreateEditTask_when_called_sends_valid_msgs()
        {
            ImgTaskFactoryRegistry.Init(typeof(CoreModule).Assembly);

            //mocks
            var imgRepo             = new Mock <IImgRepository>();
            var mqService           = new Mock <IMessageQueueService>();
            var imgTaskProgressRepo = new Mock <IImgTaskProgressRepository>();
            var imgTaskResultRepo   = new Mock <IImgTaskResultRepository>();
            //

            var service         = new ImgTaskService(imgRepo.Object, mqService.Object, imgTaskProgressRepo.Object, imgTaskResultRepo.Object);
            var img             = new MemoryStream(new byte[] { 1, 2, 3 });
            var creationParams1 = new ImgTaskCreationParams()
            {
                TaskName = "convert", TaskParams = new Dictionary <string, string>()
                {
                    { "to", "jpg" }
                }
            };
            var creationParams2 = new ImgTaskCreationParams()
            {
                TaskName   = "convert",
                TaskParams = new Dictionary <string, string>()
                {
                    { "to", "pdf" }
                }
            };

            var progressId = service.CreateEditTask(img, "jpg", new ImgTaskCreationParams[] { creationParams1, creationParams2 });

            imgTaskProgressRepo.Verify(f => f.AddTaskProgress(It.IsAny <ImgTaskProgress>()), Times.Exactly(2));
            mqService.Verify(f => f.QueueTaskAsync(It.IsAny <ImgTask>()), Times.Exactly(2));
            imgRepo.Verify(f => f.AddImg(It.IsAny <Img>()), Times.Once());
            imgTaskResultRepo.Verify(f => f.AddTaskResult(It.Is <ImgTaskResult>(result => result.ImgStream == null)), Times.Exactly(2));
        }