changed tests to use streets with at least two points and compare assertions via JSON Fluent Assertions
This commit is contained in:
parent
dc122ec2d9
commit
90df1edf75
@ -1,5 +1,8 @@
|
|||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
using FluentAssertions.Json;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
||||||
{
|
{
|
||||||
@ -26,9 +29,11 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
{
|
{
|
||||||
name = "Kaiserstraße",
|
name = "Kaiserstraße",
|
||||||
capacity = 100,
|
capacity = 100,
|
||||||
geometry = new[] { new { x = 10, y = 20 } }
|
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);
|
var post_response = await client.PostAsJsonAsync("/api/streets/", street);
|
||||||
|
|
||||||
post_response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
|
post_response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
|
||||||
@ -37,9 +42,11 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
|
|
||||||
get_response.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
get_response.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
||||||
|
|
||||||
var responseContent = await get_response.Content.ReadFromJsonAsync<object>();
|
var expected_street = JObject.Parse(JsonConvert.SerializeObject(street));
|
||||||
|
|
||||||
street.Should().BeEquivalentTo(responseContent);
|
var response_street = JObject.Parse(await get_response.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
|
response_street.Should().BeEquivalentTo(expected_street);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -49,7 +56,7 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
{
|
{
|
||||||
name = "Adenauerring",
|
name = "Adenauerring",
|
||||||
capacity = 100,
|
capacity = 100,
|
||||||
geometry = new[] { new { x = 10, y = 20 } }
|
geometry = new[] { new { x = 10, y = 20 }, new { x = 50, y = 70 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
await client.PostAsJsonAsync("/api/streets/", street);
|
await client.PostAsJsonAsync("/api/streets/", street);
|
||||||
@ -58,7 +65,7 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
{
|
{
|
||||||
name = "Adenauerring",
|
name = "Adenauerring",
|
||||||
capacity = 200,
|
capacity = 200,
|
||||||
geometry = new[] { new { x = 30, y = 40 } }
|
geometry = new[] { new { x = 30, y = 40 }, new { x = 100, y = 150 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
var response = await client.PostAsJsonAsync("/api/streets", duplicate_street);
|
var response = await client.PostAsJsonAsync("/api/streets", duplicate_street);
|
||||||
@ -71,7 +78,7 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
{
|
{
|
||||||
var response = await client.GetAsync("/api/streets/Englerstraße");
|
var response = await client.GetAsync("/api/streets/Englerstraße");
|
||||||
|
|
||||||
response.StatusCode.Should().Be(System.Net.HttpStatusCode.NoContent);
|
response.StatusCode.Should().Be(System.Net.HttpStatusCode.NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -81,7 +88,7 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
{
|
{
|
||||||
name = "Moltkestraße",
|
name = "Moltkestraße",
|
||||||
capacity = 100,
|
capacity = 100,
|
||||||
geometry = new[] { new { x = 10, y = 20 } }
|
geometry = new[] { new { x = 10, y = 20 }, new { x = 50, y = 100 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
await client.PostAsJsonAsync("/api/streets/", street);
|
await client.PostAsJsonAsync("/api/streets/", street);
|
||||||
@ -115,7 +122,7 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
{
|
{
|
||||||
name = "Ettlingerstraße",
|
name = "Ettlingerstraße",
|
||||||
capacity = 50,
|
capacity = 50,
|
||||||
geometry = new[] { new { x = 5, y = 3 } }
|
geometry = new[] { new { x = 5, y = 3 }, new { x = 6, y = 4 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
await client.PostAsJsonAsync("/api/streets/", street);
|
await client.PostAsJsonAsync("/api/streets/", street);
|
||||||
@ -133,22 +140,25 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
|
|
||||||
get_response_no_method.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
get_response_no_method.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
||||||
|
|
||||||
var content_no_method = get_response_no_method.Content.ReadFromJsonAsync<object>();
|
var expected_street_no_method = new
|
||||||
|
|
||||||
var expected_content_no_method = new
|
|
||||||
{
|
{
|
||||||
name = "Ettlingerstraße",
|
name = "Ettlingerstraße",
|
||||||
capacity = 50,
|
capacity = 50,
|
||||||
geometry = new[] { new { x = 5, y = 3 }, new { x = 15, y = 30 } }
|
geometry = new[] { new { x = 5, y = 3 }, new { x = 6, y = 4 }, new { x = 15, y = 30 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
expected_content_no_method.Should().BeEquivalentTo(content_no_method);
|
var expected_street_json = JObject.Parse(JsonConvert.SerializeObject(expected_street_no_method));
|
||||||
|
|
||||||
|
var response_street_no_method = JObject.Parse(await get_response_no_method.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
|
response_street_no_method.Should().BeEquivalentTo(expected_street_json);
|
||||||
|
|
||||||
|
|
||||||
// Test with "Backend" method
|
// Test with "Backend" method
|
||||||
var update_backend = new
|
var update_backend = new
|
||||||
{
|
{
|
||||||
Point = new { x = 20, y = 35 },
|
Point = new { x = 20, y = 35 },
|
||||||
Method = "Backend"
|
usePostGIS = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
var patch_response_backend = await client.PatchAsJsonAsync("/api/streets/Ettlingerstraße", update_backend);
|
var patch_response_backend = await client.PatchAsJsonAsync("/api/streets/Ettlingerstraße", update_backend);
|
||||||
@ -159,43 +169,35 @@ public class APITests : IClassFixture<StreetWebApplicationFactory<Program>>
|
|||||||
var update_postgis = new
|
var update_postgis = new
|
||||||
{
|
{
|
||||||
Point = new { x = 25, y = 40 },
|
Point = new { x = 25, y = 40 },
|
||||||
Method = "PostGIS"
|
usePostGIS = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var patch_response_postgis = await client.PatchAsJsonAsync("/api/streets/Ettlingerstraße", update_postgis);
|
var patch_response_postgis = await client.PatchAsJsonAsync("/api/streets/Ettlingerstraße", update_postgis);
|
||||||
|
|
||||||
patch_response_postgis.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
patch_response_postgis.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
||||||
|
|
||||||
// Test with "Database" method
|
|
||||||
var update_database = new
|
|
||||||
{
|
|
||||||
Point = new { x = 30, y = 45 },
|
|
||||||
Method = "Database"
|
|
||||||
};
|
|
||||||
|
|
||||||
var patch_response_database = await client.PatchAsJsonAsync("/api/streets/Ettlingerstraße", update_database);
|
|
||||||
|
|
||||||
patch_response_database.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
|
||||||
|
|
||||||
var get_response_final = await client.GetAsync("/api/streets/Ettlingerstraße");
|
var get_response_final = await client.GetAsync("/api/streets/Ettlingerstraße");
|
||||||
|
|
||||||
get_response_final.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
get_response_final.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
|
||||||
|
|
||||||
var content_final = await get_response_final.Content.ReadFromJsonAsync<object>();
|
var expected_street_final = new
|
||||||
var expected_content_final = new
|
|
||||||
{
|
{
|
||||||
name = "Ettlingerstraße",
|
name = "Ettlingerstraße",
|
||||||
capacity = 50,
|
capacity = 50,
|
||||||
geometry = new[]
|
geometry = new[]
|
||||||
{
|
{
|
||||||
new { x = 5, y = 3 },
|
new { x = 5, y = 3 },
|
||||||
|
new { x = 6, y = 4 },
|
||||||
new { x = 15, y = 30 },
|
new { x = 15, y = 30 },
|
||||||
new { x = 20, y = 35 },
|
new { x = 20, y = 35 },
|
||||||
new { x = 25, y = 40 },
|
new { x = 25, y = 40 },
|
||||||
new { x = 30, y = 45 }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expected_content_final.Should().BeEquivalentTo(content_final);
|
var expected_street = JObject.Parse(JsonConvert.SerializeObject(expected_street_final));
|
||||||
|
|
||||||
|
var response_street = JObject.Parse(await get_response_final.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
|
response_street.Should().BeEquivalentTo(expected_street);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user