Ejemplo n.º 1
0
        public void GetLastKnownLocationReturnsCorrectPosition()
        {
            int timeToTimeOut = 10000;
            LocationRecorded firstPosition = new LocationRecorded()
            {
                Recorded = DateTimeOffset.UtcNow.AddMilliseconds(-timeToTimeOut)
            };

            LocationRecorded secondPosition = new LocationRecorded()
            {
                Recorded = DateTimeOffset.UtcNow
            };

            LocationRecorded         positionReturned = null;
            Mock <ILocationListener> listener         = new Mock <ILocationListener>();
            TestSchedulers           scheduler        = new TestSchedulers();
            LocationService          service          =
                new LocationService(listener.Object, NullExceptionService, scheduler);

            listener
            .Setup(x => x.PositionChanged())
            .Returns(new[] { firstPosition, secondPosition }.ToObservable());


            service
            .GetLastKnownDeviceLocation(timeToTimeOut - 1, timeToTimeOut)
            .Subscribe(pos => positionReturned = pos);

            // Advance far beyond the necessary time
            scheduler
            .TaskPool
            .AdvanceBy(timeToTimeOut);

            Assert.Equal(secondPosition, positionReturned);
        }
Ejemplo n.º 2
0
        public void PositionDataSetAfterGivenTime()
        {
            LocationRecorded positionExpected = new LocationRecorded();
            LocationRecorded positionReturned = null;
            int timeToTimeOut = 10000;
            Mock <ILocationListener> listener  = new Mock <ILocationListener>();
            TestSchedulers           scheduler = new TestSchedulers();
            LocationService          service   =
                new LocationService(listener.Object, NullExceptionService, scheduler);



            // return data after half of timeout
            listener
            .Setup(x => x.PositionChanged())
            .Returns(
                Observable.Timer(TimeSpan.FromMilliseconds(timeToTimeOut / 2), scheduler.TaskPool)
                .Select(_ => positionExpected)
                );



            service
            .GetDeviceLocation(timeToTimeOut)
            .Subscribe(pos => positionReturned = pos);

            // Advance far beyond the necessary time
            scheduler
            .TaskPool
            .AdvanceBy(TimeSpan.FromMilliseconds(timeToTimeOut * 2).Ticks);

            Assert.Equal(positionExpected, positionReturned);
        }
 void DisplayPosition(LocationRecorded position)
 {
     LocationChanged = $"{position.Recorded} {position.Longitude}, {position.Latitude}";
 }