public void GetPlannedRoutes_Success_Test() { // Arrange R_PlannedRoute plannedRoute = SamplePlannedRoute(1); IList <R_PlannedRoute> list = new List <R_PlannedRoute>(); list.Add(plannedRoute); // create mock for repository var mock = new Mock <IPlannedRouteRepository>(); mock.Setup(s => s.GetPlannedRoutes()).Returns(list); // service PlannedRouteService plannedRouteService = new PlannedRouteService(); PlannedRouteService.Repository = mock.Object; // Act var resultList = plannedRouteService.GetPlannedRoutes(); PlannedRouteDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.PlannedRouteId); }
public PlannedRouteDTO GetPlannedRoute(int plannedRouteId) { try { //Requires.NotNegative("plannedRouteId", plannedRouteId); log.Debug("plannedRouteId: " + plannedRouteId + " "); // get R_PlannedRoute t = Repository.GetPlannedRoute(plannedRouteId); PlannedRouteDTO dto = new PlannedRouteDTO(t); log.Debug(PlannedRouteDTO.FormatPlannedRouteDTO(dto)); return(dto); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void UpdatePlannedRoute(R_PlannedRoute t) { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "PlannedRouteId"); t.Update(); }
public int AddPlannedRoute(PlannedRouteDTO dto) { int id = 0; try { log.Debug(PlannedRouteDTO.FormatPlannedRouteDTO(dto)); R_PlannedRoute t = PlannedRouteDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddPlannedRoute(t); dto.PlannedRouteId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public R_PlannedRoute GetPlannedRoute(int plannedRouteId) { //Requires.NotNegative("plannedRouteId", plannedRouteId); R_PlannedRoute t = R_PlannedRoute.SingleOrDefault(plannedRouteId); return(t); }
public IEnumerable <R_PlannedRoute> GetPlannedRoutes() { IEnumerable <R_PlannedRoute> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_PlannedRoute") .Where("IsDeleted = 0") ; results = R_PlannedRoute.Query(sql); return(results); }
public PlannedRouteDTO(R_PlannedRoute plannedRoute) { PlannedRouteId = plannedRoute.PlannedRouteId; Name = plannedRoute.Name; RouteTypeId = plannedRoute.RouteTypeId; TransportTypeId = plannedRoute.TransportTypeId; Description = plannedRoute.Description; StartHour = plannedRoute.StartHour; EstimatedDuration = plannedRoute.EstimatedDuration; TotalDistance = plannedRoute.TotalDistance; RouteDayOfTheWeek = plannedRoute.RouteDayOfTheWeek; Active = plannedRoute.Active; IsDeleted = plannedRoute.IsDeleted; CreateBy = plannedRoute.CreateBy; CreateOn = plannedRoute.CreateOn; UpdateBy = plannedRoute.UpdateBy; UpdateOn = plannedRoute.UpdateOn; }
public IList <R_PlannedRoute> GetPlannedRoutes(string searchTerm, int pageIndex, int pageSize) { IList <R_PlannedRoute> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_PlannedRoute") .Where("IsDeleted = 0") .Where( "Name like '%" + searchTerm + "%'" + " or " + "Description like '%" + searchTerm + "%'" + " or " + "RouteDayOfTheWeek like '%" + searchTerm + "%'" ) ; results = R_PlannedRoute.Fetch(pageIndex, pageSize, sql); return(results); }
public static R_PlannedRoute ConvertDTOtoEntity(PlannedRouteDTO dto) { R_PlannedRoute plannedRoute = new R_PlannedRoute(); plannedRoute.PlannedRouteId = dto.PlannedRouteId; plannedRoute.Name = dto.Name; plannedRoute.RouteTypeId = dto.RouteTypeId; plannedRoute.TransportTypeId = dto.TransportTypeId; plannedRoute.Description = dto.Description; plannedRoute.StartHour = dto.StartHour; plannedRoute.EstimatedDuration = dto.EstimatedDuration; plannedRoute.TotalDistance = dto.TotalDistance; plannedRoute.RouteDayOfTheWeek = dto.RouteDayOfTheWeek; plannedRoute.Active = dto.Active; plannedRoute.IsDeleted = dto.IsDeleted; plannedRoute.CreateBy = dto.CreateBy; plannedRoute.CreateOn = dto.CreateOn; plannedRoute.UpdateBy = dto.UpdateBy; plannedRoute.UpdateOn = dto.UpdateOn; return(plannedRoute); }
public void DeletePlannedRoute(PlannedRouteDTO dto) { try { log.Debug(PlannedRouteDTO.FormatPlannedRouteDTO(dto)); R_PlannedRoute t = PlannedRouteDTO.ConvertDTOtoEntity(dto); // delete Repository.DeletePlannedRoute(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void GetPlannedRoute_Success_Test() { // Arrange int id = 1; R_PlannedRoute plannedRoute = SamplePlannedRoute(id); // create mock for repository var mock = new Mock <IPlannedRouteRepository>(); mock.Setup(s => s.GetPlannedRoute(Moq.It.IsAny <int>())).Returns(plannedRoute); // service PlannedRouteService plannedRouteService = new PlannedRouteService(); PlannedRouteService.Repository = mock.Object; // Act PlannedRouteDTO result = plannedRouteService.GetPlannedRoute(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.PlannedRouteId); }
// example data public static R_PlannedRoute SamplePlannedRoute(int id = 1) { R_PlannedRoute plannedRoute = new R_PlannedRoute(); // int plannedRoute.PlannedRouteId = id; // string plannedRoute.Name = "NameTestValue"; // int? plannedRoute.RouteTypeId = 1; // int? plannedRoute.TransportTypeId = 1; // string plannedRoute.Description = "DescriptionTestValue"; // System.DateTime? plannedRoute.StartHour = new System.DateTime(); // int? plannedRoute.EstimatedDuration = 1; // double? plannedRoute.TotalDistance = 1; // string plannedRoute.RouteDayOfTheWeek = "RouteDayOfTheWeekTestValue"; // bool plannedRoute.Active = false; // bool plannedRoute.IsDeleted = false; // int? plannedRoute.CreateBy = 1; // System.DateTime? plannedRoute.CreateOn = new System.DateTime(); // int? plannedRoute.UpdateBy = 1; // System.DateTime? plannedRoute.UpdateOn = new System.DateTime(); return(plannedRoute); }
public IEnumerable <R_PlannedRoute> GetPlannedRouteListAdvancedSearch( string name , int?routeTypeId , int?transportTypeId , string description , System.DateTime?startHourFrom , System.DateTime?startHourTo , int?estimatedDuration , double?totalDistance , string routeDayOfTheWeek , bool?active ) { IEnumerable <R_PlannedRoute> results = null; var sql = PetaPoco.Sql.Builder .Select("*") .From("R_PlannedRoute") .Where("IsDeleted = 0" + (name != null ? " and Name like '%" + name + "%'" : "") + (routeTypeId != null ? " and RouteTypeId like '%" + routeTypeId + "%'" : "") + (transportTypeId != null ? " and TransportTypeId like '%" + transportTypeId + "%'" : "") + (description != null ? " and Description like '%" + description + "%'" : "") + (startHourFrom != null ? " and StartHour >= '" + startHourFrom.Value.ToShortDateString() + "'" : "") + (startHourTo != null ? " and StartHour <= '" + startHourTo.Value.ToShortDateString() + "'" : "") + (estimatedDuration != null ? " and EstimatedDuration like '%" + estimatedDuration + "%'" : "") + (totalDistance != null ? " and TotalDistance like '%" + totalDistance + "%'" : "") + (routeDayOfTheWeek != null ? " and RouteDayOfTheWeek like '%" + routeDayOfTheWeek + "%'" : "") + (active != null ? " and Active = " + (active == true ? "1" : "0") : "") ) ; results = R_PlannedRoute.Query(sql); return(results); }
public void UpdatePlannedRoute(PlannedRouteDTO dto) { try { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "PlannedRouteId"); log.Debug(PlannedRouteDTO.FormatPlannedRouteDTO(dto)); R_PlannedRoute t = PlannedRouteDTO.ConvertDTOtoEntity(dto); // update Repository.UpdatePlannedRoute(t); log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public void DeletePlannedRoute(R_PlannedRoute t) { t.IsDeleted = true; t.Update(); }
public int AddPlannedRoute(R_PlannedRoute t) { int id = (int)t.Insert(); return(id); }