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 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 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 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); }