public ActionResult Update(int?Id) { ViewBag.MachineId = Id == null ? 0 : Id.Value; var model = _machineService.GetMachineById(Id == null ? 0 : Id.Value); //MachineViewModel model = new MachineViewModel(); model.Sites = _siteService.GetAll("").ToArray(); model.Plants = this._plantService.GetPlantsForSite(model.SiteId); return(View(model)); }
public async Task <ActionResult <MachineDTO> > GetMachineById(Guid id) { try { Machine machine = await _serviceMachine.GetMachineById(id); var machineCreatedDTO = _mapper.Map <Machine, MachineDTO>(machine); return(machineCreatedDTO); } catch (KeyNotFoundException e) { return(NotFound(e.Message)); } }
public IActionResult GetMachineById(int id) { var machine = _machineService.GetMachineById(id); //TODO: Remove this mapping var machineModel = _mapper.Map <MachineModel>(machine); return(Ok(machineModel)); }
public async Task <IHttpActionResult> GetMachineById([FromUri] int id) { //instantiate service MachineService service = CreateMachineService(); List <MachineListItem> machine = await service.GetMachineById(id); return(Ok(machine)); //200 }
public async void EnsureMachineIsNotFoundById() { var context = ContextMocker.GetContextMock(); ContextMocker.SeedMachines(context); var machineService = new MachineService(context); var machineId = new Guid("11111111-2222-2222-2222-111111111111"); await Assert.ThrowsAsync <KeyNotFoundException>(() => (machineService.GetMachineById(machineId))); }
public void TestServiceShouldThrowNotFoundExceptionIfMachineIsNull() { //Given var mockRepo = new Mock <IMachineRepository>(); var service = new MachineService(mockRepo.Object); var machineId = "machine-id-1"; var machine = new AlarmSystem.Core.Entity.Dto.Machine() { MachineId = machineId }; //When mockRepo.Setup(mr => mr.ReadMachineById(It.IsAny <string>())).Returns(It.IsAny <AlarmSystem.Core.Entity.Dto.Machine>()); //Then Assert.Throws <EntityNotFoundException>(() => service.GetMachineById(machineId)); }
public async void EnsureMachineIsFoundById() { var context = ContextMocker.GetContextMock(); ContextMocker.SeedMachines(context); var machineService = new MachineService(context); var machineId = new Guid("11111111-1111-1111-1111-111111111111"); var expectedMachineTypeId = new Guid("21111111-1111-1111-1111-111111111111"); const string expectedMachineBrand = "Siemens"; const string expectedMachineModel = "HO-501"; const string expectedMachineLocation = "Sector 10"; var result = await machineService.GetMachineById(machineId); Assert.True(expectedMachineTypeId.Equals(result.MachineType.Id)); Assert.True(expectedMachineBrand.Equals(result.MachineBrand.Brand)); Assert.True(expectedMachineModel.Equals(result.MachineModel.Model)); Assert.True(expectedMachineLocation.Equals(result.MachineLocation.Location)); }
public void TestServiceShouldCallRepoOnce() { //Given var mockRepo = new Mock <IMachineRepository>(); var service = new MachineService(mockRepo.Object); var machineId = "machine-id-1"; var machine = new AlarmSystem.Core.Entity.Dto.Machine() { MachineId = machineId }; //When mockRepo.Setup(mr => mr.ReadMachineById(It.IsAny <string>())).Returns(machine); service.GetMachineById(machineId); //Then mockRepo.Verify(mr => mr.ReadMachineById(It.IsAny <string>()), Times.Once); }
[HttpGet("{id}", Name = "GetMachineById")] //Named so the Post can use it public ActionResult <MachineReadDto> GetMachineById(Guid id) { var Machine = _service.GetMachineById(id); return(Ok(Machine)); }