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(); }
public async Task ShouldReturnErrorWhenGetResponseFails() { _webRequest.Setup(r => r.GetResponseAsync()).Throws(new Exception()); _webServiceDeserializer.Setup(d => d.ParseWebServiceErrorAsync(It.IsAny <Exception>())).Returns(Task.FromResult(WebServiceError.SessionTokenExpired)); GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(new Structure("")); Assert.AreEqual(WebServiceError.SessionTokenExpired, result.Error); }
public void ShouldNotBeLoggingInOnServerNotFoundException() { var result = new GetStatusResult(WebServiceError.ServerNotFound, new Exception()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.IsFalse(_viewModel.IsLoggingIn); }
public void ShouldNotBeLoggedInOnInvalidCredentialsException() { var result = new GetStatusResult(WebServiceError.InvalidCredentials, new Exception()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.IsFalse(_viewModel.IsLoggedIn); }
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."); }
public void ShouldBeLoggingInOnSessionTokenExpiredException() { var result = new GetStatusResult(WebServiceError.SessionTokenExpired, new Exception()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.IsTrue(_viewModel.IsLoggingIn); }
public void ShouldBeInErrorStateOnAnyOtherException() { var result = new GetStatusResult(WebServiceError.Unknown, new InvalidCastException()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.IsTrue(_viewModel.IsInErrorState); }
public EzGetStatusResult( GetStatusResult result ) { if (result.item != null) { Item = new EzStatus(result.item); } }
public void ShouldBeInErrorStateOnServerNotFoundException() { var result = new GetStatusResult(WebServiceError.ServerNotFound, new Exception()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.AreEqual(_viewModel.State, NestViewModelState.Error); }
public void ShouldNotBeInErrorStateOnCanceledException() { var result = new GetStatusResult(WebServiceError.Cancelled, new Exception()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.IsFalse(_viewModel.IsInErrorState); }
public void ShouldNotBeLoggedInOnSessionTokenExpiredException() { var result = new GetStatusResult(WebServiceError.SessionTokenExpired, new Exception()); var args = new StatusEventArgs(result); _statusProvider.Raise(provider => provider.StatusUpdated += null, args); Assert.AreNotEqual(_viewModel.State, NestViewModelState.LoggedIn); }
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); }
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)); }
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 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)); }
public async Task ShouldReturnExceptionWhenGetResponseFails() { var expectedException = new Exception("Failed!"); _webRequest.Setup(r => r.GetResponseAsync()).Throws(expectedException); GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(new Structure("")); Assert.AreEqual(expectedException, result.Exception); }
public async Task ShouldReturnStructureFromDeserializer() { var expectedStructure = new Structure("structureId"); _webServiceDeserializer.Setup(d => d.ParseStructureFromGetStructureStatusResult(It.IsAny <string>(), It.IsAny <string>())).Returns(expectedStructure); GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(new Structure("")); Assert.AreEqual(expectedStructure, result.Structures.ElementAt(0)); }
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 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."); }
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 ShouldUpdateTargetTemperatureLow() { var structure = new Structure(""); var thermostat = new Thermostat("") { TargetTemperatureLow = 48d }; structure.Thermostats.Add(thermostat); var status = new GetStatusResult(new[] { structure }); _statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status)); Assert.AreEqual(thermostat.TargetTemperatureLow, _viewModel.TargetTemperatureLow, "Expected TargetTemperatureLow to update from status change."); }
public async Task ShouldUseFanModeFromDeserializer() { var expectedFanMode = FanMode.On; _webServiceDeserializer.Setup(d => d.ParseFanModeFromDeviceSubscribeResult(It.IsAny <string>())) .Returns(expectedFanMode); _webResponse.SetupSequence(w => w.GetResponseStringAsync()) .Returns(Task.FromResult(FakeJsonMessages.GetStructureStatusResult)) .Returns(Task.FromResult(FakeJsonMessages.GetDeviceStatusResult)); var structure = new Structure(""); structure.Thermostats.Add(new Thermostat("")); GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(structure); Assert.AreEqual(expectedFanMode, result.Structures.ElementAt(0).Thermostats[0].FanMode); }
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; }
public GetStatusResult GetStatus() { GetStatusResult status = null; //connect if (this.Transport.Connect() == CommunicationResult.OK) { status = new GetStatusResult(); var solarMaxRequest = new SolarMaxRequest(new SolarMaxCommand[] { new SolarMaxCommand(SolarMaxCommandEnum.DEVICE_STATUS) }.ToList()); var resSend = this.Transport.Send(solarMaxRequest.ToString()); if (resSend == CommunicationResult.OK) { //receive var resRec = this.Transport.Receive(out string rec); if (resRec == CommunicationResult.OK) { SolarMaxResponse solarMaxResponse = new SolarMaxResponse(rec); var listSolarMaxCommand = solarMaxResponse.Parse(); if (listSolarMaxCommand.Count > 0) { status.Status = listSolarMaxCommand[0].Value; status.Result = true; } } else { status.Result = false; status.ErrorDescription = "Unable to receive the response"; } } else { status.Result = false; status.ErrorDescription = "Unable to send the request"; } //disconnect this.Transport.Disconnect(); return(status); } return(new GetStatusResult() { Result = false, ErrorDescription = "Unable to connect" }); }
/// <summary> /// Get the current status of a GrabzIt screenshot /// </summary> /// <param name="id">The id of the screenshot</param> /// <returns>A Status object representing the screenshot</returns> public Status GetStatus(string id) { lock (thisLock) { if (string.IsNullOrEmpty(id)) { return(null); } string url = string.Format("{0}getstatus.ashx?id={1}", BaseURLGet, id); GetStatusResult webResult = Get <GetStatusResult>(url); if (webResult == null) { return(null); } return(webResult.GetStatus()); } }
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(); }