public void CreateRoute() { var distance = 1; var routeEntity = routeService.CreateRoute(new RouteViewModel(cityExpected1.Code, cityExpected2.Code, distance)); Assert.Equal(cityExpected1, routeEntity.CityOrigin); Assert.Equal(cityExpected2, routeEntity.CityDestination); Assert.Equal(distance, routeEntity.Distance); }
public void CreateNullRouteThrowsException() { var routeRepo = new Mock <IRouteRepo>(); var service = new RouteService(routeRepo.Object); Exception ex = Assert.Throws <InvalidDataException>(() => service.CreateRoute(null)); Assert.Equal("Route most not be null", ex.Message); }
public void CreateRouteWithNameEmptyThrowsException() { var routeRepo = new Mock <IRouteRepo>(); var service = new RouteService(routeRepo.Object); var route = new Route() { Id = 1, Name = "" }; Exception ex = Assert.Throws <InvalidDataException>(() => service.CreateRoute(route)); Assert.Equal("Route must have a name", ex.Message); }
public IActionResult NewRoute([FromForm] NewRouteViewModel routeData) { try { if (ModelState.IsValid) { var vehicle = vehicleService.GetById(routeData.VehicleId); routeService.CreateRoute(vehicle); return(PartialView("_NewRoutePartial", routeData)); } return(PartialView("_NewRoutePartial", routeData)); } catch (Exception e) { logger.LogError("Failed to create a new Route {@Exception}", e.Message); logger.LogDebug("Failed to create a new Route {@ExceptionMessage}", e); return(BadRequest(e.Message)); } }
public async Task <IActionResult> CreateRoute([FromBody] RouteCreateModel model) { var routes = await _routeService.GetRoutes(); Func <Guid?, int?> getRouteId = (id) => { return(routes.FirstOrDefault(p => p.Guid == id)?.RouteId); }; tblRoute route = new tblRoute() { Path = model.Path, ParentRouteId = getRouteId(model.ParentRouteGuid) }; await _routeService.CreateRoute(route); return(Ok(new RouteModel() { Guid = route.Guid, Path = route.Path, ParentRouteGuid = model.ParentRouteGuid })); }