auth working

pull/10/head
David D'ALMEIDA 1 year ago
parent dff77f80c5
commit 49110b2e47

@ -7,6 +7,8 @@
//-----------------------------------------------------------------------
using Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace DbContextLib
@ -14,7 +16,7 @@ namespace DbContextLib
/// <summary>
/// Represents the database context for the FitnessApp.
/// </summary>
public class HeartTrackContext : DbContext
public class HeartTrackContext : IdentityDbContext<AthleteEntity,IdentityRole<int>,int>
{
/// <summary>
/// Gets or sets the set of athletes.
@ -132,10 +134,10 @@ namespace DbContextLib
//primary key of AthleteEntity
modelBuilder.Entity<AthleteEntity>()
.HasKey(at => at.IdAthlete);
.HasKey(at => at.Id);
//generation mode (at insertion)
modelBuilder.Entity<AthleteEntity>()
.Property(at => at.IdAthlete)
.Property(at => at.Id)
.ValueGeneratedOnAdd();
// add image column type
// modelBuilder.Entity<AthleteEntity>()
@ -234,6 +236,12 @@ namespace DbContextLib
.WithOne(at => at.DataSource)
.HasForeignKey(at => at.DataSourceId)
.IsRequired(false);
List<IdentityRole> roles = new List<IdentityRole>
{
new ("Athlete"),
new ("Coach")
};
modelBuilder.Entity<IdentityRole>().HasData(roles);
}
}
}

@ -1,25 +0,0 @@
using Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace DbContextLib.Identity;
public class AuthDbContext: IdentityDbContext<IdentityUser>
{
public AuthDbContext(DbContextOptions<AuthDbContext> options) : base(options) { }
public AuthDbContext() { }
/*
/// <summary>
/// Configures the database options if they are not already configured.
/// </summary>
/// <param name="optionsBuilder">The options builder instance.</param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite($"Data Source=uca.HeartTrack.db");
}
}*/
}

