public async Task ReturnCorrectViewModel_WhenCalled() { // Arrange Mock <IUserSensorService> userSensorServiceMock = new Mock <IUserSensorService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); Mock <ISensorDataService> sensorDataServiceMock = new Mock <ISensorDataService>(); string validId = string.Empty; UserSensor validUserSensorResult = new UserSensor(); Sensor validSensor = new Sensor { IsState = false }; validUserSensorResult.Sensor = validSensor; validUserSensorResult.Latitude = "0"; validUserSensorResult.Longitude = "0"; userSensorServiceMock.Setup(mock => mock.GetSensorByIdAsync(validId)) .Returns(Task.FromResult(validUserSensorResult)); SensorController SUT = new SensorController( userSensorServiceMock.Object, sensorServiceMock.Object, memoryCacheMock.Object, sensorDataServiceMock.Object); // Act var result = await SUT.Modify(validId) as ViewResult; // Assert Assert.IsInstanceOfType(result.Model, typeof(ModifyViewModel)); }
public async Task UpdateUserSensorAsync(UserSensor userSensor) { Validator.ValidateNull(userSensor, "userSensor is null"); this.dataContext.Update(userSensor); await this.dataContext.SaveChangesAsync(); }
public async Task CallGetSensorByIdAsync_WhenInvoked() { // Arrange Mock <IUserSensorService> userSensorServiceMock = new Mock <IUserSensorService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); Mock <ISensorDataService> sensorDataServiceMock = new Mock <ISensorDataService>(); string validId = string.Empty; UserSensor validUserSensorResult = new UserSensor(); Sensor validSensor = new Sensor { IsState = false }; validUserSensorResult.Sensor = validSensor; validUserSensorResult.Latitude = "0"; validUserSensorResult.Longitude = "0"; userSensorServiceMock.Setup(mock => mock.GetSensorByIdAsync(validId)) .Returns(Task.FromResult(validUserSensorResult)); SensorController SUT = new SensorController( userSensorServiceMock.Object, sensorServiceMock.Object, memoryCacheMock.Object, sensorDataServiceMock.Object); // Act await SUT.Modify(validId); // Assert userSensorServiceMock.Verify(mock => mock.GetSensorByIdAsync(validId), Times.Once); }
public async Task <int> Add(UserSensor userSensor) { _userSensors.Add(userSensor); int result = await _userSensors.SaveChangesAsync(); return(result); }
public async Task ThrowApplicationException_WhenPassedUserSensorIsNull() { // Arrange Mock <IUserSensorService> userSensorServiceMock = new Mock <IUserSensorService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); Mock <ISensorDataService> sensorDataServiceMock = new Mock <ISensorDataService>(); string validId = string.Empty; UserSensor validUserSensorResult = null; userSensorServiceMock.Setup(mock => mock.GetSensorByIdAsync(validId)) .Returns(Task.FromResult(validUserSensorResult)); SensorController SUT = new SensorController( userSensorServiceMock.Object, sensorServiceMock.Object, memoryCacheMock.Object, sensorDataServiceMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ApplicationException>(() => SUT.Modify(validId)); }
public async Task ReturnPublicSensors_WhenCollectionIsNotEmpty() { var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>() .UseInMemoryDatabase("ReturnPublicSensors_WhenCollectionIsNotEmpty") .Options; var seedUsersMock = new Mock <ISeedUsers>(); var seedApiDataMock = new Mock <ISeedApiData>(); var measure = new Measure { Id = 1, MeasureType = "test" }; var sensorType = new SensorType { Id = 1, Name = "Test" }; var sampleSensor = new SampleSensor { Id = Guid.Parse("00000000-0000-0000-0000-000000000002"), Tag = "Test Sensor", Description = "Test Sensor", MinPollingInterval = 20, MeasureId = measure.Id, ValueCurrent = 50, SensorTypeId = sensorType.Id, IsOnline = true }; var userSensor = new UserSensor { Id = Guid.Parse("00000000-0000-0000-0000-000000000001"), CreatedOn = DateTime.Now, isDeleted = false, SampleSensorId = sampleSensor.Id, PollingInterval = 100, SendNotification = true, IsPrivate = false }; //Act using (var actContext = new DormitorySystemContext(contextOptions, seedUsersMock.Object, seedApiDataMock.Object)) { actContext.Measures.Add(measure); actContext.SensorTypes.Add(sensorType); actContext.SampleSensors.Add(sampleSensor); actContext.UserSensors.Add(userSensor); actContext.SaveChanges(); } //Assert using (var assertContext = new DormitorySystemContext(contextOptions, seedUsersMock.Object, seedApiDataMock.Object)) { var service = new SensorService(assertContext); var result = await service.GetPublicSensorsAsync(); Assert.AreEqual(1, result.Count()); } }
public void ReturnRedirectResult_WhenModelStateIsValid() { // Arrange Mock <IUserSensorService> userSensorServiceMock = new Mock <IUserSensorService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); Mock <ISensorDataService> sensorDataServiceMock = new Mock <ISensorDataService>(); var controller = new SensorController(userSensorServiceMock.Object, sensorServiceMock.Object, memoryCacheMock.Object, sensorDataServiceMock.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = new ClaimsPrincipal() } }, TempData = new Mock <ITempDataDictionary>().Object }; var viewModel = new ModifyViewModel() { Name = "Name", Description = "Description", PollingInterval = 10, Latitude = 0, Longitude = 0, IsPublic = true, AlarmTriggered = true, AlarmMin = 0, AlarmMax = 0, Id = "Description", IsState = true, }; string validId = viewModel.Id; UserSensor validUserSensorResult = new UserSensor(); Sensor validSensor = new Sensor { IsState = false }; validUserSensorResult.Sensor = validSensor; validUserSensorResult.Latitude = "0"; validUserSensorResult.Longitude = "0"; userSensorServiceMock.Setup(mock => mock.GetSensorByIdAsync(validId)) .Returns(Task.FromResult(validUserSensorResult)); // Act var result = controller.Modify(viewModel); //Assert Assert.IsInstanceOfType(result.Result, typeof(RedirectToActionResult)); var redirectResult = (RedirectToActionResult)result.Result; Assert.AreEqual("Modify", redirectResult.ActionName); Assert.IsNull(redirectResult.RouteValues); }
public BaseUserSensorViewModel(UserSensor model) { Id = model.Id; Name = model.Name; Type = model.SampleSensor.SensorType.Name; CreatedOn = model.CreatedOn; ModifiedOn = model.ModifiedOn; }
public async Task NotCallGetSensorData_WhenTimeSpanIsLessThanPollingInterval() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "NotCallGetSensorData_WhenTimeSpanIsLessThanPollingInterval") .Options; Sensor validSensor = new Sensor { SensorId = "validId" }; DateTime value = DateTime.Now; validSensor.LastTimeStamp = value; validSensor.MinPollingIntervalInSeconds = 1000000; IEnumerable <Sensor> expectedList = new List <Sensor> { validSensor }; SensorData dbSensorData = new SensorData { Sensor = validSensor }; UserSensor dbUserSensor = new UserSensor { Sensor = validSensor }; using (DataContext actContext = new DataContext(contextOptions)) { Mock <IApiClient> apiClientMock = new Mock <IApiClient>(); Mock <INotificationService> notificationServiceMock = new Mock <INotificationService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCacheWrapper> memoryCacheMock = new Mock <IMemoryCacheWrapper>(); await actContext.SensorData.AddAsync(dbSensorData); await actContext.Sensors.AddAsync(validSensor); await actContext.UserSensors.AddAsync(dbUserSensor); await actContext.SaveChangesAsync(); memoryCacheMock.Setup(mock => mock.GetOrSetCache()) .Returns(Task.FromResult(expectedList)); SensorDataService SUT = new SensorDataService( apiClientMock.Object, actContext, notificationServiceMock.Object, memoryCacheMock.Object); await SUT.GetSensorsDataAsync(); apiClientMock.Verify(mock => mock.GetSensorData(It.IsAny <string>()), Times.Never); } }
public async Task ListSensorByIdAsync_ShouldReturnValidSensor() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "ListSensorByIdAsync_ShouldReturnValidSensor") .Options; UserSensor userSensor = new UserSensor { AlarmMin = 20, AlarmMax = 30, AlarmTriggered = true, Coordinates = "42.672143,23.292216", CreatedOn = DateTime.Now, Description = "Description122", Id = "82a2e1b1-ea5d-4356-8266-b6b42471653e", IsPublic = true, LastValueUser = "******", Latitude = "42.672143", Longitude = "23.292216", Name = "Thermostat temp", IsDeleted = false, PollingInterval = 50, SensorId = "81a2e1b1-ea5d-4356-8266-b6b42471653e", TimeStamp = DateTime.Now, Type = "Celsius", UserId = "81a2e1b1-ea5d-4356-8266-b6b42471665e", UserInterval = 44 }; var result = new UserSensor(); // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <ISensorService> sensor = new Mock <ISensorService>(); await actContext.UserSensors.AddAsync(userSensor); await actContext.SaveChangesAsync(); UserSensorService SUT = new UserSensorService(actContext, sensor.Object); result = await SUT.ListSensorByIdAsync("82a2e1b1-ea5d-4356-8266-b6b42471653e"); } //Assert using (DataContext assertContext = new DataContext(contextOptions)) { Assert.IsTrue(assertContext.UserSensors.Any(s => s.Coordinates.Equals(result.Coordinates))); Assert.IsTrue(assertContext.UserSensors.Any(s => s.LastValueUser.Equals(result.LastValueUser))); Assert.IsTrue(assertContext.UserSensors.Any(s => s.SensorId.Equals(result.SensorId))); } }
private static UserSensor GetPublicSensor() { var measure = new Measure { Id = 1, MeasureType = "test" }; var sensorType = new SensorType { Id = 1, Name = "Test" }; var sampleSensor = new SampleSensor { Id = Guid.Parse("00000000-0000-0000-0000-000000000333"), Tag = "Test Sensor", Description = "Test Sensor", MinPollingInterval = 20, MeasureId = measure.Id, Measure = measure, ValueCurrent = 50, SensorTypeId = sensorType.Id, SensorType = sensorType, TimeStamp = DateTime.Now.ToString(), IsOnline = true }; var user = new User() { Id = "00000000-0000-0000-0000-000000000001", Email = "*****@*****.**", }; var userSensor = new UserSensor { Id = Guid.Parse("00000000-0000-0000-0000-000000000444"), Name = "Test", CreatedOn = DateTime.Now, isDeleted = false, SampleSensorId = sampleSensor.Id, SampleSensor = sampleSensor, PollingInterval = 100, UserMinValue = 100, UserMaxValue = 200, Latitude = "51.1524", Longitude = "55.546", SendNotification = true, IsPrivate = false, User = user, UserId = user.Id, }; return(userSensor); }
public async Task AddUserSensorAsync_ShouldThrowEntityAlreadyExistsExceptionExceptionsWhenSensorExists() { UserSensor validUserSensor = new UserSensor { AlarmMin = 20, AlarmMax = 30, AlarmTriggered = true, Coordinates = "42.672143,23.292216", CreatedOn = DateTime.Now, Description = "Description122", Id = "82a2e1b1-ea5d-4356-8266-b6b42471653e", IsPublic = true, LastValueUser = "******", Latitude = "42.672143", Longitude = "23.292216", Name = "name example", IsDeleted = false, PollingInterval = 50, SensorId = "81a2e1b1-ea5d-4356-8266-b6b42471653e", TimeStamp = DateTime.Now, Type = "Celsius", UserId = "81a2e1b1-ea5d-4356-8266-b6b42471665e", UserInterval = 44, Sensor = new Sensor { Id = "81a2e1b1-ea5d-4356-8266-b6b42471653e", SensorId = "81a2e1b1-ea5d-4356-8266-b6b42471653e" } }; // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "AddUserSensorAsync_ShouldThrowEntityAlreadyExistsExceptionExceptionsWhenSensorExists") .Options; var result = new UserSensor(); // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <ISensorService> sensor = new Mock <ISensorService>(); await actContext.UserSensors.AddAsync(validUserSensor); await actContext.SaveChangesAsync(); UserSensorService SUT = new UserSensorService(actContext, sensor.Object); await SUT.AddUserSensorAsync(validUserSensor.Id, validUserSensor.SensorId, validUserSensor.Name, validUserSensor.Description, validUserSensor.Latitude, validUserSensor.Longitude, validUserSensor.AlarmMin, validUserSensor.AlarmMax, validUserSensor.PollingInterval, validUserSensor.AlarmTriggered, validUserSensor.IsPublic, validUserSensor.LastValueUser, validUserSensor.Type); } }
public async Task <UserSensor> RegisterSensorAsync(UserSensor newSensor) { if (newSensor == null) { throw new SensorNullableException("There is no sensor for registration."); } await this.context.UserSensors.AddAsync(newSensor); await this.context.SaveChangesAsync(); return(newSensor); }
public SensorTableViewModel(UserSensor userSensor) { this.Id = userSensor.Id; this.Name = userSensor.Name; this.Latitude = userSensor.Latitude; this.Longitude = userSensor.Longitude; this.AlarmMax = userSensor.AlarmMax; this.AlarmMin = userSensor.AlarmMin; this.IsPublic = userSensor.IsPublic; this.LastValue = double.Parse(userSensor.Sensor.LastValue); this.IsState = userSensor.Sensor.IsState; this.IsDeleted = userSensor.IsDeleted; }
public UserIndexModel(UserSensor model) : base(model) { this.Description = model.SampleSensor.Description; this.CurrentValue = model.SampleSensor.ValueCurrent.ToString() + " " + model.SampleSensor.Measure.MeasureType.ToString(); this.SensorType = model.SampleSensor.SensorType.Name; this.IsPrivate = model.IsPrivate; this.IsOnline = model.SampleSensor.IsOnline; this.IsDeleted = model.isDeleted; }
public UserSensorDetailsModel(UserSensor model) : base(model) { this.SampleSensorId = model.SampleSensorId; this.UserPollingInterval = model.PollingInterval; this.UserMinValue = model.UserMinValue; this.UserMaxValue = model.UserMaxValue; this.Latitude = model.Latitude; this.Longitude = model.Longitude; this.SendNotification = model.SendNotification; this.IsPrivate = model.IsPrivate; this.MeasureType = model.SampleSensor.Measure.MeasureType; this.IsDeleted = model.isDeleted; this.TimeStamp = DateTime.Parse(model.SampleSensor.TimeStamp); }
public async Task <UserSensor> EditSensorAsync(UserSensor editedSensor) { if (editedSensor == null) { throw new SensorNullableException("There is no sensor for update."); } this.context.Update(editedSensor); editedSensor.ModifiedOn = DateTime.Now; await this.context.SaveChangesAsync(); return(editedSensor); }
public ModifyViewModel(UserSensor userSensor) { this.Name = userSensor.Name; this.Description = userSensor.Description; this.PollingInterval = userSensor.PollingInterval; this.Latitude = double.Parse(userSensor.Latitude); this.Longitude = double.Parse(userSensor.Longitude); this.IsPublic = userSensor.IsPublic; this.AlarmTriggered = userSensor.AlarmTriggered; this.AlarmMin = userSensor.AlarmMin; this.AlarmMax = userSensor.AlarmMax; this.Id = userSensor.Id; this.IsState = userSensor.Sensor.IsState; }
public async Task <IActionResult> RegisterNewSensor ([Bind(include: WebConstants.UserSensorViewModelBindingString)] RegisterSensorModel model) { if (!ModelState.IsValid) { this.TempData["Lng-Lat"] = "Please set the location of the sensor."; return(View(model)); } if (model.UserMinValue >= model.UserMaxValue) { this.TempData["Invalid-Min-Max-Value"] = "The minimum value can not be equal to or greater than the maximum value."; return(View(model)); } if (model.UserId == null) { var currentUser = await this.userManager.GetUserAsync(HttpContext.User); model.UserId = currentUser.Id; } var registrationData = new UserSensor() { Name = model.Name, PollingInterval = model.UserPollingInterval, SampleSensorId = model.SampleSensorId, UserId = model.UserId, UserMinValue = model.UserMinValue, UserMaxValue = model.UserMaxValue, Latitude = model.Latitude, Longitude = model.Longitude, SendNotification = model.SendNotification, IsPrivate = model.IsPrivate }; UserSensor sensor; try { sensor = await this.sensorsService.RegisterSensorAsync(registrationData); } catch (SensorNullableException ex) { this.TempData["Service-Error"] = ex.Message; return(View("ServiceError")); } this.TempData["Success-Message"] = $"Sensor {sensor.Name} was registered successfully!"; return(this.RedirectToAction("ListSampleSensors", new { userId = sensor.UserId })); }
public BaseRegisterEditViewModel(UserSensor model) : base(model) { UserPollingInterval = model.PollingInterval; MinPollingInterval = model.SampleSensor.MinPollingInterval; UserMinValue = model.UserMinValue; MinValue = model.SampleSensor.MinValue; UserMaxValue = model.UserMaxValue; MaxValue = model.SampleSensor.MaxValue; Latitude = model.Latitude; Longitude = model.Longitude; SendNotification = model.SendNotification; SampleSensorId = model.SampleSensorId; UserId = model.UserId; MeasureType = model.SampleSensor.Measure.MeasureType; }
public async Task RestoreUserSensor_ShouldFlagChampionAsNotDeleted_WhenPassedValidParameters() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "RestoreUserSensor_ShouldFlagChampionAsNotDeleted_WhenPassedValidParameters") .Options; Guid Id = Guid.NewGuid(); bool validIsDeleted = false; UserSensor validUserSensor = new UserSensor { Id = Id.ToString(), Name = "testChamp", DeletedOn = DateTime.UtcNow.AddHours(2), IsDeleted = true }; UserSensor result = null; // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); await actContext.AddAsync(validUserSensor); await actContext.SaveChangesAsync(); UserSensorService SUT = new UserSensorService( actContext, sensorServiceMock.Object); result = await SUT.RestoreUserSensor(Id.ToString()); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { Assert.IsNotNull(result); Assert.IsNull(result.DeletedOn); Assert.IsTrue(result.IsDeleted.Equals(validIsDeleted)); } }
public async Task <IActionResult> EditSensor( [Bind(include: WebConstants.UserSensorViewModelBindingString)] EditSensorModel model) { if (!this.ModelState.IsValid) { return(View(model)); } if (model.UserMinValue >= model.UserMaxValue) { this.TempData["Invalid-Min-Max-Value"] = "The minimum value can not be equal to or greater than the maximum value."; return(View(model)); } var editedSensor = new UserSensor() { Id = model.Id, Name = model.Name, PollingInterval = model.UserPollingInterval, SampleSensorId = model.SampleSensorId, UserId = model.UserId, UserMinValue = model.UserMinValue, UserMaxValue = model.UserMaxValue, Latitude = model.Latitude, Longitude = model.Longitude, SendNotification = model.SendNotification, IsPrivate = model.IsPrivate, CreatedOn = model.RegisteredOn }; UserSensor sensor; try { sensor = await this.sensorsService.EditSensorAsync(editedSensor); } catch (SensorNullableException ex) { this.TempData["Service-Error"] = ex.Message; return(View("ServiceError")); } return(this.RedirectToAction("SensorDetails", new { userSensorid = sensor.Id })); }
public UserSensorViewModel(UserSensor sensor) { Name = sensor.Name; Description = sensor.Description; Type = sensor.Type; UserInterval = sensor.UserInterval; LastValueUser = sensor.LastValueUser; TimeStamp = sensor.TimeStamp; Coordinates = sensor.Coordinates; IsPublic = sensor.IsPublic; AlarmTriggered = sensor.AlarmTriggered; AlarmMin = sensor.AlarmMin; AlarmMax = sensor.AlarmMax; UserId = sensor.UserId; User = sensor.User; SensorId = sensor.SensorId; Sensor = sensor.Sensor; Id = sensor.Id; }
public async Task <UserSensor> DisableUserSensor(string userSensorId) { Validator.ValidateNull(userSensorId, "User sensor Id cannot be null!"); Validator.ValidateGuid(userSensorId, "User sensor id is not in the correct format.Unable to parse to Guid!"); UserSensor userSensor = await this.dataContext.UserSensors .Include(us => us.Sensor) .FirstAsync(us => us.Id.Equals(userSensorId)); if (userSensorId == null) { throw new EntityNotFoundException(); } this.dataContext.Remove(userSensor); await this.dataContext.SaveChangesAsync(); return(userSensor); }
public async Task CallGetSensorsByUserId_WhenInvoked() { // Arrange Mock <IUserSensorService> userSensorServiceMock = new Mock <IUserSensorService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); Mock <ISensorDataService> sensorDataServiceMock = new Mock <ISensorDataService>(); string validId = "testGuid"; double validLastValue = 10; int validPageNumber = 1; int validPageSize = 10; UserSensor validUserSensor = new UserSensor(); Sensor validSensor = new Sensor(); validUserSensor.Sensor = validSensor; validUserSensor.Sensor.LastValue = validLastValue.ToString(); List <UserSensor> validList = new List <UserSensor> { validUserSensor }; IPagedList <UserSensor> validCollection = new PagedList <UserSensor>(validList.AsQueryable(), validPageNumber, validPageSize); userSensorServiceMock.Setup(mock => mock.GetSensorsByUserId(validId, validPageNumber, validPageSize)) .Returns(Task.FromResult(validCollection)); SensorController SUT = new SensorController( userSensorServiceMock.Object, sensorServiceMock.Object, memoryCacheMock.Object, sensorDataServiceMock.Object); // Act await SUT.Index(validId, validPageNumber, validPageSize); // Assert userSensorServiceMock .Verify(mock => mock.GetSensorsByUserId(validId, validPageNumber, validPageSize), Times.Once); }
public async Task GetSensorByIdAsync_ShouldThrowArgumentNullExceptionsWhenUserSensorIsNull() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "GetSensorByIdAsync_ShouldThrowArgumentNullExceptionsWhenUserSensorIsNull") .Options; var result = new UserSensor(); // Act using (DataContext actContext = new DataContext(contextOptions)) { Mock <ISensorService> sensor = new Mock <ISensorService>(); await actContext.SaveChangesAsync(); UserSensorService SUT = new UserSensorService(actContext, sensor.Object); result = await SUT.GetSensorByIdAsync("82a231b1-ea5d-4356-8266-b6b42471653e"); } }
public async Task <UserSensor> AddUserSensorAsync(string userId, string sensorId, string name, string description, string latitude, string longitude, double alarmMin, double alarmMax, int pollingInterval, bool alarmTriggered, bool isPublic, string lastValue, string type) { Validator.ValidateNull(name, "Sensor name cannot be null!"); if (await this.dataContext.UserSensors.AnyAsync(us => us.Name.Equals(name))) { throw new EntityAlreadyExistsException("User sensor already exists!"); } var sensor = await this.dataContext.Sensors.FirstOrDefaultAsync(ss => ss.Id == sensorId); var userSensor = new UserSensor { UserId = userId, Name = name, Description = description, Latitude = latitude, Longitude = longitude, AlarmTriggered = alarmTriggered, AlarmMin = alarmMin, AlarmMax = alarmMax, IsPublic = isPublic, PollingInterval = pollingInterval, Coordinates = latitude + "," + longitude, Type = type, LastValueUser = lastValue, SensorId = sensor.Id, UserInterval = pollingInterval }; await this.dataContext.UserSensors.AddAsync(userSensor); await this.dataContext.SaveChangesAsync(); return(userSensor); }
private bool AccountForState(UserSensor userSensor) { bool shouldNotify = false; var newValue = double.Parse(userSensor.Sensor.LastValue); if (userSensor.Sensor.IsState == true) { if (newValue == 1 && userSensor.AlarmTriggered == true) { shouldNotify = true; } } else { if ((newValue <= userSensor.AlarmMin || newValue >= userSensor.AlarmMax) && userSensor.AlarmTriggered == true) { shouldNotify = true; } } return(shouldNotify); }
public async Task ThrowApplicationException_WhenPassedNullId() { // Arrange Mock <IUserSensorService> userSensorServiceMock = new Mock <IUserSensorService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); Mock <ISensorDataService> sensorDataServiceMock = new Mock <ISensorDataService>(); string validId = "testGuid"; double validLastValue = 10; int validPageNumber = 1; int validPageSize = 10; UserSensor validUserSensor = new UserSensor(); Sensor validSensor = new Sensor(); validUserSensor.Sensor = validSensor; validUserSensor.Sensor.LastValue = validLastValue.ToString(); List <UserSensor> validList = new List <UserSensor> { validUserSensor }; IPagedList <UserSensor> validCollection = new PagedList <UserSensor>(validList.AsQueryable(), validPageNumber, validPageSize); userSensorServiceMock.Setup(mock => mock.GetSensorsByUserId(validId, validPageNumber, validPageSize)) .Returns(Task.FromResult(validCollection)); SensorController SUT = new SensorController( userSensorServiceMock.Object, sensorServiceMock.Object, memoryCacheMock.Object, sensorDataServiceMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ApplicationException>(() => SUT.Index(null, validPageNumber, validPageSize)); }
public SensorsCoordinatesModel(UserSensor model) { Name = model.Name; Latitude = model.Latitude; Longitude = model.Longitude; }