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));
        }
Beispiel #3
0
        private async Task UpdateStatusAsync(Structure structure)
        {
            GetStatusResult result = await _nestWebService.GetStructureAndDeviceStatusAsync(structure);

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

            _delayedStatusProvider.CacheStatus(result);
        }
			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();
        }
Beispiel #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) {}
        }
Beispiel #8
0
 private void Reset()
 {
     _cachedStatusResult = null;
 }
Beispiel #9
0
 public void CacheStatus(GetStatusResult status)
 {
     _cachedStatusResult = status;
 }
Beispiel #10
0
 public StatusEventArgs(GetStatusResult status)
 {
     Status = status;
 }
 private void Reset()
 {
     _cachedStatusResult = null;
 }
Beispiel #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.");
			}
 public void CacheStatus(GetStatusResult status)
 {
     _cachedStatusResult = status;
 }
Beispiel #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.");
			}
Beispiel #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);
			}
Beispiel #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.");
			}
Beispiel #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();
		}
Beispiel #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);
			}
Beispiel #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);
			}
Beispiel #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);
			}
Beispiel #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));
			}
Beispiel #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;
 }
Beispiel #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;
		}