Events-MVC (example with htmx)

This commit is contained in:
Boris Milašinović
2026-04-25 22:21:35 +02:00
parent eb04483417
commit 0ee1b22f61
114 changed files with 7966 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
using System.Net;
using Events.Tests.IntegrationTests.Infrastructure;
namespace Events.Tests.IntegrationTests;
public class CountriesCrudShould
{
[Fact]
public async Task CreateCountry()
{
await using var factory = new CustomWebApplicationFactory();
using var client = factory.CreateClient();
var response = await AntiforgeryRequestHelper.PostFormAsync(
client,
"/Countries",
"/Countries/Create",
[
new("Code", "DE"),
new("Alpha3", "DEU"),
new("Name", "Germany"),
new("Translations[0].LanguageCode", "hr"),
new("Translations[0].Name", "Germany")
]);
var html = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Contains("Germany", html);
}
[Fact]
public async Task EditCountry()
{
await using var factory = new CustomWebApplicationFactory(ctx => ctx.Countries.Add(TestDataSeederCountry()));
using var client = factory.CreateClient();
var response = await AntiforgeryRequestHelper.PostFormAsync(
client,
"/Countries",
"/Countries/Edit/HR",
[
new("Code", "HR"),
new("Alpha3", "HRV"),
new("Name", "Republic of Croatia"),
new("Translations[0].LanguageCode", ""),
new("Translations[0].Name", "")
]);
var html = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Contains("Republic of Croatia", html);
}
[Fact]
public async Task DeleteCountry()
{
await using var factory = new CustomWebApplicationFactory(ctx => ctx.Countries.Add(TestDataSeederCountry()));
using var client = factory.CreateClient();
var response = await AntiforgeryRequestHelper.PostFormAsync(client, "/Countries", "/Countries/Delete/HR", []);
var html = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.DoesNotContain("Croatia", html);
}
private static Events.EF.Models.Country TestDataSeederCountry()
{
return new()
{
Code = "HR",
Alpha3 = "HRV",
Name = "Croatia"
};
}
}