Inheritance: WebServiceResult
        public void ShouldStopTimerIfGetStructureAndDeviceStatusFails()
        {
            var expectedResult = new GetStatusResult(WebServiceError.Unknown, new Exception());
            _mockWebService.Setup(w => w.GetStructureAndDeviceStatusAsync(It.IsAny<Structure>())).Returns(Task.FromResult(expectedResult));

            _timerCallback(null);

            _mockTimer.Verify(t => t.Change(Timeout.Infinite, Timeout.Infinite));
        }
        public void ShouldCacheStatusOnTimerTick()
        {
            var expectedResult = new GetStatusResult(new[] { new Structure("") });
            _mockWebService.Setup(w => w.GetStructureAndDeviceStatusAsync(It.IsAny<Structure>())).Returns(Task.FromResult(expectedResult));

            _timerCallback(null);

            _mockStatusProvider.Verify(s => s.CacheStatus(expectedResult));
        }
Esempio n. 3
0
        private async Task UpdateStatusAsync(Structure structure)
        {
            GetStatusResult result = await _nestWebService.GetStructureAndDeviceStatusAsync(structure);

            if (result.Exception != null)
            {
                Stop();
            }

            _delayedStatusProvider.CacheStatus(result);
        }
Esempio n. 4
0
			public void ShouldUpdateTargetTemperature() {
				var structure = new Structure("");
				var thermostat = new Thermostat("") {TargetTemperature = 48d};
				structure.Thermostats.Add(thermostat);
				var status = new GetStatusResult(new[] {structure});
				thermostat.TargetTemperature = 48d;

				_statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status));

				Assert.AreEqual(thermostat.TargetTemperature, _viewModel.TargetTemperature, "Expected TargetTemperature to update from status change.");
			}
        private void OnDisplayCachedStatusTick(object state)
        {
            try {
                Deployment.Current.Dispatcher.InvokeAsync(() => {
                    GetStatusResult cachedStatus = _cachedStatusResult;
                    if (cachedStatus != null) {

                        if (StatusUpdated != null)
                            StatusUpdated(this, new StatusEventArgs(cachedStatus));

                        _cachedStatusResult = null;
                    }
                });
            }
            catch (NullReferenceException) {}
        }
        public void SetUp()
        {
            _mockTimer = new Mock<ITimer>();
            _mockStatusProvider = new Mock<IStatusProvider>();
            _mockWebService = new Mock<INestWebService>();

            ServiceContainer.RegisterService<ITimer>(_mockTimer.Object);
            ServiceContainer.RegisterService<INestWebService>(_mockWebService.Object);
            ServiceContainer.RegisterService<IStatusProvider>(_mockStatusProvider.Object);

            _mockWebService.Setup(w => w.GetThermostatStatusAsync(It.IsAny<Thermostat>())).Returns(Task.FromResult(new GetThermostatStatusResult(new Thermostat(""))));
            _mockWebService.Setup(w => w.GetStructureAndDeviceStatusAsync(It.IsAny<Structure>())).Returns(Task.FromResult(new GetStatusResult(new[] { new Structure("") })));
            _mockTimer.Setup(t => t.SetCallback(It.IsAny<TimerCallback>())).Callback<TimerCallback>(c => _timerCallback = c);
            _mockStatusProvider.Setup(s => s.CacheStatus(It.IsAny<GetStatusResult>())).Callback<GetStatusResult>(g => _cachedStatusResult = g);

            _updaterService = new StatusUpdaterService();
        }
Esempio n. 7
0
        private void OnDisplayCachedStatusTick(object state)
        {
            try {
                Deployment.Current.Dispatcher.InvokeAsync(() => {
                    GetStatusResult cachedStatus = _cachedStatusResult;
                    if (cachedStatus != null)
                    {
                        if (StatusUpdated != null)
                        {
                            StatusUpdated(this, new StatusEventArgs(cachedStatus));
                        }

                        _cachedStatusResult = null;
                    }
                });
            }
            catch (NullReferenceException) {}
        }
Esempio n. 8
0
 private void Reset()
 {
     _cachedStatusResult = null;
 }
Esempio n. 9
0
 public void CacheStatus(GetStatusResult status)
 {
     _cachedStatusResult = status;
 }
Esempio n. 10
0
 public StatusEventArgs(GetStatusResult status)
 {
     Status = status;
 }
Esempio n. 11
0
 private void Reset()
 {
     _cachedStatusResult = null;
 }
Esempio n. 12
0
			public void ShouldUpdateHvacMode() {
				var structure = new Structure("");
				var thermostat = new Thermostat(""){HvacMode = HvacMode.HeatAndCool};
				structure.Thermostats.Add(thermostat);
				var status = new GetStatusResult(new[] {structure});

				_statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status));

				Assert.AreEqual(thermostat.HvacMode, _viewModel.HvacMode, "Expected HvacMode to update from status change.");
			}
