public void JsonBuilder_LazyLoading() { var engine = new EmptyEngineBuilder(_loggerFactory) .SetLazyLoadingTimeout(1000) .SetProcessCost(TimeSpan.FromMilliseconds(500).Ticks) .Build(); var jsonBuilder = new JsonBuilderElementBuilder(_loggerFactory) .Build(); var sequenceElement = new SequenceElementBuilder(_loggerFactory) .Build(); var pipeline = new PipelineBuilder(_loggerFactory) .AddFlowElement(sequenceElement) .AddFlowElement(engine) .AddFlowElement(jsonBuilder) .Build(); var flowData = pipeline.CreateFlowData(); Trace.WriteLine("Process starting"); flowData.Process(); Trace.WriteLine("Process complete"); var jsonResult = flowData.Get <IJsonBuilderElementData>(); Assert.IsNotNull(jsonResult); Assert.IsNotNull(jsonResult.Json); var jsonData = JsonConvert.DeserializeObject <JsonData>(jsonResult.Json); Assert.AreEqual(1, jsonData.EmptyAspect.Valueone); Assert.AreEqual(2, jsonData.EmptyAspect.Valuetwo); Trace.WriteLine("Data validated"); }
public void AspectEngineLazyLoad_ProcessMultipleErrored() { // Arrange // Set the engine to throw an exception while processing var exceptionMessage = "an exception message"; var engine2 = new EmptyEngineBuilder(_loggerFactory) .SetLazyLoading(new LazyLoadingConfiguration(_timeoutMS, _cancellationTokenSource.Token)) .Build(); _engine.SetException(new Exception(exceptionMessage)); engine2.SetException(new Exception(exceptionMessage)); // Act var evidence = new Dictionary <string, object>() { { "user-agent", "1234" } }; // Use the mock flow data to populate this variable with the // engine data from the call to process. var mockData = MockFlowData.CreateFromEvidence(evidence, false); EmptyEngineData engineData = null; mockData.Setup(d => d.GetOrAdd(It.IsAny <ITypedKey <EmptyEngineData> >(), It.IsAny <Func <IPipeline, EmptyEngineData> >())) .Callback((ITypedKey <EmptyEngineData> k, Func <IPipeline, EmptyEngineData> f) => { if (engineData == null) { engineData = f(mockData.Object.Pipeline); } }) .Returns((ITypedKey <EmptyEngineData> k, Func <IPipeline, EmptyEngineData> f) => { return(engineData); }); var data = mockData.Object; // Process the data twice _engine.Process(data); engine2.Process(data); // Attempt to get the value. try { var result = engineData.ValueOne; } catch (Exception e) { Assert.IsTrue(e is AggregateException); Assert.IsNotNull(((AggregateException)e).InnerExceptions); Assert.AreEqual(2, ((AggregateException)e).InnerExceptions.Count); Assert.AreEqual( $"One or more errors occurred. ({exceptionMessage})", ((AggregateException)e).InnerExceptions[0].Message); Assert.AreEqual( $"One or more errors occurred. ({exceptionMessage})", ((AggregateException)e).InnerExceptions[1].Message); } }
private void BuildEngine(bool lazyLoading) { var builder = new EmptyEngineBuilder(_loggerFactory); if (lazyLoading) { builder.SetLazyLoading(new LazyLoadingConfiguration(_timeoutMS, _cancellationTokenSource.Token)); } _engine = builder.Build(); _pipeline = new PipelineBuilder(_loggerFactory) .AddFlowElement(_engine) .Build(); }