public void ScanRepository_AddWebsiteToScan_NoScanFound() { var repository = new ScanRepository(new DatabaseFactory(Database)); //Act repository.AddWebsiteToScan(23, 122); }
public void ScanRepository_AddWebsiteToScan() { //Arrange Database.Scans.Add(new Scans() { Id = 23, Target = "usa.gov", ScanError = "", ValidationError = "", AnalysisParams = "{}", ConnInfo = "{}" }); Database.Websites.Add(new Websites() { Id = 122, Hostname = "usa.gov" }); Database.SaveChanges(); var unitOfWorkFactory = new Mock <IUnitOfWorkFactory>(); unitOfWorkFactory.Setup(x => x.GetUnitOfWork()).Returns(new UnitOfWork(Database)); var repository = new ScanRepository(new DatabaseFactory(Database)) { UnitOfWorkFactory = unitOfWorkFactory.Object }; //Act repository.AddWebsiteToScan(23, 122); var scan = Database.Scans.Find(23); //Assert Assert.IsNotNull(scan); Assert.AreEqual(122, scan.WebsiteId); }
private IActionResult UpdateScan(Scan scan, Veteran veteran) { try { var updatedScan = ScanRepository.Update(scan); return(StatusCode(201, new ScanResponse(updatedScan, veteran))); } catch (Exception ex) { throw new Exception($"Error processing Scan: {ex.Message}. See inner Exception for details.", ex); } }
public IActionResult Delete(Guid eventId, Guid serviceId, string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest($"The card or veteran ID is null or empty.")); } var veteran = default(Veteran); if (int.TryParse(id, out var cardNumber)) { veteran = VeteranRepository .GetAll(new VeteranFilters() { CardNumber = cardNumber }) .SingleOrDefault(); } else if (Guid.TryParse(id, out var veteranId)) { veteran = VeteranRepository.Get(veteranId); } else { return(BadRequest($"The provided ID is neither a Card Number nor Veteran ID.")); } if (veteran == default(Veteran)) { return(StatusCode(404, $"The specified Card Number or Veteran Id doesn't match an enrolled Veteran.")); } var scan = ScanRepository.Get(eventId, veteran.Id, serviceId); if (scan == default(Scan)) { return(StatusCode(404, $"A Scan matching the specified information could not be found.")); } try { ScanRepository.Delete(eventId, veteran.Id, serviceId); return(NoContent()); } catch (Exception ex) { throw new Exception($"Error deleting the Scan matching the specified information: {ex.Message}. See inner Exception for details.", ex); } }
public IActionResult GetCheckIn(Guid eventId, string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest($"The card or veteran ID is null or empty.")); } var veteran = default(Veteran); if (int.TryParse(id, out var cardNumber)) { veteran = VeteranRepository .GetAll(new VeteranFilters() { CardNumber = cardNumber }) .SingleOrDefault(); } else if (Guid.TryParse(id, out var veteranId)) { veteran = VeteranRepository.Get(veteranId); } else { return(BadRequest($"The provided ID is neither a Card Number nor Veteran ID.")); } if (veteran == default(Veteran)) { return(StatusCode(404, $"The specified Card Number or Veteran Id doesn't match an enrolled Veteran.")); } var scan = ScanRepository.Get(eventId, veteran.Id, Guid.Empty); if (scan == default(Scan)) { return(StatusCode(404, $"The Veteran has not checked in for this Event.")); } return(Ok(scan)); }
public IActionResult Scan([FromBody] ScanRequest scan) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetReadableString())); } if (!int.TryParse(scan.CardNumber, out var cardNumber)) { return(BadRequest($"Card Number {scan.CardNumber} is not a valid integer.")); } var @event = EventRepository.Get((Guid)scan.EventId); if (@event == default(Event)) { StatusCode(404, "The specified Event could not be found."); } var service = ServiceRepository.Get(scan.ServiceId); if (service == default(Service)) { return(StatusCode(404, "The specified Service could not be found.")); } var veteran = VeteranRepository .GetAll(new VeteranFilters() { CardNumber = cardNumber, IncludePhotoBase64 = true }) .SingleOrDefault(); if (veteran == default(Veteran)) { return(StatusCode(404, $"Card Number {scan.CardNumber} doesn't match an enrolled Veteran.")); } var previousScans = ScanRepository.GetAll(new ScanFilters() { EventId = scan.EventId, VeteranId = veteran.Id }); var existingCheckIn = previousScans.Where(s => s.ServiceId == Guid.Empty).SingleOrDefault(); var scanRecord = new Scan() { EventId = (Guid)scan.EventId, VeteranId = veteran.Id, ServiceId = scan.ServiceId, ScanById = User.GetId(), ScanDate = DateTime.UtcNow, PlusOne = scan.PlusOne, }; // check in scan if (scan.ServiceId == Guid.Empty) { if (existingCheckIn == default(Scan)) { return(CreateScan(scanRecord, veteran)); } else if (existingCheckIn.PlusOne != scanRecord.PlusOne) { return(UpdateScan(scanRecord, veteran)); } else { return(Conflict(new ScanError(existingCheckIn, veteran, "Duplicate Scan"))); } } // service scan if (existingCheckIn == default(Scan)) { return(StatusCode(403, new ScanError(scanRecord, veteran, "The Veteran has not checked in for this Event."))); } if (scanRecord.PlusOne && !existingCheckIn.PlusOne) { return(StatusCode(403, new ScanError(scanRecord, veteran, "The Veteran did not check in with a +1."))); } var previousServiceScan = previousScans.Where(s => s.ServiceId == scan.ServiceId).SingleOrDefault(); if (previousServiceScan != default(Scan)) { return(Conflict(new ScanError(previousServiceScan, veteran, "Duplicate Scan"))); } return(CreateScan(scanRecord, veteran)); }
public IActionResult GetAll([FromQuery] ScanFilters filters) { return(Ok(ScanRepository.GetAll(filters))); }
public void GetScansByRegistration() { var rep = new ScanRepository(); var scans = rep.ListByRegistration(new Guid("1B7FC4C9-ECBB-426A-9263-D59449958313")); }