public async void NonExistingTaskWId() { var mtId = 2222222; using (var context = new FactoryContext(builder.Options)) { IMaintenanceTaskService maintenanceTaskService = new MaintenanceTaskService(context); PaginationOpts paginationOpts = new PaginationOpts(); var mt = (await maintenanceTaskService.Get(mtId)); Assert.Null(mt); } }
public async void TasksByNonExistingDevice() { var fdId = 2222; using (var context = new FactoryContext(builder.Options)) { IMaintenanceTaskService maintenanceTaskService = new MaintenanceTaskService(context); PaginationOpts paginationOpts = new PaginationOpts(); var mts = (await maintenanceTaskService.GetAllByDeviceId(fdId, paginationOpts)).ToList(); Assert.Empty(mts); } }
public async void AllTasks() { using (var context = new FactoryContext(builder.Options)) { IMaintenanceTaskService maintenanceTaskService = new MaintenanceTaskService(context); PaginationOpts paginationOpts = new PaginationOpts(); var mts = (await maintenanceTaskService.GetAll(paginationOpts)).ToList(); Assert.NotNull(mts); Assert.NotEmpty(mts); Assert.Equal(50, mts.Count); } }
public async void NonExistingDeviceWithId() { int fdId = 2222; using (var context = new FactoryContext(builder.Options)) { IFactoryDeviceService factoryDeviceService = new FactoryDeviceService(context); PaginationOpts paginationOpts = new PaginationOpts(); var fd = (await factoryDeviceService.Get(fdId)); Assert.Null(fd); } }
public async void AllDevices() { using (var context = new FactoryContext(builder.Options)) { IFactoryDeviceService factoryDeviceService = new FactoryDeviceService(context); PaginationOpts paginationOpts = new PaginationOpts(); var fds = (await factoryDeviceService.GetAll(paginationOpts)).ToList(); Assert.NotNull(fds); Assert.NotEmpty(fds); Assert.Equal(50, fds.Count); } }
public async Task <IEnumerable <FactoryDeviceDto> > Get([FromQuery] PaginationOpts paginationOpts) { return((await _factoryDeviceService.GetAll(paginationOpts)) .Select(fd => new FactoryDeviceDto { Id = fd.Id, Name = fd.Name, Year = fd.Year, Type = fd.Type } )); }
/// <summary> /// Fetches all Maintenance Tasks from db (paginated) /// </summary> /// <param name="paginationOpts">Pagination options for result</param> /// <returns>IEnumerable<MaintenanceTask></returns> public async Task <IEnumerable <MaintenanceTask> > GetAll(PaginationOpts paginationOpts) { try { return(await _context.MaintenanceTasks .OrderBy(mt => mt.Criticality) .ThenByDescending(mt => mt.Time) .Skip((paginationOpts.PageNumber - 1) * paginationOpts.PageSize) .Take(paginationOpts.PageSize) .ToListAsync()); } catch (Exception e) { throw e; } }
public async Task <IEnumerable <MaintenanceTaskDto> > GetByDevice([FromQuery] PaginationOpts paginationOpts, int deviceId) { return((await _service.GetAllByDeviceId(deviceId, paginationOpts)) .Select(mt => new MaintenanceTaskDto { Id = mt.Id, Description = mt.Description, Criticality = mt.Criticality.ToString(), FactoryDeviceId = mt.FactoryDeviceId, Done = mt.Done, Time = mt.Time } )); }
public async void TasksPaginationOptions() { var pageSize = 25; using (var context = new FactoryContext(builder.Options)) { IMaintenanceTaskService maintenanceTaskService = new MaintenanceTaskService(context); PaginationOpts paginationOpts = new PaginationOpts(); paginationOpts.PageSize = pageSize; paginationOpts.PageNumber = 5; var mts = (await maintenanceTaskService.GetAll(paginationOpts)).ToList(); Assert.NotNull(mts); Assert.NotEmpty(mts); Assert.Equal(pageSize, mts.Count); } }
/// <summary> /// Fetches FactoryDevices from db /// </summary> /// <param name="paginationOpts">Options for result pagination</param> /// <returns>IEnumerable of FactoryDevices</returns> public async Task <IEnumerable <FactoryDevice> > GetAll(PaginationOpts paginationOpts) { try { // if no entries in db, seed db // REMOVE if you want to seed with own data var b = _context.FactoryDevices.Any(); if (!b) { DbSeeder.Seed(_context); } return(await _context.FactoryDevices .Skip((paginationOpts.PageNumber - 1) *paginationOpts.PageSize) .Take(paginationOpts.PageSize) .ToListAsync()); } catch (Exception e) { throw e; } }