public async Task Handle_WhenIncidentClientReturnsSuccessful_ReturnCorrectIncidents() { string expectedIncidentTitle = "The thing we were looking for"; var expectedIncident = new NewIncident { Title = expectedIncidentTitle, PrimaryTicket = new Ticket() { OriginId = "testOnlyPleaseIgnore" } }; var serviceUnderTest = new PostIncidentHandler( await MockFactory .IncidentContext(nameof(Handle_WhenIncidentClientReturnsSuccessful_ReturnCorrectIncidents)) .ConfigureAwait(continueOnCapturedContext: false)); var request = new PostIncidentRequest(expectedIncident, new DummyAuthenticatedUserContext()); var result = await serviceUnderTest .Handle(request, new System.Threading.CancellationToken()) .ConfigureAwait(continueOnCapturedContext: false); Assert.AreEqual(expectedIncidentTitle, result.Title); }
public async Task <IActionResult> Post([FromBody] NewIncident incident) { var result = await _mediator.Send(new PostIncidentRequest(incident, _authContext)); if (result == null) { return(NotFound($"{nameof(Incident)} not found")); } var newUrl = _urlHelper.Link(EventsController.GetMultipleRouteName, new { incidentId = result.Id }); Response.Headers.AddLinksHeader(CreateLinks(result.Id.ToString(), null, PostSingleRouteName)); return(Created(newUrl, result)); }
public async Task <IActionResult> Post([FromBody] NewIncident incident) { var result = await _mediator .Send(new PostIncidentRequest(incident, AuthContext)) .ConfigureAwait(continueOnCapturedContext: false); ILinksHeader getLinks(Incident res) => Links.CreateLinks(res.Id); Uri getRetrievalRoute(Incident res) => new Uri(_urlHelper.Link(IncidentRoutes.GetSingle, new { incidentId = res.Id })); return(CreatedIfExists(result, getRetrievalRoute, getLinks)); }
public void CreateNewIncident() { if (NewIncident.ValidValues()) { IsWorking = true; NewIncident.AnimalID = AnimalID; NewIncident.SaveIncident(); Filter(); IsWorking = false; ClearNewIncident(); MessageBox.Show("Záznam vytvořen."); } else { MessageBox.Show("Vyplňte prosím datum."); } }
public override async Task <IEnumerable <Incident> > Handle( GetIncidentsByTicketCreateIfNeededRequest message, CancellationToken cancellationToken ) { var incidents = await _context.Incidents .WithEagerLoading() .Where(incident => incident .Tickets .Any(inc => inc.OriginId == message.TicketId)) .ProjectTo <Incident>() .ToListAsync(cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); if (incidents.Any()) { AttachTickets(incidents); return(incidents); } var newIncident = new NewIncident { PrimaryTicket = new Ticket { TicketingSystemId = 1, OriginId = message.TicketId } }; var dataIncident = Mapper.Map <Data.Incidents.Models.Incident>(newIncident); var result = _context.Incidents.Add(dataIncident); await _context.SaveChangesAsync(cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); var incidentDto = Mapper.Map <Incident>(result.Entity); AttachTickets(incidentDto); return(new List <Incident> { incidentDto }); }
public ActionResult <IncidentSummary> Create(NewIncident newIncident) { string part = Guid.NewGuid().ToString().Substring(0, 6).ToUpper(); newIncident.PropertyName = $"Fake Property {newIncident.PropertyCode}"; var incident = new IncidentSummary { ReferenceCode = $"I-{part}-19", Location = new LocationInfo { PropertyName = newIncident.PropertyName }, ReportedBy = newIncident.ReportedBy, IncidentDate = newIncident.IncidentDate, DateReported = newIncident.DateReported, Description = newIncident.Description }; items.Add(incident); return(CreatedAtAction(nameof(GetIncident), new { id = incident.ReferenceCode }, incident)); }
public PostIncidentRequest(NewIncident incident, AuthenticatedUserContext userContext) : base(userContext) { Incident = ThrowIf.Null(incident, nameof(incident)); }
public PostIncidentRequest(NewIncident incident, AuthenticatedUserContext userContext) : base(userContext) { Incident = incident; }