public void TestDisposesETLComponents() { Mock <IDisposableExtractor <object> > extractorMock = new Mock <IDisposableExtractor <object> >(); Mock <IDisposableTransformer <object, object> > transformerMock = new Mock <IDisposableTransformer <object, object> >(); Mock <IDisposableLoader <object> > loaderMock = new Mock <IDisposableLoader <object> >(); extractorMock.Setup(_ => _.Extract()).Returns(new object()); extractorMock.Setup(_ => _.Dispose()).Verifiable(); transformerMock.Setup(_ => _.Transform(It.IsAny <object>())).Returns(new object()); transformerMock.Setup(_ => _.Dispose()).Verifiable(); loaderMock.Setup(_ => _.Dispose()).Verifiable(); IProcessor processor = new ProcessorBuilder <object>(loaderMock.Object) .AddSource("process", extractorMock.Object, transformerMock.Object) .Build(); processor.Dispose(); extractorMock.Verify(_ => _.Dispose(), Times.Once); transformerMock.Verify(_ => _.Dispose(), Times.Once); loaderMock.Verify(_ => _.Dispose(), Times.Once); }
static async Task Main(string[] args) { if (args.Length < 1) { ShowUsage(); Environment.Exit(1); } var builder = new ProcessorBuilder(); var processor = builder.Build(args); if (processor == null) { ShowUsage(); Environment.Exit(2); } try { await processor.ProcessAsync().ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine($"Error encountered when processing: { ex.Message }"); Environment.Exit(3); } }
public MainForm() { InitializeComponent(); var builder = new ProcessorBuilder(); ConfigureConveyor(builder); _mainProcessor = builder.Build(); }
public void TestWillNoExecuteAnyJobIfNoExtractorIsSpecified() { object data = new object(); Mock <ILoader <object> > loaderMock = new Mock <ILoader <object> >(); IProcessor processor = new ProcessorBuilder <object>(loaderMock.Object).Build(); IEnumerable <Task> tasks = processor.Process(); Task.WaitAll(new List <Task>(tasks).ToArray()); loaderMock.Verify(_ => _.Load(data), Times.Never); }
public void TestResultHasErrorWhenLoaderFails() { string errorMessage = "LoadingException"; string loaderID = "1111...55555"; object data = new object(); Exception exceptionToThrow = new Exception(errorMessage); Mock <IExtractor <object> > extractorMock = new Mock <IExtractor <object> >(); Mock <ITransformer <object, object> > transformerMock = new Mock <ITransformer <object, object> >(); Mock <ILoader <object> > loaderMock = new Mock <ILoader <object> >(); extractorMock.Setup(_ => _.Extract()).Returns(data); transformerMock.Setup(_ => _.Transform(data)).Returns(data); loaderMock.Setup(_ => _.GetID()).Returns(loaderID); loaderMock.Setup(_ => _.Load(data)).Throws(exceptionToThrow); IProcessor processor = new ProcessorBuilder <object>(loaderMock.Object) .AddSource("ProcessWithLoadingError", extractorMock.Object, transformerMock.Object) .Build(); IEnumerable <Task <JobResult> > tasks = processor.Process(); Task.WaitAll(new List <Task>(tasks).ToArray()); IEnumerator <Task <JobResult> > enumerator = tasks.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Task <JobResult> result = enumerator.Current; Assert.IsNotNull(result); Assert.IsTrue(result.IsCompletedSuccessfully); Assert.IsNotNull(result.Result); JobResult jobResult = result.Result; Assert.IsFalse(jobResult.CompletedWithouErrors); Assert.IsNotNull(jobResult.Errors); IEnumerator <JobException> errorsEnumerator = jobResult.Errors.GetEnumerator(); Assert.IsTrue(errorsEnumerator.MoveNext()); JobException jobException = errorsEnumerator.Current; Assert.AreEqual(Phase.LOADING, jobException.JobPhase); Assert.AreEqual(loaderID, jobException.FaillingComponentID); Assert.IsFalse(errorsEnumerator.MoveNext()); Assert.IsFalse(enumerator.MoveNext()); }
public void TestSendResultToMultipleReports() { object o = new object(); Mock <IReport> mockReportOne = new Mock <IReport>(); Mock <IReport> mockReportTwo = new Mock <IReport>(); Mock <IExtractor <object> > mockExtractor = new Mock <IExtractor <object> >(); Mock <ITransformer <object, object> > mockTransformer = new Mock <ITransformer <object, object> >(); Mock <ILoader <object> > mockLoader = new Mock <ILoader <object> >(); mockExtractor.Setup(_ => _.GetID()).Returns("extractor"); mockExtractor.Setup(_ => _.Extract()).Returns(o); mockTransformer.Setup(_ => _.GetID()).Returns("transformer"); mockTransformer.Setup(_ => _.Transform(o)).Returns(o); mockLoader.Setup(_ => _.GetID()).Returns("loader"); ProcessorBuilder <object> builder = new ProcessorBuilder <object>(mockLoader.Object); builder.AddSource("mock processor", mockExtractor.Object, mockTransformer.Object); builder.AddReport(mockReportOne.Object); builder.AddReport(mockReportTwo.Object); IProcessor processor = builder.Build(); IEnumerable <Task <JobResult> > tasks = processor.Process(); Task.WaitAll(new List <Task <JobResult> >(tasks).ToArray()); //Mock one check IInvocationList invocationList = mockReportOne.Invocations; Assert.AreEqual(1, invocationList.Count); IEnumerator <IInvocation> invocationEnumerator = invocationList.GetEnumerator(); invocationEnumerator.MoveNext(); IInvocation invocation = invocationEnumerator.Current; Assert.AreEqual("Report", invocation.Method.Name); //Mock two check invocationList = mockReportTwo.Invocations; Assert.AreEqual(1, invocationList.Count); invocationEnumerator = invocationList.GetEnumerator(); invocationEnumerator.MoveNext(); invocation = invocationEnumerator.Current; Assert.AreEqual("Report", invocation.Method.Name); }
public void TestResultHasErrorWhenExtractorFails() { object data = new object(); string errorMessage = "Expected exception."; string extractorID = "extractor_175"; Exception exceptionToThrow = new Exception(errorMessage); Mock <IExtractor <object> > extractorMock = new Mock <IExtractor <object> >(); Mock <ILoader <object> > loaderMock = new Mock <ILoader <object> >(); extractorMock.Setup(_ => _.Extract()).Throws(exceptionToThrow); extractorMock.Setup(_ => _.GetID()).Returns(extractorID); ProcessorBuilder <object> builder = new ProcessorBuilder <object>(loaderMock.Object); IProcessor faillingProcessor = builder.AddSource("FailingProcessor", extractorMock.Object).Build(); IEnumerable <Task <JobResult> > tasks = faillingProcessor.Process(); Task.WaitAll(new List <Task>(tasks).ToArray()); IEnumerator <Task <JobResult> > enumerator = tasks.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext()); Task <JobResult> result = enumerator.Current; Assert.IsTrue(result.IsCompletedSuccessfully); JobResult jobResult = result.Result; Assert.IsNotNull(jobResult); Assert.IsFalse(jobResult.CompletedWithouErrors); Assert.IsNotNull(jobResult.Errors); IEnumerator <JobException> errorsEnumerator = jobResult.Errors.GetEnumerator(); Assert.IsTrue(errorsEnumerator.MoveNext()); JobException jobException = errorsEnumerator.Current; Assert.AreEqual(Phase.EXTRACTION, jobException.JobPhase); Assert.AreEqual(extractorID, jobException.FaillingComponentID); Assert.IsFalse(errorsEnumerator.MoveNext()); Assert.IsFalse(enumerator.MoveNext()); }
public void TestWillNotReachTransformerIfThereIsAnExtractionError() { Exception expectedException = new Exception("ExtractorError"); Mock <IExtractor <object> > extractorMock = new Mock <IExtractor <object> >(); Mock <ITransformer <object, object> > transfomerMock = new Mock <ITransformer <object, object> >(); Mock <ILoader <object> > loaderMock = new Mock <ILoader <object> >(); IProcessor processor = new ProcessorBuilder <object>(loaderMock.Object) .AddSource("Processor", extractorMock.Object, transfomerMock.Object) .Build(); IEnumerable <Task <JobResult> > tasks = processor.Process(); Task.WaitAll(new List <Task>(tasks).ToArray()); transfomerMock.Verify(_ => _.Transform(new object()), Times.Never); }
public void TestWillDispoeEvenIfLoaderIsNotSpecified() { Mock <IDisposableExtractor <object> > extractorMock = new Mock <IDisposableExtractor <object> >(); Mock <IDisposableTransformer <object, object> > transformerMock = new Mock <IDisposableTransformer <object, object> >(); extractorMock.Setup(_ => _.Extract()).Returns(new object()); transformerMock.Setup(_ => _.Transform(It.IsAny <object>())).Returns(new object()); ICollection <ILoader <object> > loaders = new List <ILoader <object> >(); IProcessor processor = new ProcessorBuilder <object>(loaders) .AddSource("process", extractorMock.Object, transformerMock.Object) .Build(); processor.Dispose(); extractorMock.Verify(_ => _.Dispose(), Times.Once); transformerMock.Verify(_ => _.Dispose(), Times.Once); }
public void TestWilNotReachLoaderIfThereIsTranformationError() { object data = new object(); Mock <IExtractor <object> > extractorMock = new Mock <IExtractor <object> >(); Mock <ITransformer <object, object> > transformerMock = new Mock <ITransformer <object, object> >(); Mock <ILoader <object> > loader = new Mock <ILoader <object> >(); extractorMock.Setup(_ => _.Extract()).Returns(data); transformerMock.Setup(_ => _.Transform(data)).Throws(new Exception()); IProcessor processor = new ProcessorBuilder <object>(loader.Object) .AddSource("processor", extractorMock.Object, transformerMock.Object) .Build(); IEnumerable <Task <JobResult> > tasks = processor.Process(); Task.WaitAll(new List <Task>(tasks).ToArray()); loader.Verify(_ => _.Load(data), Times.Never, "ILoader.Load should not be called"); }
public void TestExtractorsWillNotMessWithAnotherExtractorsData() { object dataA = new SourceModel() { StringData = "string" }; object dataB = new SourceModel() { DecimalData = 33.52m }; object dataC = new SourceModel() { Int32Data = 45, DoubleData = 45.58 }; Mock <IExtractor <object> > extractorBeforeMock = new Mock <IExtractor <object> >(); Mock <IExtractor <object> > extractorLockedMock = new Mock <IExtractor <object> >(); Mock <IExtractor <object> > extractorAfterMock = new Mock <IExtractor <object> >(); Mock <ILoader <object> > loaderMock = new Mock <ILoader <object> >(); extractorBeforeMock.Setup(_ => _.Extract()).Callback(() => Thread.Sleep(3000)).Returns(dataA); extractorLockedMock.Setup(_ => _.Extract()).Returns(dataB); extractorAfterMock.Setup(_ => _.Extract()).Returns(dataC); IProcessor processor = new ProcessorBuilder <object>(loaderMock.Object) .AddSource("Processor before", extractorBeforeMock.Object) .AddSource("Processor locked", extractorLockedMock.Object) .AddSource("Processor after", extractorAfterMock.Object) .Build(); List <Task <JobResult> > tasks = new List <Task <JobResult> >(processor.Process()); Task.WaitAll(tasks.ToArray()); loaderMock.Verify(_ => _.Load(dataA), Times.Once); loaderMock.Verify(_ => _.Load(dataB), Times.Once); loaderMock.Verify(_ => _.Load(dataC), Times.Once); }
public void TestWillNoExecuteAnyJobIfNoLoaderIsSpecified() { object data = new object(); Mock <IExtractor <object> > extractorMock = new Mock <IExtractor <object> >(); Mock <ITransformer <object, object> > transformerMock = new Mock <ITransformer <object, object> >(); ICollection <ILoader <object> > loaders = new List <ILoader <object> >(); extractorMock.Setup(_ => _.Extract()).Returns(data); transformerMock.Setup(_ => _.Transform(data)).Returns(data); IProcessor processor = new ProcessorBuilder <object>(loaders) .AddSource("process", extractorMock.Object, transformerMock.Object) .Build(); IEnumerable <Task> tasks = processor.Process(); Task.WaitAll(new List <Task>(tasks).ToArray()); extractorMock.Verify(_ => _.Extract(), Times.Never); transformerMock.Verify(_ => _.Transform(data), Times.Never); }
public static WindowsImagingProcessorBuilder Image(this ProcessorBuilder builder) { return(new WindowsImagingProcessorBuilder(builder)); }
public ProcessorDirector(ProcessorBuilder builder) { _builder = builder; }
public void TestIndependenJobWillNotCollideWithOtherJobs() { SourceModel independentData = new SourceModel() { DecimalData = 33m, StringData = "independent" }; SourceModel dataA = new SourceModel() { StringData = "dataA" }; SourceModel dataB = new SourceModel() { StringData = "dataB" }; SourceModel dataC = new SourceModel() { StringData = "dataC" }; DestinationModel independentDestinationData = new DestinationModel() { StringData = "independent destination" }; DestinationModel sharedDestinationData = new DestinationModel() { StringData = "Shared destination" }; Mock <IExtractor <SourceModel> > independentExtractorMock = new Mock <IExtractor <SourceModel> >(); Mock <IExtractor <SourceModel> > firstExtractorMock = new Mock <IExtractor <SourceModel> >(); Mock <IExtractor <SourceModel> > secondExtractorMock = new Mock <IExtractor <SourceModel> >(); Mock <IExtractor <SourceModel> > thirdExtractorMock = new Mock <IExtractor <SourceModel> >(); Mock <IExtractor <DestinationModel> > sameTypeIndependentExtractorMock = new Mock <IExtractor <DestinationModel> >(); Mock <ITransformer <SourceModel, DestinationModel> > independentTransformerMock = new Mock <ITransformer <SourceModel, DestinationModel> >(); Mock <ITransformer <SourceModel, DestinationModel> > sharedTransformerMock = new Mock <ITransformer <SourceModel, DestinationModel> >(); Mock <ILoader <DestinationModel> > loaderMock = new Mock <ILoader <DestinationModel> >(); Mock <ILoader <DestinationModel> > independentLoaderMock = new Mock <ILoader <DestinationModel> >(); independentExtractorMock.Setup(_ => _.Extract()).Returns(independentData); firstExtractorMock.Setup(_ => _.Extract()).Returns(dataA); secondExtractorMock.Setup(_ => _.Extract()).Returns(dataB); thirdExtractorMock.Setup(_ => _.Extract()).Returns(dataC); sameTypeIndependentExtractorMock.Setup(_ => _.Extract()).Returns(independentDestinationData); independentTransformerMock.Setup(_ => _.Transform(independentData)).Returns(independentDestinationData); sharedTransformerMock.Setup(_ => _.Transform(It.IsAny <SourceModel>())).Returns(sharedDestinationData); IProcessor processor = new ProcessorBuilder <DestinationModel>(loaderMock.Object) .AddSource("Processor A", firstExtractorMock.Object, sharedTransformerMock.Object) .AddSource("Processor B", secondExtractorMock.Object, sharedTransformerMock.Object) .AddSource("Processor C", thirdExtractorMock.Object, sharedTransformerMock.Object) .AddIndependentJob("Independent processor", independentExtractorMock.Object, independentTransformerMock.Object, independentLoaderMock.Object) .Build(); IEnumerable <Task <JobResult> > tasks = processor.Process(); Task.WaitAll(new List <Task <JobResult> >(tasks).ToArray()); independentTransformerMock.Verify(_ => _.Transform(independentData), Times.Once); independentTransformerMock.Verify(_ => _.Transform(dataA), Times.Never); independentTransformerMock.Verify(_ => _.Transform(dataB), Times.Never); independentTransformerMock.Verify(_ => _.Transform(dataC), Times.Never); independentLoaderMock.Verify(_ => _.Load(independentDestinationData), Times.Once); independentLoaderMock.Verify(_ => _.Load(sharedDestinationData), Times.Never); loaderMock.Verify(_ => _.Load(independentDestinationData), Times.Never); loaderMock.Reset(); independentLoaderMock.Reset(); processor = new ProcessorBuilder <DestinationModel>(loaderMock.Object) .AddIndependentJob("independent process", sameTypeIndependentExtractorMock.Object, independentLoaderMock.Object) .Build(); tasks = processor.Process(); Task.WaitAll(new List <Task <JobResult> >(tasks).ToArray()); independentLoaderMock.Verify(_ => _.Load(independentDestinationData), Times.Once); loaderMock.Verify(_ => _.Load(independentDestinationData), Times.Never); }
static void Main(string[] args) { int pictures = 300; IProcessorBuilder builder = new ProcessorBuilder(); using var file = Image.FromFile(Path.Combine(FullPath, Picture)); var bitmap = new Bitmap(file, new Size(450, 450)); var source = BitmapConverter.ToColorsMatrix(bitmap); bitmap.Dispose(); var picturesWidth = 300; var picturesHeight = 300; var horizontalenergyProcessor = builder .SetDefaultHorizontalConveyor() .SetJpegImageSaver(picturesWidth, picturesHeight) .Build(); builder.Reset(); var energyProcessor = builder .SetDefaultVerticalConveyor() .SetJpegImageSaver(picturesWidth, picturesHeight) .Build(); ProcessingContext context; string filename; string fileDestination; var startTime = DateTime.Now; for (int i = 0; i < pictures; i++) { filename = $"{i}.jpg"; fileDestination = Path.Combine(FullPath, Folder, filename); context = new ProcessingContext { Source = source, DestinationFileName = fileDestination }; if (i % 2 == 0) { energyProcessor.Process(context); } else { horizontalenergyProcessor.Process(context); } source = context.Result; Console.WriteLine($"{filename} was succesfully saved."); } var endTime = DateTime.Now; var difference = endTime - startTime; Console.WriteLine($"Processed in {difference.Minutes} m {difference.Seconds} s."); }