public IActionResult CreateVehicleIncident([FromBody] CreateVehicleIncidentForm payload) { var newVehicleIncident = new VehicleIncident { VIN = payload.VIN, DateTime = Convert.ToDateTime(payload.DateTime), Note = payload.Note }; if (_dbContext.ContainsIncident(newVehicleIncident)) { return(BadRequest()); } SetAttributes(newVehicleIncident); _dbContext.VehicleIncidents.Add(newVehicleIncident); _dbContext.SaveChanges(); return(CreatedAtAction(nameof(VehicleIncident), new { vin = newVehicleIncident.VIN }, newVehicleIncident)); }
public void TestAttributes_HoldLookedUpValuesInMemory() { using (var _dbContext = new VehicleIncidentContext(CreateNewContextOptions())) { VINAttributes attributes; VINDecodeService decodeService = new VINDecodeService(); string vinToLookup = "1FTNW21P04EB82562"; attributes = decodeService.GetAttributes(vinToLookup).Result; _dbContext.VINAttributes.Add(attributes); _dbContext.SaveChanges(); _dbContext.ContainsAttributes(vinToLookup).Should().BeTrue(); } }
public void TestAddIncident() { using (var _dbContext = new VehicleIncidentContext(CreateNewContextOptions())) { var newVehicleIncident = new VehicleIncident { VIN = "1FTNW21P04EB82562", DateTime = DateTime.Today, Note = "Hit a pole", Model = "F-250", Make = "FORD", Year = 2004 }; _dbContext.VehicleIncidents.Add(newVehicleIncident); _dbContext.SaveChanges(); var incidents = _dbContext.VehicleIncidents.ToList(); incidents.Should().ContainSingle(x => x.VIN == "1FTNW21P04EB82562"); } }