Esempio n. 1
0
        public void Initialize()
        {
            _request       = ImageRequestBuilder.NewBuilderWithSource(new Uri("http://request")).Build();
            _callerContext = new object();
            _error         = new Exception();
            _immutableMap  = new Dictionary <string, string>();

            ProducerListenerImpl producerListener1 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls1; },
                (_, __, ___) => { ++_onProducerEventFuncCalls1; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls1; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls1; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls1; },
                (_) => { ++_requiresExtraMapFuncCalls1; return(false); });

            ProducerListenerImpl producerListener2 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls2; },
                (_, __, ___) => { ++_onProducerEventFuncCalls2; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls2; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls2; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls2; },
                (_) => { ++_requiresExtraMapFuncCalls2; return(false); });

            ProducerListenerImpl producerListener3 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls3; },
                (_, __, ___) => { ++_onProducerEventFuncCalls3; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls3; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls3; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls3; },
                (_) => { ++_requiresExtraMapFuncCalls3; return(false); });

            _requestListener1 = new RequestListenerImpl(
                producerListener1,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls1; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall1; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls1; },
                (_) => { ++_onRequestCancellationFuncCalls1; });

            _requestListener2 = new RequestListenerImpl(
                producerListener2,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls2; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall2; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls2; },
                (_) => { ++_onRequestCancellationFuncCalls2; });

            _requestListener3 = new RequestListenerImpl(
                producerListener3,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls3; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall3; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls3; },
                (_) => { ++_onRequestCancellationFuncCalls3; });

            _listenerManager = new ForwardingRequestListener(new HashSet <IRequestListener>
            {
                _requestListener1,
                _requestListener2,
                _requestListener3
            });
        }
Esempio n. 2
0
 /// <summary>
 /// Instantiates the <see cref="RequestListenerImpl"/>.
 /// </summary>
 public RequestListenerImpl(
     ProducerListenerImpl producerListener,
     Action <ImageRequest, object, string, bool> onRequestStartFunc,
     Action <ImageRequest, string, bool> onRequestSuccessFunc,
     Action <ImageRequest, string, Exception, bool> onRequestFailureFunc,
     Action <string> onRequestCancellationFunc)
 {
     _producerListener          = producerListener;
     _onRequestStartFunc        = onRequestStartFunc;
     _onRequestSuccessFunc      = onRequestSuccessFunc;
     _onRequestFailureFunc      = onRequestFailureFunc;
     _onRequestCancellationFunc = onRequestCancellationFunc;
 }
Esempio n. 3
0
        public void Initialize()
        {
            // Initializes the mock producer listener
            ProducerListenerImpl producerListener = new ProducerListenerImpl(
                (_, __) => { },
                (_, __, ___) => { },
                (_, __, ___) => { },
                (_, __, ___, ____) => { },
                (_, __, ___) => { },
                (_) =>
            {
                return(false);
            });

            // Initializes the mock producer context callbacks
            _callbacks1 = new BaseProducerContextCallbacks(
                () =>
            {
                ++_onCancellationRequestedCount1;
            },
                () =>
            {
                ++_onIsPrefetchChangedCount1;
            },
                () =>
            {
                ++_onIsIntermediateResultExpectedChangedCount1;
            },
                () =>
            {
                ++_onPriorityChangedCount1;
            });

            _callbacks2 = new BaseProducerContextCallbacks(
                () =>
            {
                ++_onCancellationRequestedCount2;
            },
                () =>
            {
                ++_onIsPrefetchChangedCount2;
            },
                () =>
            {
                ++_onIsIntermediateResultExpectedChangedCount2;
            },
                () =>
            {
                ++_onPriorityChangedCount2;
            });

            _settableProducerContext = new SettableProducerContext(
                IMAGE_REQUEST,
                REQUEST_ID,
                producerListener,
                new object(),
                RequestLevel.FULL_FETCH,
                false,
                true,
                Priority.MEDIUM);
        }
Esempio n. 4
0
        public void Initialize()
        {
            // Initializes the mock RequestListener
            ProducerListenerImpl producerListener = new ProducerListenerImpl(
                (_, __) => { },
                (_, __, ___) => { },
                (_, __, ___) => { },
                (_, __, ___, ____) => { },
                (_, __, ___) => { },
                (_) => { return(false); });

            _requestListener = new RequestListenerImpl(
                producerListener,
                (imageRequest, callerContext, requestId, isPrefetch) =>
            {
                _onRequestStartInvocation = true;
                _internalImageRequest     = imageRequest;
                _internalCallerContext    = callerContext;
                _internalRequestId        = requestId;
                _internalIsPrefetch       = isPrefetch;
            },
                (imageRequest, requestId, isPrefetch) =>
            {
                _onRequestSuccessInvocation = true;
                _internalImageRequest       = imageRequest;
                _internalRequestId          = requestId;
                _internalIsPrefetch         = isPrefetch;
            },
                (imageRequest, requestId, exception, isPrefetch) =>
            {
                _onRequestFailureInvocation = true;
                _internalImageRequest       = imageRequest;
                _internalRequestId          = requestId;
                _internalException          = exception;
                _internalIsPrefetch         = isPrefetch;
            },
                (requestId) =>
            {
                _onRequestCancellationInvocation = true;
                _internalRequestId = requestId;
            });
            _resourceReleaser = new ResourceReleaserImpl <object>(_ => { });
            _resultRef1       = CloseableReference <object> .of(new object(), _resourceReleaser);

            _resultRef2 = CloseableReference <object> .of(new object(), _resourceReleaser);

            _resultRef3 = CloseableReference <object> .of(new object(), _resourceReleaser);

            _dataSubscriber1 = new MockDataSubscriber <CloseableReference <object> >();
            _dataSubscriber2 = new MockDataSubscriber <CloseableReference <object> >();

            _internalIsPrefetch      = true;
            _settableProducerContext = new SettableProducerContext(
                IMAGE_REQUEST,
                REQUEST_ID,
                producerListener,
                CALLER_CONTEXT,
                RequestLevel.FULL_FETCH,
                IS_PREFETCH,
                true,
                Priority.HIGH);
            _producer = new ProducerImpl <CloseableReference <object> >(
                (consumer, _) =>
            {
                _internalConsumer = consumer;
            });
            _dataSource = CloseableProducerToDataSourceAdapter <object> .Create(
                _producer,
                _settableProducerContext,
                _requestListener);

            Assert.IsTrue(_onRequestStartInvocation);
            Assert.AreSame(_internalImageRequest, IMAGE_REQUEST);
            Assert.AreSame(_internalCallerContext, CALLER_CONTEXT);
            Assert.AreSame(_internalRequestId, REQUEST_ID);
            Assert.IsFalse(_internalIsPrefetch);
            Assert.IsNotNull(_internalConsumer);
            _onRequestStartInvocation = false;

            _dataSource.Subscribe(_dataSubscriber1, CallerThreadExecutor.Instance);
        }