Ejemplo n.º 1
0
        public void CanUploadPendingEnvelopesWhenConnectionIsAvailable()
        {
            //Given                        
            connectivityMonitor.Setup(c => c.IsNetworkAvailable())
                .Returns(true);

            var networkAwareService = new NetworkAwareSyncService<object>(connectivityMonitor.Object);

            var eventRecorder = new EventRecorder( 
                typeof(SyncUpdateEvent<object>),
                typeof(SyncUpdateEvent<object>),
                typeof(SyncCompletedEvent<object>));
            
            networkAwareService.StatusUpdate += (e) => { eventRecorder.ActualTypes.Add(e.GetType()); };

            var dummyWork = new List<object>() { "one", "two" };

            //When
            networkAwareService.Process(dummyWork, (o, i) => Console.WriteLine(o));

            //Then
            eventRecorder.IsSatisfied();
        }
Ejemplo n.º 2
0
        public void CanResumeProcessingWhenNetworkBecomesAvailable()
        {
            //Given                        
            connectivityMonitor.SetupSequence(c => c.IsNetworkAvailable())
                .Returns(true)
                .Returns(false) // Returns false after network error leading to SyncPausedEvent
                .Returns(true) 
                .Returns(true);

            var networkAwareService = new NetworkAwareSyncService<string>(connectivityMonitor.Object);

            var eventRecorder = new EventRecorder(
                typeof(SyncUpdateEvent<string>),
                typeof(SyncUpdateEvent<string>),
                typeof(SyncPausedEvent<string>),
                typeof(SyncUpdateEvent<string>),
                typeof(SyncCompletedEvent<string>));

            networkAwareService.StatusUpdate += (e) => { eventRecorder.ActualTypes.Add(e.GetType()); };
            
            var dummyWork = new List<string>(){ "one", "two" };

            bool thrown = false;

            //When
            networkAwareService.Process(dummyWork, (o, i) =>
            {
                if (i == 1 && !thrown)
                {
                    thrown = true; 
                    throw new WebException("simulate a network error on processing second item");
                }
            });

            //Then
            eventRecorder.IsSatisfied();
        }