@ -13,14 +13,14 @@ public static class UserMappeur
{
Func<AthleteEntity, User> create = athleteEntity => new User
{
Id = athleteEntity.IdAthlete,
Id = athleteEntity.Id,
FirstName = athleteEntity.FirstName,
LastName = athleteEntity.LastName,
Email = athleteEntity.Email,
MotDePasse = athleteEntity.Password,
MotDePasse = athleteEntity.PasswordHash,
DateOfBirth = athleteEntity.DateOfBirth.ToDateTime(TimeOnly.MinValue),
Sexe = athleteEntity.Sexe,
Username = athleteEntity.Username,
Username = athleteEntity.UserName,
Weight = athleteEntity.Weight,
Lenght = (float)athleteEntity.Length,
ProfilePicture = athleteEntity.ProfilPicture,
@ -42,13 +42,13 @@ public static class UserMappeur
{
Func<User, AthleteEntity> create = user => new AthleteEntity
{
IdAthlete = user.Id,
Username = user.Username,
Id = user.Id,
UserName = user.Username,
Sexe = user.Sexe,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Password = user.MotDePasse,
PasswordHash = user.MotDePasse,
DateOfBirth = DateOnly.FromDateTime(user.DateOfBirth),
IsCoach = user.Role is Coach,
Weight = user.Weight,

@ -8,56 +8,58 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Identity;
namespace Entities
{
//dentityRole<int>,int
/// <summary>
/// Represents an athlete entity in the database.
/// </summary>
[Table("Athlete")]
public class AthleteEntity
public class AthleteEntity : IdentityUser<int>
{
/// <summary>
/// Gets or sets the unique identifier of the athlete.
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdAthlete { get; set; }
public override int Id { get; set; }
/// <summary>
/// Gets or sets the username of the athlete.
/// </summary>
[MaxLength(100)]
[Required(ErrorMessage = "Athlete Username is ")]
public required string Username { get; set; }
public override string UserName { get; set; }
/// <summary>
/// Gets or sets the last name of the athlete.
/// </summary>
[MaxLength(100)]
[Required(ErrorMessage = "Athlete Last Name is ")]
public required string LastName { get; set; }
public string LastName { get; set; }
/// <summary>
/// Gets or sets the first name of the athlete.
/// </summary>
[MaxLength(150)]
[Required(ErrorMessage = "Athlete First Name is ")]
public required string FirstName { get; set; }
public string FirstName { get; set; }
/// <summary>
/// Gets or sets the email of the athlete.
/// </summary>
[MaxLength(100)]
[Required(ErrorMessage = "Athlete Email is ")]
public required string Email { get; set; }
public override string Email { get; set; }
/// <summary>
/// Gets or sets the gender of the athlete.
/// </summary>
[MaxLength(1)]
[Required(ErrorMessage = "Athlete Sexe is ")]
public required string Sexe { get; set; }
public string Sexe { get; set; }
/// <summary>
/// Gets or sets the height of the athlete.
@ -68,12 +70,12 @@ namespace Entities
/// Gets or sets the weight of the athlete.
/// </summary>
public float Weight { get; set; }
/*
/// <summary>
/// Gets or sets the password of the athlete.
/// </summary>
[Required(ErrorMessage = "Athlete Password is ")]
public required string Password { get; set; }
[Required(ErrorMessage = "Athlete PasswordHash is ")]
public string PasswordHash { get; set; }*/
/// <summary>
/// Gets or sets the date of birth of the athlete.

@ -5,4 +5,14 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Identity.Stores">
<HintPath>..\..\..\.nuget\packages\microsoft.extensions.identity.stores\8.0.2\lib\net8.0\Microsoft.Extensions.Identity.Stores.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

@ -11,4 +11,10 @@
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Identity.Stores">
<HintPath>..\..\..\.nuget\packages\microsoft.extensions.identity.stores\8.0.2\lib\net8.0\Microsoft.Extensions.Identity.Stores.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

@ -21,14 +21,14 @@ public static class UserMappeur
{
Func<AthleteEntity, UserTinyDto> create = athleteEntity => new UserTinyDto
{
Id = athleteEntity.IdAthlete,
Id = athleteEntity.Id,
FirstName = athleteEntity.FirstName,
LastName = athleteEntity.LastName,
Email = athleteEntity.Email,
Password = athleteEntity.Password,
Password = athleteEntity.PasswordHash,
DateOfBirth = athleteEntity.DateOfBirth.ToDateTime(TimeOnly.MinValue),
Sexe = athleteEntity.Sexe,
Username = athleteEntity.Username,
Username = athleteEntity.UserName,
Weight = athleteEntity.Weight,
Lenght = (float)athleteEntity.Length,
ProfilePicture = athleteEntity.ProfilPicture ?? "",
@ -42,13 +42,13 @@ public static class UserMappeur
{
Func<UserTinyDto, AthleteEntity> create = user => new AthleteEntity
{
IdAthlete = user.Id,
Username = user.Username,
Id = user.Id,
UserName = user.Username,
Sexe = user.Sexe,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Password = user.Password ?? "",
PasswordHash = user.Password ?? "",
DateOfBirth = DateOnly.FromDateTime(user.DateOfBirth),
IsCoach = user.IsCoach,
Weight = user.Weight,
@ -63,14 +63,14 @@ public static class UserMappeur
{
Func<AthleteEntity, ResponseUserDto> creator = athleteEntity => new ResponseUserDto
{
Id = athleteEntity.IdAthlete,
Id = athleteEntity.Id,
FirstName = athleteEntity.FirstName,
LastName = athleteEntity.LastName,
Email = athleteEntity.Email,
Password = athleteEntity.Password,
Password = athleteEntity.PasswordHash,
DateOfBirth = athleteEntity.DateOfBirth.ToDateTime(TimeOnly.MinValue),
Sexe = athleteEntity.Sexe,
Username = athleteEntity.Username,
Username = athleteEntity.UserName,
Weight = athleteEntity.Weight,
Lenght = (float)athleteEntity.Length,
ProfilePicture = athleteEntity.ProfilPicture ?? "",

@ -27,7 +27,7 @@ public class ActivityController : Controller
}
[HttpGet]
[ProducesResponseType(typeof(PageResponse<ActivityDto>), 200)]
[ProducesResponseType(typeof(PageResponse<ActivityTinyDto>), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public async Task<ActionResult<PageResponse<ActivityTinyDto>>> GetActivities([FromQuery] PageRequest pageRequest)

@ -6,7 +6,7 @@ namespace HeartTrackAPI.Controllers;
[ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")]
public class AnalysisController : ControllerBase
public class AnalysisController : Controller
{
private readonly List<HeartRateZone> _heartRateZones = new()
{
@ -35,7 +35,26 @@ public class AnalysisController : ControllerBase
heartRates.Count(hr => hr.HeartRate >= zone.MinHeartRate && hr.HeartRate <= zone.MaxHeartRate);
return TimeSpan.FromSeconds(secondsInZone);
}
/*
[HttpGet("getOptimizedPath")]
public IActionResult GetOptimizedPath(int activityId)
{
var heartRateData = GetMockHeartRateData();
var sortedData = heartRateData.OrderBy(x => x.Timestamp).ToList();
var path = new GeoJsonPath();
foreach (var item in sortedData)
{
if (item.Latitude.HasValue && item.Longitude.HasValue)
{
path.Coordinates.Add(new GeoJsonCoordinate(item.Longitude.Value, item.Latitude.Value));
}
}
return Ok(path.ToGeoJson());
}
*/
private List<HeartRateTinyDto> GetMockHeartRateData()
{
var random = new Random();

@ -361,24 +361,5 @@ public class UsersController : Controller
}
}*/
/// <summary>
/// Déconnecte l'utilisateur actuel.
/// </summary>
/// <param name="signInManager">Le gestionnaire de connexion.</param>
/// <param name="empty">Paramètre vide utilisé pour s'assurer que la requête provient bien d'un client.</param>
/// <returns>Action result.</returns>
/// <response code="200">Déconnexion réussie.</response>
/// <response code="401">Déconnexion non autorisée.</response>
/// <response code="500">Erreur interne du serveur.</response>
[HttpPost("logout")]
[ProducesResponseType(200)]
[ProducesResponseType(401)]
[ProducesResponseType(500)]
public async Task<IActionResult> Logout(SignInManager<IdentityUser> signInManager, [FromBody] object? empty)
{
if (empty == null) return Unauthorized();
await signInManager.SignOutAsync();
return Ok();
}
}

@ -10,11 +10,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

@ -1,11 +1,12 @@
using System.Reflection;
using DbContextLib;
using DbContextLib.Identity;
using Entities;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Model.Manager;
using Model2Entities;
@ -20,14 +21,17 @@ public class AppBootstrap(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddEndpointsApiExplorer();
AddSwagger(services);
AddHeartTrackContextServices(services);
AddModelService(services);
AddIdentityServices(services);
AddIdentityServices(services,configuration);
AddApiVersioning(services);
services.AddHealthChecks();
}
private void AddHeartTrackContextServices(IServiceCollection services)
@ -47,7 +51,6 @@ public class AppBootstrap(IConfiguration configuration)
Console.WriteLine("========RUNNING USING THE MYSQL SERVER==============");
Console.WriteLine(connectionString);
Console.WriteLine("====================================================");
services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
services.AddDbContext<HeartTrackContext>(options =>
options.UseMySql($"{connectionString}", new MySqlServerVersion(new Version(10, 11, 1)))
, ServiceLifetime.Singleton);
@ -58,13 +61,11 @@ public class AppBootstrap(IConfiguration configuration)
Console.WriteLine(connectionString);
if (!string.IsNullOrWhiteSpace(connectionString))
{
services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
services.AddDbContext<TrainingStubbedContext>(options =>
options.UseSqlite(connectionString), ServiceLifetime.Singleton);
}
else
{
services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
services.AddDbContext<TrainingStubbedContext>();
}
break;
@ -94,14 +95,61 @@ public class AppBootstrap(IConfiguration configuration)
}
}
private void AddIdentityServices(IServiceCollection services)
private void AddIdentityServices(IServiceCollection services, IConfiguration config)
{
// services.AddTransient<IEmailSender<AthleteEntity>, EmailSender>();
services.AddAuthorization();
services.AddIdentityApiEndpoints<AthleteEntity>()
.AddEntityFrameworkStores<TrainingStubbedContext>();
/*services.AddIdentity<AthleteEntity, IdentityRole<int>>(options =>
{
options.PasswordHash.RequireDigit = true;
options.PasswordHash.RequireLowercase = true;
options.PasswordHash.RequireUppercase = true;
options.PasswordHash.RequireNonAlphanumeric = true;
options.PasswordHash.RequiredLength = 8;
})
.AddEntityFrameworkStores<HeartTrackContext>();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme =
options.DefaultChallengeScheme =
options.DefaultForbidScheme =
options.DefaultScheme =
options.DefaultSignInScheme =
options.DefaultSignOutScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
//ValidIssuer =config["JWT:Issuer"],
ValidateAudience = true,
//ValidAudience = config["JWT:Audience"],
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(
System.Text.Encoding.UTF8.GetBytes(config["JWT:SigningKey"])
)
};
});*/
/*
app.UseCors(x => x
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
//.WithOrigins("https://localhost:44351))
.SetIsOriginAllowed(origin => true));*/
services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<AuthDbContext>();
// .AddEntityFrameworkStores<AuthDbContext>().AddDefaultTokenProviders();
// services.AddTransient<IEmailSender<AthleteEntity>, EmailSender>();
// services.AddAuthorization();
// services.AddIdentityApiEndpoints<AthleteEntity>()
// .AddEntityFrameworkStores<HeartTrackContext>();
// .AddEntityFrameworkStores<AuthDbContext>().AddDefaultTokenProviders();
}
private void AddApiVersioning(IServiceCollection services)
@ -122,8 +170,6 @@ public class AppBootstrap(IConfiguration configuration)
{
services.AddSwaggerGen(options =>
{
options.OperationFilter<SwaggerDefaultValues>();
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
@ -155,28 +201,28 @@ public class AppBootstrap(IConfiguration configuration)
};
options.AddSecurityRequirement(scheme);
});
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, SwaggerOptions>();
services.AddSwaggerGen(options =>
{
options.OperationFilter<SwaggerDefaultValues>();
});
});
//services.AddTransient<IConfigureOptions<SwaggerGenOptions>, SwaggerOptions>();
/*
services.AddVersionedApiExplorer(setup =>
{
setup.GroupNameFormat = "'v'VVV";
setup.SubstituteApiVersionInUrl = true;
});
});*/
}
public void Configure(WebApplication app, IWebHostEnvironment env)
{
app.UseHttpsRedirection();
app.MapIdentityApi<IdentityUser>();
app.MapControllers();
app.UseAuthentication();
app.UseAuthorization();
app.MapIdentityApi<AthleteEntity>();
app.MapControllers();
app.MapHealthChecks("/health");

@ -8,5 +8,10 @@
"AllowedHosts": "*",
"ConnectionStrings": {
"HeartTrackAuthConnection": "Data Source=uca_HeartTrack.db"
}
},
"Jwt": {
"Issuer": "HeartTrack",
"Audience": "HeartTrack",
"SigningKey": "ThisIsMySuperKey"
}
}

@ -57,7 +57,7 @@ public partial class DbDataManager
_logger.LogInformation($"GetItemById with id {id}", id);
var userEntity = await _dataManager.DbContext.AthletesSet.IncludeStandardProperties()
.SingleOrDefaultAsync(a => a.IdAthlete == id);
.SingleOrDefaultAsync(a => a.Id == id);
var user = userEntity != null ? userEntity.ToModel() : null;
if (user != null)
_logger.LogInformation($"Retrieved user with ID {id}");
@ -95,7 +95,7 @@ public partial class DbDataManager
{
_logger.LogInformation($"GetTinyItemById with id {id}", id);
var userEntity = await _dataManager.DbContext.AthletesSet.IncludeStandardProperties().Include(a => a.Followers).Include(a => a.Followings)
.SingleOrDefaultAsync(a => a.IdAthlete == id);
.SingleOrDefaultAsync(a => a.Id == id);
var user = userEntity != null ? userEntity.ToResponseDto() : null;
if (user != null)
_logger.LogInformation($"Retrieved user with ID {id}");
@ -199,7 +199,7 @@ public partial class DbDataManager
var userEntity = _dataManager.DbContext.AthletesSet
.Include(a => a.Followings)
.FirstOrDefault(a => a.IdAthlete == fromUser);
.FirstOrDefault(a => a.Id == fromUser);
if (userEntity == null)
{
@ -232,7 +232,7 @@ public partial class DbDataManager
var userEntity = _dataManager.DbContext.AthletesSet
.Include(a => a.Followings)
.FirstOrDefault(a => a.IdAthlete == fromUser);
.FirstOrDefault(a => a.Id == fromUser);
if (userEntity == null)
{
@ -265,7 +265,7 @@ public partial class DbDataManager
var athlete = await _dataManager.DbContext.AthletesSet
.Include(a => a.Followers).ThenInclude(f => f.Follower)
.Include(a => a.Followings).ThenInclude(f => f.Following)
.FirstOrDefaultAsync(a => a.IdAthlete == userId); // Use async version for better performance
.FirstOrDefaultAsync(a => a.Id == userId); // Use async version for better performance
if (athlete == null)
{
@ -299,7 +299,7 @@ public partial class DbDataManager
var athlete = await _dataManager.DbContext.AthletesSet
.Include(a => a.Followers).ThenInclude(f => f.Follower)
.Include(a => a.Followings).ThenInclude(f => f.Following)
.FirstOrDefaultAsync(a => a.IdAthlete == userId);
.FirstOrDefaultAsync(a => a.Id == userId);
if (athlete == null)
{

@ -42,11 +42,11 @@ namespace StubbedContextLib
modelBuilder.Entity<LargeImageEntity>().HasData(picture);
modelBuilder.Entity<AthleteEntity>().HasData(
new AthleteEntity { IdAthlete = 1, Username = "Doe",ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,LastName = "Doe", FirstName = "John", Email = "john.doe@example.com", Password = "password123", Sexe = "M", Length = 1.80, Weight = 75, DateOfBirth = new DateOnly(1990, 01, 01), IsCoach = true , DataSourceId = 1},
new AthleteEntity { IdAthlete = 2, Username = "Smith",ProfilPicture = picture2,LastName = "Smith", FirstName = "Jane", Email = "jane.smith@exemple.com", Password = "secure456", Sexe = "F", Length = 1.65, Weight = 60, DateOfBirth = new DateOnly(1995, 01, 01), IsCoach = false, DataSourceId = 1 },
new AthleteEntity { IdAthlete = 3, Username = "Martin",ProfilPicture = picture2,ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,LastName = "Martin", FirstName = "Paul", Email = "paul.martin@example.com", Password = "super789", Sexe = "M", Length = 1.75, Weight = 68, DateOfBirth = new DateOnly(1992, 01, 01), IsCoach = true, DataSourceId = 1},
new AthleteEntity { IdAthlete = 4, Username = "Brown",ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"),LastName = "Brown", FirstName = "Anna", Email = "anna.brown@example.com", Password = "test000", Sexe = "F", Length = 1.70, Weight = 58, DateOfBirth = new DateOnly(1993, 01, 01), IsCoach = false, DataSourceId = 2 },
new AthleteEntity { IdAthlete = 5, Username = "Lee", ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"),LastName = "Lee", FirstName = "Bruce", Email = "bruce.lee@example.com", Password = "hello321", Sexe = "M", Length = 2.0, Weight = 90, DateOfBirth = new DateOnly(1991, 01, 01), IsCoach = false, DataSourceId = 3 }
new AthleteEntity { Id = 1, UserName = "Doe",ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,LastName = "Doe", FirstName = "John", Email = "john.doe@example.com", PasswordHash = "password123", Sexe = "M", Length = 1.80, Weight = 75, DateOfBirth = new DateOnly(1990, 01, 01), IsCoach = true , DataSourceId = 1},
new AthleteEntity { Id = 2, UserName = "Smith",ProfilPicture = picture2,LastName = "Smith", FirstName = "Jane", Email = "jane.smith@exemple.com", PasswordHash = "secure456", Sexe = "F", Length = 1.65, Weight = 60, DateOfBirth = new DateOnly(1995, 01, 01), IsCoach = false, DataSourceId = 1 },
new AthleteEntity { Id = 3, UserName = "Martin",ProfilPicture = picture2,ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,LastName = "Martin", FirstName = "Paul", Email = "paul.martin@example.com", PasswordHash = "super789", Sexe = "M", Length = 1.75, Weight = 68, DateOfBirth = new DateOnly(1992, 01, 01), IsCoach = true, DataSourceId = 1},
new AthleteEntity { Id = 4, UserName = "Brown",ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"),LastName = "Brown", FirstName = "Anna", Email = "anna.brown@example.com", PasswordHash = "test000", Sexe = "F", Length = 1.70, Weight = 58, DateOfBirth = new DateOnly(1993, 01, 01), IsCoach = false, DataSourceId = 2 },
new AthleteEntity { Id = 5, UserName = "Lee", ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"),LastName = "Lee", FirstName = "Bruce", Email = "bruce.lee@example.com", PasswordHash = "hello321", Sexe = "M", Length = 2.0, Weight = 90, DateOfBirth = new DateOnly(1991, 01, 01), IsCoach = false, DataSourceId = 3 }
);
}
}

@ -56,25 +56,25 @@ class Program
foreach (var athlete in db.AthletesSet)
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete d'id '2' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2))
foreach (var athlete in db.AthletesSet.Where(a => a.Id == 2))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de username 'Doe' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Username == "Doe"))
foreach (var athlete in db.AthletesSet.Where(a => a.UserName == "Doe"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -83,7 +83,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Sexe == "F"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -92,7 +92,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Email == "bruce.lee@example.com"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -101,7 +101,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Weight == 90))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -110,7 +110,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Length == 1.80))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -119,7 +119,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.DateOfBirth == new DateOnly(1990, 01, 01)))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -128,7 +128,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.LastName == "Martin"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -137,7 +137,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.FirstName == "Anna"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -146,7 +146,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.LastName == "Brown" && a.FirstName == "Anna"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -155,7 +155,7 @@ class Program
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.IsCoach == true))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
@ -755,7 +755,7 @@ class Program
Console.WriteLine("Test d'ajout, de modification et de suppression des athletes :");
var picture = "https://davidalmeida.site/assets/me_avatar.f77af006.png";
// Ajout d'un nouveau livre
var newAthlete = new AthleteEntity { Username = "Doe", LastName = "Doe",ProfilPicture = picture,FirstName = "John", Email = "essaie.example.com", Password = "TheNewPassword", Sexe = "M", Length = 1.80, Weight = 90, DateOfBirth = new DateOnly(2024, 02, 22), IsCoach = false };
var newAthlete = new AthleteEntity { UserName = "Doe", LastName = "Doe",ProfilPicture = picture,FirstName = "John", Email = "essaie.example.com", PasswordHash = "TheNewPassword", Sexe = "M", Length = 1.80, Weight = 90, DateOfBirth = new DateOnly(2024, 02, 22), IsCoach = false };
db.AthletesSet.Add(newAthlete);
db.SaveChanges();
@ -763,7 +763,7 @@ class Program
Console.WriteLine("Athlete après ajout :");
foreach (var athlete in db.AthletesSet)
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
// Modification du titre du nouveau livre
@ -774,7 +774,7 @@ class Program
Console.WriteLine("Livres après modification :");
foreach (var athlete in db.AthletesSet)
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
// Suppression du nouveau livre
@ -785,7 +785,7 @@ class Program
Console.WriteLine("Livres après suppression :");
foreach (var athlete in db.AthletesSet)
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.UserName}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Length}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
}

@ -96,7 +96,7 @@ class Program
foreach (var athlete in dataSource.Athletes)
{
Console.WriteLine($"\t\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"\t\t\t{athlete.Id} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
}
}
@ -122,7 +122,7 @@ class Program
foreach (var athlete in dataSource.Athletes)
{
Console.WriteLine($"\t\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"\t\t\t{athlete.Id} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
}
}
@ -138,7 +138,7 @@ class Program
foreach (var athlete in db.AthletesSet.Include(a => a.Statistics).Include(a => a.Activities).Include(a => a.TrainingsAthlete).Include(a => a.NotificationsSent).Include(a => a.DataSource).Include(a => a.TrainingsCoach).Include(a => a.NotificationsReceived))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine("\t\tStatistiques :");
Console.WriteLine("\t\t---------------------------------");
@ -199,9 +199,9 @@ class Program
Console.WriteLine("Accès à l'athlète d'id '2' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2).Include(a => a.Statistics).Include(a => a.Activities).Include(a => a.TrainingsAthlete).Include(a => a.NotificationsSent).Include(a => a.DataSource).Include(a => a.TrainingsCoach).Include(a => a.NotificationsReceived))
foreach (var athlete in db.AthletesSet.Where(a => a.Id == 2).Include(a => a.Statistics).Include(a => a.Activities).Include(a => a.TrainingsAthlete).Include(a => a.NotificationsSent).Include(a => a.DataSource).Include(a => a.TrainingsCoach).Include(a => a.NotificationsReceived))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine("\t\tStatistiques :");
Console.WriteLine("\t\t---------------------------------");
@ -269,7 +269,7 @@ class Program
foreach (var athlete in db.AthletesSet.Include(f => f.Followers).Include(f => f.Followings))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"\t{athlete.Id} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"");
Console.WriteLine($"");

@ -12,14 +12,14 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
{
var athlete = new AthleteEntity
{
Username = "john_doe",
UserName = "john_doe",
LastName = "Doe",
FirstName = "John",
Email = "john.doe@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.5f,
Password = "password",
PasswordHash = "password",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
ProfilPicture = "profile.jpg",
@ -36,9 +36,9 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedAthlete = context.AthletesSet.First(a => a.Username == "john_doe");
var savedAthlete = context.AthletesSet.First(a => a.UserName == "john_doe");
Assert.NotNull(savedAthlete);
Assert.Equal("john_doe", savedAthlete.Username);
Assert.Equal("john_doe", savedAthlete.UserName);
}
}
@ -47,14 +47,14 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
{
var athlete = new AthleteEntity
{
Username = "jane_smith",
UserName = "jane_smith",
LastName = "Smith",
FirstName = "Jane",
Email = "jane.smith@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "password123",
PasswordHash = "password123",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false,
DataSourceId = 2,
@ -70,16 +70,16 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedAthlete = context.AthletesSet.First(a => a.Username == "jane_smith");
savedAthlete.Username = "jane_doe";
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");
var updatedAthlete = context.AthletesSet.First(a => a.UserName == "jane_doe");
Assert.NotNull(updatedAthlete);
Assert.Equal("jane_doe", updatedAthlete.Username);
Assert.Equal("jane_doe", updatedAthlete.UserName);
Assert.Equal("Smith", updatedAthlete.LastName);
}
}
@ -89,14 +89,14 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
{
var athlete = new AthleteEntity
{
Username = "test_user",
UserName = "test_user",
LastName = "Test",
FirstName = "User",
Email = "test.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "testpassword",
PasswordHash = "testpassword",
DateOfBirth = new DateOnly(1985, 10, 20),
IsCoach = false,
DataSourceId = 3
@ -111,14 +111,14 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedAthlete = context.AthletesSet.First(a => a.Username == "test_user");
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");
var deletedAthlete = context.AthletesSet.FirstOrDefault(a => a.UserName == "test_user");
Assert.Null(deletedAthlete);
}
}
@ -128,14 +128,14 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
{
var athlete = new AthleteEntity
{
Username = "john_doe",
UserName = "john_doe",
LastName = "Doe",
FirstName = "John",
Email = "john.doe@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.5f,
Password = "password",
PasswordHash = "password",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -150,16 +150,16 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedAthlete = context.AthletesSet.First(a => a.Username == "john_doe");
var savedAthlete = context.AthletesSet.First(a => a.UserName == "john_doe");
Assert.NotNull(savedAthlete);
Assert.Equal("john_doe", savedAthlete.Username);
Assert.Equal("john_doe", savedAthlete.UserName);
Assert.Equal("Doe", savedAthlete.LastName);
Assert.Equal("John", savedAthlete.FirstName);
Assert.Equal("john.doe@example.com", savedAthlete.Email);
Assert.Equal("M", savedAthlete.Sexe);
Assert.Equal(180.0, savedAthlete.Length);
Assert.Equal(75.5f, savedAthlete.Weight);
Assert.Equal("password", savedAthlete.Password);
Assert.Equal("password", savedAthlete.PasswordHash);
Assert.Equal(new DateOnly(1990, 1, 1), savedAthlete.DateOfBirth);
Assert.False(savedAthlete.IsCoach);
}
@ -170,14 +170,14 @@ public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<Databa
{
var athlete = new AthleteEntity
{
Username = null,
UserName = null,
LastName = null,
FirstName = null,
Email = null,
Sexe = null,
Length = 0,
Weight = 0,
Password = null,
PasswordHash = null,
DateOfBirth = default,
IsCoach = false
};

@ -12,14 +12,14 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
{
var follower = new AthleteEntity
{
Username = "follower_user1",
UserName = "follower_user1",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
PasswordHash = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -27,14 +27,14 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
var following = new AthleteEntity
{
Username = "following_user1",
UserName = "following_user1",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
PasswordHash = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false,
DataSourceId = 2
@ -63,13 +63,13 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedFriendship = context.AthletesSet.Include(a => a.Followers).Include(a => a.Followings).FirstOrDefault(a => a.Username == "follower_user1").Followings.FirstOrDefault(f => f.FollowerId == follower.IdAthlete && f.FollowingId == following.IdAthlete);
var savedFriendship = context.AthletesSet.Include(a => a.Followers).Include(a => a.Followings).FirstOrDefault(a => a.UserName == "follower_user1").Followings.FirstOrDefault(f => f.FollowerId == follower.Id && f.FollowingId == following.Id);
Assert.NotNull(savedFriendship);
if (savedFriendship != null)
{
Assert.Equal(follower.IdAthlete, savedFriendship.FollowerId);
Assert.Equal(following.IdAthlete, savedFriendship.FollowingId);
Assert.Equal(follower.Id, savedFriendship.FollowerId);
Assert.Equal(following.Id, savedFriendship.FollowingId);
}
}
}
@ -79,42 +79,42 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
{
var follower = new AthleteEntity
{
Username = "follower_user",
UserName = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
PasswordHash = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
UserName = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
PasswordHash = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
var thirdAthlete = new AthleteEntity
{
Username = "third_user",
UserName = "third_user",
LastName = "Third",
FirstName = "User",
Email = "third.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "thirdpassword",
PasswordHash = "thirdpassword",
DateOfBirth = new DateOnly(1988, 3, 15),
IsCoach = false
};
@ -157,28 +157,28 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
// Act
var follower = new AthleteEntity
{
Username = "follower_user",
UserName = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
PasswordHash = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
UserName = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
PasswordHash = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};

@ -12,14 +12,14 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
{
var sender = new AthleteEntity
{
Username = "sender_user",
UserName = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
PasswordHash = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -55,14 +55,14 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
{
var sender = new AthleteEntity
{
Username = "sender_user",
UserName = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
PasswordHash = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -105,14 +105,14 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
{
var sender = new AthleteEntity
{
Username = "sender_user",
UserName = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
PasswordHash = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 3
@ -154,14 +154,14 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
{
var sender = new AthleteEntity
{
Username = "sender_user",
UserName = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
PasswordHash = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 3

@ -12,14 +12,14 @@ public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<Data
{
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -56,14 +56,14 @@ public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<Data
{
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -107,14 +107,14 @@ public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<Data
{
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1
@ -158,14 +158,14 @@ public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<Data
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false,
DataSourceId = 1

@ -12,14 +12,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
{
var coach = new AthleteEntity
{
Username = "coach_user",
UserName = "coach_user",
LastName = "Coach",
FirstName = "User",
Email = "coach.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "coachpassword",
PasswordHash = "coachpassword",
DateOfBirth = new DateOnly(1985, 5, 15),
IsCoach = true,
DataSourceId = 1
@ -27,14 +27,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 3, 20),
IsCoach = false,
DataSourceId = 1
@ -73,14 +73,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
{
var coach = new AthleteEntity
{
Username = "coach_user",
UserName = "coach_user",
LastName = "Coach",
FirstName = "User",
Email = "coach.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "coachpassword",
PasswordHash = "coachpassword",
DateOfBirth = new DateOnly(1985, 5, 15),
IsCoach = true,
DataSourceId = 1
@ -88,14 +88,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 3, 20),
IsCoach = false,
DataSourceId = 1
@ -141,14 +141,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
{
var coach = new AthleteEntity
{
Username = "coach_user",
UserName = "coach_user",
LastName = "Coach",
FirstName = "User",
Email = "coach.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "coachpassword",
PasswordHash = "coachpassword",
DateOfBirth = new DateOnly(1985, 5, 15),
IsCoach = true,
DataSourceId = 1
@ -156,14 +156,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 3, 20),
IsCoach = false,
DataSourceId = 1
@ -208,14 +208,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
{
var coach = new AthleteEntity
{
Username = "coach_user",
UserName = "coach_user",
LastName = "Coach",
FirstName = "User",
Email = "coach.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "coachpassword",
PasswordHash = "coachpassword",
DateOfBirth = new DateOnly(1985, 5, 15),
IsCoach = true,
DataSourceId = 1
@ -223,14 +223,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
var athlete = new AthleteEntity
{
Username = "athlete_user",
UserName = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "athletepassword",
PasswordHash = "athletepassword",
DateOfBirth = new DateOnly(1990, 3, 20),
IsCoach = false,
DataSourceId = 1

Loading…
Cancel
Save