public void ProcessTask_sends_valid_msgs_to_other_objects() { ImgTaskFactoryRegistry.Init(typeof(ConvertTaskConsumer_Tests).Assembly); var stubImg = new MemoryStream(new byte[] { 1, 2, 3 }); var convertTask = (TestConvertTask)ImgTaskFactoryRegistry.GetImgTask(Guid.NewGuid(), Guid.NewGuid(), "testConvert", new Dictionary <string, string>() { { "to", "pdf" } }); var expectedTaskResult = new ImgTaskResult(convertTask.TaskId, convertTask.GroupId, stubImg, "png"); var resultRepo = new Mock <IImgTaskResultRepository>(); var imgRepo = new Mock <IImgRepository>(); imgRepo.Setup(f => f.GetImg(convertTask.ImgId)).Returns(new Img(convertTask.ImgId, stubImg, "png")); var progressRepo = new Mock <IImgTaskProgressRepository>(); var consumer = new ConvertTaskConsumer(resultRepo.Object, progressRepo.Object, imgRepo.Object); consumer.ProcessTask(convertTask); resultRepo.Verify(f => f.AddTaskResult(It.Is <ImgTaskResult>(result => result.TaskId == expectedTaskResult.TaskId && result.GroupId == expectedTaskResult.GroupId)), Times.Never()); resultRepo.Verify(f => f.UpdateTaskResult(It.Is <ImgTaskResult>(result => result.TaskId == expectedTaskResult.TaskId && result.GroupId == expectedTaskResult.GroupId)), Times.Once()); }
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"); } } }
protected override void Load(ContainerBuilder builder) { RegisterDbModule(builder); RegisterBusModule(builder); builder.RegisterAssemblyTypes(typeof(CoreModule).Assembly) .Where(t => t.Name.EndsWith("Repository")) .AsImplementedInterfaces(); builder.RegisterAssemblyTypes(typeof(CoreModule).Assembly) .Where(t => t.Name.EndsWith("Service")) .WithNonPublicCtors().InstancePerLifetimeScope(); builder.RegisterAssemblyTypes(typeof(CoreModule).Assembly) .Where(t => t.Name.EndsWith("Service")) .WithNonPublicCtors().AsImplementedInterfaces(); // builder.RegisterType<ImgTaskService>().WithNonPublicCtors().InstancePerLifetimeScope(); // builder.RegisterType<ImgTaskProgressService>().WithNonPublicCtors().InstancePerLifetimeScope(); // builder.RegisterType<MassTransitMqService>().WithNonPublicCtors().As<IMessageQueueService>() // .InstancePerLifetimeScope(); ImgTaskFactoryRegistry.Init(typeof(ImgTaskFactoryRegistry).Assembly); builder.AddAutoMapper(typeof(CoreModule).Assembly); }
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)); }