Esempio n. 13
0
 public void CacheStatus(GetStatusResult status)
 {
     _cachedStatusResult = status;
 }
Esempio n. 14
0
			public void ShouldUpdateIsLeafOn() {
				var structure = new Structure("");
				var thermostat = new Thermostat("") {IsLeafOn = true};
				structure.Thermostats.Add(thermostat);
				var status = new GetStatusResult(new[] {structure});

				_statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status));

				Assert.AreEqual(thermostat.IsLeafOn, _viewModel.IsLeafOn, "Expected IsLeafOn to update from status change.");
			}
Esempio n. 15
0
			public void ShouldBeLoggingInOnInvalidCredentialsException() {
				var result = new GetStatusResult(WebServiceError.InvalidCredentials, new Exception());
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				Assert.AreEqual(_viewModel.State, NestViewModelState.LoggingIn);
			}
Esempio n. 16
0
			public void ShouldClearSessionOnInvalidCredentialsException() {
				var result = new GetStatusResult(WebServiceError.InvalidCredentials, new Exception());
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				_sessionProvider.Verify(provider => provider.ClearSession(), "Expected session to be cleared when an InvalidCredentials exception occurs.");
			}
Esempio n. 17
0
		private async Task OnLoggedIn() {
			State = NestViewModelState.Loading;

			var result = await _nestWebService.UpdateTransportUrlAsync();
			if (IsErrorHandled(result.Error, result.Exception))
				return;

			_getStatusResult = await _nestWebService.GetFullStatusAsync();
			if (IsErrorHandled(_getStatusResult.Error, _getStatusResult.Exception))
				return;

			State = NestViewModelState.LoggedIn;

			UpdateViewModelFromGetStatusResult(_getStatusResult);

			_statusUpdater.CurrentStructure = _getStatusResult.Structures.ElementAt(0);
			_statusUpdater.Start();
			_statusProvider.Start();
		}
Esempio n. 18
0
			public void ShouldBeInErrorStateOnAnyOtherException() {
				var result = new GetStatusResult(WebServiceError.Unknown, new InvalidCastException());
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				Assert.AreEqual(_viewModel.State, NestViewModelState.Error);
			}
Esempio n. 19
0
			public void ShouldNotBeInErrorStateOnCanceledException() {
				var result = new GetStatusResult(WebServiceError.Cancelled, new Exception());
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				Assert.AreNotEqual(_viewModel.State, NestViewModelState.Error);
			}
Esempio n. 20
0
			public void ShouldNotBeLoggingInOnServerNotFoundException() {
				var result = new GetStatusResult(WebServiceError.ServerNotFound, new Exception());
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				Assert.AreNotEqual(_viewModel.State, NestViewModelState.LoggingIn);
			}
Esempio n. 21
0
			public void ShouldLogToAnalyticsOnException() {
				var expectedException = new Exception();
				var result = new GetStatusResult(WebServiceError.Unknown, expectedException);
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				_analyticsService.Verify(analytics => analytics.LogError(expectedException));
			}
Esempio n. 22
0
			public void ShouldSetCurrentErrorToErrorOnSessionTokenExpiredException() {
				var expectedError = WebServiceError.SessionTokenExpired;
				var result = new GetStatusResult(expectedError, new Exception());
				var args = new StatusEventArgs(result);

				_statusProvider.Raise(provider => provider.StatusUpdated += null, args);

				Assert.AreEqual(expectedError, _viewModel.CurrentError);
			}
 public StatusEventArgs(GetStatusResult status)
 {
     Status = status;
 }
Esempio n. 24
0
		private void UpdateViewModelFromGetStatusResult(GetStatusResult statusResult) {
			Structure firstStructure = statusResult.Structures.ElementAt(0);
			Thermostat firstThermostat = firstStructure.Thermostats.ElementAt(0);

			_getStatusResult = statusResult;

			TargetTemperature = firstThermostat.TargetTemperature;
			TargetTemperatureLow = firstThermostat.TargetTemperatureLow;
			TargetTemperatureHigh = firstThermostat.TargetTemperatureHigh;
			CurrentTemperature = firstThermostat.CurrentTemperature;
			IsHeating = firstThermostat.IsHeating;
			IsCooling = firstThermostat.IsCooling;
			FanMode = firstThermostat.FanMode;
			IsLeafOn = firstThermostat.IsLeafOn;
			HvacMode = firstThermostat.HvacMode;
			IsAway = firstStructure.IsAway;
		}