namespace UnitTestsEntities; using Xunit; using System.Linq; using Entities; using Microsoft.EntityFrameworkCore; using StubbedContextLib; public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture { [Fact] public void Add_Athlete_Success() { var athlete = new AthleteEntity { Username = "john_doe", LastName = "Doe", FirstName = "John", Email = "john.doe@example.com", Sexe = "M", Length = 180.0, Weight = 75.5f, Password = "password", DateOfBirth = new DateOnly(1990, 1, 1), IsCoach = false }; using (var context = new TrainingStubbedContext(fixture._options)) { context.Database.EnsureCreated(); context.AthletesSet.Add(athlete); context.SaveChanges(); } using (var context = new TrainingStubbedContext(fixture._options)) { var savedAthlete = context.AthletesSet.First(a => a.Username == "john_doe"); Assert.NotNull(savedAthlete); Assert.Equal("john_doe", savedAthlete.Username); } } [Fact] public void Update_Athlete_Success() { var athlete = new AthleteEntity { Username = "jane_smith", LastName = "Smith", FirstName = "Jane", Email = "jane.smith@example.com", Sexe = "F", Length = 165.0, Weight = 60.0f, Password = "password123", DateOfBirth = new DateOnly(1995, 5, 10), IsCoach = false }; using (var context = new TrainingStubbedContext(fixture._options)) { context.Database.EnsureCreated(); context.AthletesSet.Add(athlete); context.SaveChanges(); } using (var context = new TrainingStubbedContext(fixture._options)) { var savedAthlete = context.AthletesSet.First(a => a.Username == "jane_smith"); savedAthlete.Username = "jane_doe"; context.SaveChanges(); } using (var context = new TrainingStubbedContext(fixture._options)) { var updatedAthlete = context.AthletesSet.First(a => a.Username == "jane_doe"); Assert.NotNull(updatedAthlete); Assert.Equal("jane_doe", updatedAthlete.Username); Assert.Equal("Smith", updatedAthlete.LastName); } } [Fact] public void Delete_Athlete_Success() { var athlete = new AthleteEntity { Username = "test_user", LastName = "Test", FirstName = "User", Email = "test.user@example.com", Sexe = "M", Length = 170.0, Weight = 70.0f, Password = "testpassword", DateOfBirth = new DateOnly(1985, 10, 20), IsCoach = false }; using (var context = new TrainingStubbedContext(fixture._options)) { context.Database.EnsureCreated(); context.AthletesSet.Add(athlete); context.SaveChanges(); } using (var context = new TrainingStubbedContext(fixture._options)) { var savedAthlete = context.AthletesSet.First(a => a.Username == "test_user"); context.AthletesSet.Remove(savedAthlete); context.SaveChanges(); } using (var context = new TrainingStubbedContext(fixture._options)) { var deletedAthlete = context.AthletesSet.FirstOrDefault(a => a.Username == "test_user"); Assert.Null(deletedAthlete); } } }