Compare commits
3 Commits
3d0d9faf12
...
ce4e5848db
| Author | SHA1 | Date | |
|---|---|---|---|
| ce4e5848db | |||
| 421d33df99 | |||
| 418153ffce |
@ -17,7 +17,7 @@ public class StreetController : ControllerBase
|
||||
public async Task<IActionResult> CreateStreet([FromBody] CreateStreetDTO dto)
|
||||
{
|
||||
if (dto == null)
|
||||
return BadRequest("Invalid request body.");
|
||||
return BadRequest();
|
||||
|
||||
try
|
||||
{
|
||||
@ -28,9 +28,9 @@ public class StreetController : ControllerBase
|
||||
|
||||
return Created();
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
catch
|
||||
{
|
||||
return Conflict(ex);
|
||||
return Conflict();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,9 +43,9 @@ public class StreetController : ControllerBase
|
||||
var street = await StreetService.GetStreetAsync(streetname);
|
||||
return Ok(street);
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
catch
|
||||
{
|
||||
return NotFound(ex);
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class StreetController : ControllerBase
|
||||
{
|
||||
var deleted = await StreetService.DeleteStreetAsync(streetname);
|
||||
if (!deleted)
|
||||
return NotFound($"Street '{streetname}' not found.");
|
||||
return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
@ -65,24 +65,24 @@ public class StreetController : ControllerBase
|
||||
public async Task<IActionResult> AddPoint(string streetname, [FromBody] AddPointDTO dto)
|
||||
{
|
||||
if (dto == null)
|
||||
return BadRequest("Invalid request body.");
|
||||
return BadRequest();
|
||||
|
||||
try
|
||||
{
|
||||
await StreetService.AddPointAsync(streetname, StreetService.ToGeometryPoint(dto.Point), dto.usePostGIS);
|
||||
return Ok();
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
return NotFound(ex);
|
||||
return NotFound();
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return BadRequest(ex);
|
||||
return BadRequest();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Conflict("Concurrency conflict. Please retry your request.");
|
||||
return Conflict();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,8 +32,6 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
||||
geometry = new[] { new { x = 10, y = 20 }, new { x = 15, y = 25 } }
|
||||
};
|
||||
|
||||
Console.WriteLine(JsonConvert.SerializeObject(street));
|
||||
|
||||
var post_response = await client.PostAsJsonAsync("/api/streets/", street);
|
||||
|
||||
post_response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
|
||||
|
||||
@ -18,6 +18,12 @@ public class StreetWebApplicationFactory<Program> : WebApplicationFactory<Progra
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
|
||||
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<StreetDbContext>));
|
||||
if (descriptor != null)
|
||||
{
|
||||
services.Remove(descriptor);
|
||||
}
|
||||
|
||||
// Use the test database
|
||||
services.AddDbContext<StreetDbContext>(options => options.UseNpgsql(dbTestContainer.GetConnectionString(), o => o.UseNetTopologySuite()));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user