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