protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("dpsLast", Global.throttle1, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; var routeValues = context.Request.RequestContext.RouteData.Values; string dvid = routeValues["dvid"].ToString(); string ssid = routeValues["ssid"].ToString(); //查看设备信息 if (meth == "GET") { int dv; int ss; if (int.TryParse(dvid, out dv) && int.TryParse(ssid, out ss)) { var result = SensorsController.GetSensors().GetSensorType(dv, ss); if (!result.hasError) { if (result.type == em_SensorType.gen) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().GetGenLast(dv, ss, result.type))); } else if (result.type == em_SensorType.gps || result.type == em_SensorType.photo || result.type == em_SensorType.value) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().GetGpsValImgLast(dv, ss, result.type))); } } else { return(context.Response.Output.WriteAsync(result.error)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }
public override void _PhysicsProcess(float deltaTime) { UpdateShipStatusInfo(); //ActiveSensors.GenerateEMSReadings(); //ActiveSensors.PerformScan(0f, Mathf.Pi * 2f, 400f); PassiveSensors.GeneratePassiveSensorReadings(); if (SensorsController.IsProcessing) { SensorsController.SensorsUpdate(shipStatusInfo, ActiveSensors, PassiveSensors, deltaTime); } if (NavigationController.IsProcessing) { NavigationController.NavigationUpdate(shipStatusInfo, gameCore.GalaxyMap.GalaxyMapData, deltaTime); } if (PropulsionController.IsProcessing) { PropulsionController.PropulsionUpdate(shipStatusInfo, ThrusterControls, deltaTime); } if (DefenceController.IsProcessing) { DefenceController.DefenceUpdate(shipStatusInfo, Turret.TurretControls, deltaTime); } if (!IsLanded) { TimeElapsed += deltaTime; } }
public void UpdateSensor_WithUnknownSensorType_Returns_ConflictResult() { // Arrange var sensorServiceMock = new Mock <ISensorService>(); sensorServiceMock.Setup(service => service .GetSensorByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(GetSensor())); sensorServiceMock.Setup(service => service .UpdateSensorAsync(It.IsAny <SensorDTO>())) .Returns(Task.FromResult(false)); var loggerMock = new Mock <ILogger <SensorsController> >(); var controller = new SensorsController(sensorServiceMock.Object, loggerMock.Object); var sensorDTO = new SensorDTO { Id = 1 }; // Act var result = controller.UpdateSensor(sensorDTO).GetAwaiter().GetResult(); // Assert var conflictResult = Assert.IsType <ConflictResult>(result); }
public void DeleteSensor_Returns_OkResult() { // Arrange var sensorServiceMock = new Mock <ISensorService>(); sensorServiceMock.Setup(service => service .GetSensorByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(GetSensor())); sensorServiceMock.Setup(service => service .DeleteSensorByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(true)); var loggerMock = new Mock <ILogger <SensorsController> >(); var controller = new SensorsController(sensorServiceMock.Object, loggerMock.Object); var id = 1; // Act var result = controller.DeleteSensor(id).GetAwaiter().GetResult(); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); Assert.IsAssignableFrom <int>(okObjectResult.Value); }
public async Task Post_WhenCalled_NotifyFailed_ReturnsOk() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var newSensor = new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000003"), Type = "test_type", RoomId = Guid.Parse("00000000-0000-0000-0000-000000000001") }; mockedRepo.Setup(repo => repo.AddSensor(newSensor)).ReturnsAsync(newSensor); this.listenerMock.Setup(l => l.NotifySensorUpdate(newSensor)).ReturnsAsync((Sensor)null); var result = await controller.Post(newSensor); var contentResult = (result as OkObjectResult).Value; this.listenerMock.Verify(client => client.NotifySensorUpdate(newSensor), Times.Once); Assert.NotNull(contentResult); Assert.Equal(newSensor, contentResult); }
public LoriotWebsocket(DataWebserviceContext _context) { this._context = _context; sc = new Controllers.API.SensorsController(_context); dc = new DataController(_context); slc = new SensorLogsController(_context); }
public async Task InvokeOnce__ListSampleSensorsAsync() { //Arrange var sensorsService = new Mock <ISensorsService>(); var mockUserManager = GetUserManagerMock(); var memoryCacheMock = new MemoryCache(new MemoryCacheOptions()); var user = GetUser(); var testSampleSensor = GetSampleSensor(); sensorsService.Setup(s => s.ListSampleSensorsAsync()). ReturnsAsync(new List <SampleSensor>() { testSampleSensor }); var controller = new SensorsController (sensorsService.Object, mockUserManager.Object, memoryCacheMock); //Act await controller.ListSampleSensors(null); // first call await controller.ListSampleSensors(null); // second call from memoryCache //Assert sensorsService.Verify(s => s.ListSampleSensorsAsync(), Times.Once()); }
public async Task GetHomeyMapping_WhenCalled_ReturnsOk() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var newSensor = new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000003"), Type = "test_type" }; mockedRepo.Setup(repo => repo.GetSensor(newSensor.Id)).ReturnsAsync(newSensor); var newMapping = new HomeyMapping() { HumTopic = "humTopic", TempTopic = "tempTopic", MotionTopic = "motionTopic" }; mockedRepo.Setup(repo => repo.GetHomeyMapping(newSensor)).ReturnsAsync(newMapping); var result = await controller.GetHomeyMapping(newSensor.Id.ToString()); var contentResult = (result as OkObjectResult).Value; Assert.Equal(newMapping, contentResult); }
public async Task PostHomeyMapping_WhenCalled_WrongSensor_ReturnsNotFound() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var sensorId = Guid.Parse("00000000-0000-0000-0000-000000000003"); var newMapping = new HomeyMapping() { HumTopic = "humTopic", TempTopic = "tempTopic", MotionTopic = "motionTopic" }; mockedRepo.Setup(repo => repo.GetSensor(sensorId)).ReturnsAsync((Sensor)null); var result = await controller.PostHomeyMapping(sensorId.ToString(), newMapping); var contentResult = (result as NotFoundResult); Assert.NotNull(contentResult); mockedRepo.Verify(repo => repo.GetSensor(sensorId)); mockedRepo.VerifyNoOtherCalls(); }
public async Task PostHomeyMapping_WhenCalled_AddFailed_Returns500() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var newSensor = new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000003"), Type = "test_type" }; var newMapping = new HomeyMapping() { HumTopic = "humTopic", TempTopic = "tempTopic", MotionTopic = "motionTopic" }; mockedRepo.Setup(repo => repo.GetSensor(newSensor.Id)).ReturnsAsync(newSensor); mockedRepo.Setup(repo => repo.AddHomeyMapping(newSensor.Id, newMapping)).ReturnsAsync((HomeyMapping)null); var result = await controller.PostHomeyMapping(newSensor.Id.ToString(), newMapping); var contentResult = (result as StatusCodeResult); Assert.Equal(StatusCodes.Status500InternalServerError, contentResult.StatusCode); }
public async Task GetById_WhenCalled_UnknownID_ReturnsNotFoundResult() { var mockedRepo = new Mock <IHomeRepository>(); var sensors = new List <Sensor> { new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000001") }, new Sensor() { Name = "test_sensor_2", Id = Guid.Parse("00000000-0000-0000-0000-000000000002") } }; mockedRepo.Setup(repo => repo.GetSensor(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(sensors[0]); mockedRepo.Setup(repo => repo.GetSensor(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync(sensors[1]); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var result = await controller.Get("00000000-0000-0000-0000-000000000003"); var contentResult = result as NotFoundResult; Assert.NotNull(contentResult); }
public async void Can_post_items() { using (_context) { DataController controller = new DataController(_context); SensorsController sensorsController = new SensorsController(_context); // Finding a sensor to atach the data var sensors = sensorsController.GetSensor(); var List = new List <Sensor>(); var sensorID = 0; foreach (var data1 in sensors.Result.Value.ToList()) { List.Add(data1); } if (List.Count > 0) { var item = List[List.Count - 1]; sensorID = item.sensorID; } Models.Data testdata = new Models.Data(); testdata.sensorID = sensorID; testdata.timestamp = DateTime.Today; testdata.humidity = 123; testdata.CO2 = 123; testdata.temperature = 123; await controller.PostData(testdata); var data = controller.GetData(); var DTOList = new List <DataDTO>(); int DTOListcount = 0; foreach (var data1 in data.Result.Value.ToList()) { DTOList.Add(data1); DTOListcount++; } Assert.AreEqual(DTOListcount, DTOList.Count); Assert.AreEqual("123", DTOList[DTOList.Count - 1].CO2_value.ToString()); //Delete await controller.DeleteData(sensorID, DateTime.Today); data = controller.GetData(); DTOList = new List <DataDTO>(); foreach (var data1 in data.Result.Value.ToList()) { DTOList.Add(data1); } Assert.AreEqual(DTOListcount - 1, DTOList.Count); } }
public void Init() { _mocksensorDataProvider = new Mock <ISensorDataProvider>(); _mockauditDataProvider = new Mock <IAuditDataProvider>(); _mockmapper = new Mock <IMapper>(); sensorsController = new SensorsController(_mocksensorDataProvider.Object, _mockauditDataProvider.Object, _mockmapper.Object); }
public SensorsControllerTest() { sensorService = new Mock <ISensorService>(); sensorsController = new SensorsController(sensorService.Object); fixture = new Fixture(); fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); }
public void CreateInstance_WhenParametersAreCorrect() { //Arrange var serviceMock = new Mock <ISensorService>(); //Act var controller = new SensorsController(serviceMock.Object); //Assert Assert.IsNotNull(controller); }
public void ReturnDefaultViewWithCorrectViewModel() { //Arrange var serviceMock = new Mock <ISensorService>(); var controller = new SensorsController(serviceMock.Object); //Act & Assert controller .WithCallTo(x => x.Create()) .ShouldRenderDefaultView(); }
public async void Can_post_items() { using (_context) { SensorsController controller = new SensorsController(_context); RoomsController roomsController = new RoomsController(_context); var room = roomsController.GetRoom(); var RoomList = new List <Room>(); foreach (Room data1 in room.Result.Value.ToList()) { RoomList.Add(data1); } Models.Sensor testdata = new Models.Sensor(); testdata.servoSetting = "5"; testdata.roomID = RoomList[0].roomID; await controller.PostSensor(testdata); var sensor = controller.GetSensor(); var List = new List <Sensor>(); int Listcount = 0; foreach (var sensor1 in sensor.Result.Value.ToList()) { List.Add(sensor1); Listcount++; } Assert.AreEqual(Listcount, List.Count); Assert.AreEqual("5", List[Listcount - 1].servoSetting); //Delete if (List.Count > 0) { var item = List[List.Count - 1]; await controller.DeleteSensor(item.sensorID); } sensor = controller.GetSensor(); List = new List <Sensor>(); foreach (var sensor1 in sensor.Result.Value.ToList()) { List.Add(sensor1); } Assert.AreEqual(Listcount - 1, List.Count); } }
public void VerifyServiceMethod_IsCalled() { //Arrange var serviceMock = new Mock <ISensorService>(); var controller = new SensorsController(serviceMock.Object); //Act controller.Run(); //Assert serviceMock.Verify(m => m.Update(), Times.Once); }
public async Task InvokeOnce_DeleteUserSensorAsync() { var sensorsService = new Mock <ISensorsService>(); var mockUserManager = GetUserManagerMock(); var memoryCacheMock = new Mock <IMemoryCache>(); var testSensor = TestUserSensor(); var controller = new SensorsController (sensorsService.Object, mockUserManager.Object, memoryCacheMock.Object); await controller.DeleteSensor(testSensor.Id); sensorsService.Verify(s => s.DeleteUserSensorAsync(testSensor.Id), Times.Once()); }
public void UpdateSensor_WithInvalidModel_Returns_BadRequestResult() { // Arrange var sensorServiceMock = new Mock <ISensorService>(); var loggerMock = new Mock <ILogger <SensorsController> >(); var controller = new SensorsController(sensorServiceMock.Object, loggerMock.Object); controller.ModelState.AddModelError("Error", "Model Error"); var sensorDTO = new SensorDTO(); // Act var result = controller.UpdateSensor(sensorDTO).GetAwaiter().GetResult(); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public async Task Return_EditSensorView() { var sensorsService = new Mock <ISensorsService>(); var mockUserManager = GetUserManagerMock(); var memoryCacheMock = new Mock <IMemoryCache>(); var testSensor = TestUserSensor(); sensorsService.Setup(s => s.GetUserSensorAsync(It.IsAny <Guid>())). ReturnsAsync(testSensor); var controller = new SensorsController (sensorsService.Object, mockUserManager.Object, memoryCacheMock.Object); var result = await controller.EditSensor(testSensor.Id) as ViewResult; Assert.AreEqual("EditSensor", result.ViewName); }
public void Can_get_items() { using (_context) { SensorsController controller = new SensorsController(_context); var sensor = controller.GetSensor(); var List = new List <Sensor>(); foreach (var sensor1 in sensor.Result.Value.ToList()) { List.Add(sensor1); } Assert.AreEqual(List.Count, List.Count); } }
public void GetSensors_Returns_CollectionOfSensorDTO() { // Arrange var sensorServiceMock = new Mock <ISensorService>(); sensorServiceMock.Setup(service => service .GetAllSensorsAsync()) .Returns(Task.FromResult(GetAllSensors())); var loggerMock = new Mock <ILogger <SensorsController> >(); var controller = new SensorsController(sensorServiceMock.Object, loggerMock.Object); // Act var result = controller.GetSensors().GetAwaiter().GetResult(); // Assert Assert.IsType <List <SensorDTO> >(result); }
public void UpdateSensor_WithInvalidModelId_Returns_BadRequestResult() { // Arrange var sensorServiceMock = new Mock <ISensorService>(); var loggerMock = new Mock <ILogger <SensorsController> >(); var controller = new SensorsController(sensorServiceMock.Object, loggerMock.Object); var sensorDTO = new SensorDTO { Id = -1 }; // Act var result = controller.UpdateSensor(sensorDTO).GetAwaiter().GetResult(); // Assert var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); Assert.IsAssignableFrom <int>(badRequestObjectResult.Value); }
public async Task ReturnUserSensor_AsUserSensorDetailsModel() { var sensorsService = new Mock <ISensorsService>(); var mockUserManager = GetUserManagerMock(); var memoryCacheMock = new Mock <IMemoryCache>(); var testSensor = TestUserSensor(); sensorsService.Setup(s => s.GetUserSensorAsync(It.IsAny <Guid>())). ReturnsAsync(testSensor); var controler = new SensorsController (sensorsService.Object, mockUserManager.Object, memoryCacheMock.Object); var result = await controler.SensorDetails(testSensor.Id) as ViewResult; var viewModel = (UserSensorDetailsModel)result.ViewData.Model; Assert.AreEqual(testSensor.Id, viewModel.Id); }
public void GetSensor_WithValidModelAndInvalidId_Returns_NoContentResult() { // Arrange var sensorServiceMock = new Mock <ISensorService>(); sensorServiceMock.Setup(service => service .GetSensorByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(GetNullSensor())); var loggerMock = new Mock <ILogger <SensorsController> >(); var controller = new SensorsController(sensorServiceMock.Object, loggerMock.Object); var id = 2; // Act var result = controller.GetSensor(id).GetAwaiter().GetResult(); // Assert var noContentResult = Assert.IsType <NoContentResult>(result); }
public async Task Delete_WhenCalled_UnknownObject_ReturnsNotFound() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var newSensor = new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000003") }; mockedRepo.Setup(repo => repo.GetSensor(Guid.Parse("00000000-0000-0000-0000-000000000002"))).ReturnsAsync((Sensor)null); var result = await controller.Delete("00000000-0000-0000-0000-000000000002"); var contentResult = result as NotFoundResult; Assert.NotNull(contentResult); }
public async Task Put_WhenCalled_BadObject_ReturnsBadRequest() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var newSensor = new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000003") }; mockedRepo.Setup(repo => repo.EditSensor(newSensor)).ReturnsAsync(false); var result = await controller.Put(newSensor); var contentResult = result as BadRequestResult; Assert.NotNull(contentResult); }
public async Task Put_WhenCalled_ReturnsOkResult() { var mockedRepo = new Mock <IHomeRepository>(); var sensor = new Sensor() { Name = "test_sensor_1" }; var mockedSensorListenerClient = new Mock <ISensorListenerAPI>(); mockedSensorListenerClient.Setup(listener => listener.NotifySensorUpdate(sensor)).ReturnsAsync(sensor); mockedRepo.Setup(repo => repo.EditSensor(sensor)).ReturnsAsync(true); var controller = new SensorsController(mockedRepo.Object, mockedSensorListenerClient.Object, this.loggerMock); var result = await controller.Put(sensor); var contentResult = (result as OkObjectResult).Value; Assert.NotNull(contentResult); Assert.Equal(contentResult, sensor); }
public async Task GetAll_WhenCalled_ReturnsOk() { var mockedRepo = new Mock <IHomeRepository>(); var controller = new SensorsController(mockedRepo.Object, listenerClient, this.loggerMock); var newSensor = new Sensor() { Name = "test_sensor_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000003") }; mockedRepo.Setup(r => r.GetSensors()).ReturnsAsync(new List <Sensor> { newSensor }); var result = await controller.GetAll(); var contentResult = (List <Sensor>)(result as OkObjectResult).Value; Assert.Single(contentResult); Assert.Equal(newSensor, contentResult[0]); }