public void FlowElementCached_Process_CheckCachePut()
        {
            // Arrange
            var evidence = new Dictionary <string, object>()
            {
                { "user-agent", "1234" }
            };
            Mock <IFlowData> data       = MockFlowData.CreateFromEvidence(evidence, false);
            EmptyEngineData  aspectData = new EmptyEngineData(
                _loggerFactory.CreateLogger <EmptyEngineData>(),
                data.Object.Pipeline,
                _engine,
                MissingPropertyService.Instance);

            data.Setup(d => d.GetOrAdd(
                           It.IsAny <TypedKey <EmptyEngineData> >(),
                           It.IsAny <Func <IPipeline, EmptyEngineData> >()))
            .Returns(aspectData);

            _cache.Setup(c => c[It.IsAny <IFlowData>()])
            .Returns <IDictionary <string, object> >(null);

            // Act
            _engine.Process(data.Object);

            // Assert
            // Verify that the cache was checked to see if there was an
            // existing result for this key.
            _cache.Verify(c => c[It.Is <IFlowData>(d => d == data.Object)], Times.Once);
            // Verify that the result was added to the cache.
            _cache.Verify(c => c.Put(It.Is <IFlowData>(d => d == data.Object),
                                     It.IsAny <EmptyEngineData>()), Times.Once);
            // Verify the CacheHit flag is false.
            Assert.IsFalse(aspectData.CacheHit);
        }
Esempio n. 2
0
        public void AspectEngineLazyLoad_Process()
        {
            // Arrange
            // Set the process time to half of the configured timeout
            _engine.SetProcessCost(TimeSpan.TicksPerMillisecond * (_timeoutMS / 2));

            // Act
            var evidence = new Dictionary <string, object>()
            {
                { "user-agent", "1234" }
            };
            var mockData = MockFlowData.CreateFromEvidence(evidence, false);
            // Use the mock flow data to populate this variable with the
            // engine data from the call to process.
            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) =>
            {
                engineData = f(mockData.Object.Pipeline);
            })
            .Returns((ITypedKey <EmptyEngineData> k, Func <IPipeline, EmptyEngineData> f) =>
            {
                return(engineData);
            });
            var data = mockData.Object;

            // Process the data.
            _engine.Process(data);
            // Check that the task is not complete when process returns.
            bool processReturnedBeforeTaskComplete =
                engineData.ProcessTask.IsCompleted == false;

            // Assert
            Assert.AreEqual(2, engineData.ValueTwo);
            // Check that the task is now complete (because the code to get
            // the property value will wait until it is complete)
            bool valueReturnedAfterTaskComplete =
                engineData.ProcessTask.IsCompleted == true;

            Assert.IsTrue(processReturnedBeforeTaskComplete);
            Assert.IsTrue(valueReturnedAfterTaskComplete);
        }