|
|
|
@ -0,0 +1,202 @@
|
|
|
|
|
namespace UnitTestsEntities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Entities;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TrainingEntityTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Add_Training_Success()
|
|
|
|
|
{
|
|
|
|
|
var coach = new AthleteEntity
|
|
|
|
|
{
|
|
|
|
|
Username = "coach_user",
|
|
|
|
|
LastName = "Coach",
|
|
|
|
|
FirstName = "User",
|
|
|
|
|
Email = "coach.user@example.com",
|
|
|
|
|
Sexe = "M",
|
|
|
|
|
Length = 180.0,
|
|
|
|
|
Weight = 75.0f,
|
|
|
|
|
Password = "coachpassword",
|
|
|
|
|
DateOfBirth = new DateOnly(1985, 5, 15),
|
|
|
|
|
IsCoach = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var athlete = new AthleteEntity
|
|
|
|
|
{
|
|
|
|
|
Username = "athlete_user",
|
|
|
|
|
LastName = "Athlete",
|
|
|
|
|
FirstName = "User",
|
|
|
|
|
Email = "athlete.user@example.com",
|
|
|
|
|
Sexe = "F",
|
|
|
|
|
Length = 165.0,
|
|
|
|
|
Weight = 60.0f,
|
|
|
|
|
Password = "athletepassword",
|
|
|
|
|
DateOfBirth = new DateOnly(1990, 3, 20),
|
|
|
|
|
IsCoach = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var training = new TrainingEntity
|
|
|
|
|
{
|
|
|
|
|
Date = new DateOnly(2024, 3, 15),
|
|
|
|
|
Description = "Training description",
|
|
|
|
|
Latitude = 40.12345f,
|
|
|
|
|
Longitude = -74.56789f,
|
|
|
|
|
FeedBack = "Training feedback",
|
|
|
|
|
Coach = coach,
|
|
|
|
|
Athletes = { athlete }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
context.Athletes.Add(coach);
|
|
|
|
|
context.Athletes.Add(athlete);
|
|
|
|
|
context.Trainings.Add(training);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
var savedTraining = context.Trainings.First();
|
|
|
|
|
Assert.NotNull(savedTraining);
|
|
|
|
|
Assert.Equal("Training description", savedTraining.Description);
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Update_Training_Success()
|
|
|
|
|
{
|
|
|
|
|
var coach = new AthleteEntity
|
|
|
|
|
{
|
|
|
|
|
Username = "coach_user",
|
|
|
|
|
LastName = "Coach",
|
|
|
|
|
FirstName = "User",
|
|
|
|
|
Email = "coach.user@example.com",
|
|
|
|
|
Sexe = "M",
|
|
|
|
|
Length = 180.0,
|
|
|
|
|
Weight = 75.0f,
|
|
|
|
|
Password = "coachpassword",
|
|
|
|
|
DateOfBirth = new DateOnly(1985, 5, 15),
|
|
|
|
|
IsCoach = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var athlete = new AthleteEntity
|
|
|
|
|
{
|
|
|
|
|
Username = "athlete_user",
|
|
|
|
|
LastName = "Athlete",
|
|
|
|
|
FirstName = "User",
|
|
|
|
|
Email = "athlete.user@example.com",
|
|
|
|
|
Sexe = "F",
|
|
|
|
|
Length = 165.0,
|
|
|
|
|
Weight = 60.0f,
|
|
|
|
|
Password = "athletepassword",
|
|
|
|
|
DateOfBirth = new DateOnly(1990, 3, 20),
|
|
|
|
|
IsCoach = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var training = new TrainingEntity
|
|
|
|
|
{
|
|
|
|
|
Date = new DateOnly(2024, 3, 15),
|
|
|
|
|
Description = "Training description",
|
|
|
|
|
Latitude = 40.12345f,
|
|
|
|
|
Longitude = -74.56789f,
|
|
|
|
|
FeedBack = "Training feedback",
|
|
|
|
|
Coach = coach,
|
|
|
|
|
Athletes = { athlete }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
context.Athletes.Add(coach);
|
|
|
|
|
context.Athletes.Add(athlete);
|
|
|
|
|
context.Trainings.Add(training);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
var savedTraining = context.Trainings.First();
|
|
|
|
|
savedTraining.Description = "Updated training description";
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
var updatedTraining = context.Trainings.First();
|
|
|
|
|
Assert.NotNull(updatedTraining);
|
|
|
|
|
Assert.Equal("Updated training description", updatedTraining.Description);
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Delete_Training_Success()
|
|
|
|
|
{
|
|
|
|
|
var coach = new AthleteEntity
|
|
|
|
|
{
|
|
|
|
|
Username = "coach_user",
|
|
|
|
|
LastName = "Coach",
|
|
|
|
|
FirstName = "User",
|
|
|
|
|
Email = "coach.user@example.com",
|
|
|
|
|
Sexe = "M",
|
|
|
|
|
Length = 180.0,
|
|
|
|
|
Weight = 75.0f,
|
|
|
|
|
Password = "coachpassword",
|
|
|
|
|
DateOfBirth = new DateOnly(1985, 5, 15),
|
|
|
|
|
IsCoach = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var athlete = new AthleteEntity
|
|
|
|
|
{
|
|
|
|
|
Username = "athlete_user",
|
|
|
|
|
LastName = "Athlete",
|
|
|
|
|
FirstName = "User",
|
|
|
|
|
Email = "athlete.user@example.com",
|
|
|
|
|
Sexe = "F",
|
|
|
|
|
Length = 165.0,
|
|
|
|
|
Weight = 60.0f,
|
|
|
|
|
Password = "athletepassword",
|
|
|
|
|
DateOfBirth = new DateOnly(1990, 3, 20),
|
|
|
|
|
IsCoach = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var training = new TrainingEntity
|
|
|
|
|
{
|
|
|
|
|
Date = new DateOnly(2024, 3, 15),
|
|
|
|
|
Description = "Training description",
|
|
|
|
|
Latitude = 40.12345f,
|
|
|
|
|
Longitude = -74.56789f,
|
|
|
|
|
FeedBack = "Training feedback",
|
|
|
|
|
Coach = coach,
|
|
|
|
|
Athletes = { athlete }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
context.Athletes.Add(coach);
|
|
|
|
|
context.Athletes.Add(athlete);
|
|
|
|
|
context.Trainings.Add(training);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
var savedTraining = context.Trainings.First();
|
|
|
|
|
context.Trainings.Remove(savedTraining);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
{
|
|
|
|
|
var deletedTraining = context.Trainings.FirstOrDefault();
|
|
|
|
|
Assert.Null(deletedTraining);
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|