💥 🚧 Début des tests
continuous-integration/drone/push Build is passing Details

WORK-KEV
Kevin MONTEIRO 1 year ago
parent 06351b05f0
commit 55364ee999

@ -41,8 +41,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFMappers", "EFMappers\EFMa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APIMappers", "APIMappers\APIMappers.csproj", "{41D18203-1688-43BD-A3AC-FD0C2BD81909}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestsEntities2", "UnitTestsEntities2\UnitTestsEntities2.csproj", "{43757AC2-2924-46CF-BCCD-80F1C1265B6A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -117,10 +115,6 @@ Global
{41D18203-1688-43BD-A3AC-FD0C2BD81909}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41D18203-1688-43BD-A3AC-FD0C2BD81909}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41D18203-1688-43BD-A3AC-FD0C2BD81909}.Release|Any CPU.Build.0 = Release|Any CPU
{43757AC2-2924-46CF-BCCD-80F1C1265B6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43757AC2-2924-46CF-BCCD-80F1C1265B6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43757AC2-2924-46CF-BCCD-80F1C1265B6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43757AC2-2924-46CF-BCCD-80F1C1265B6A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -133,7 +127,6 @@ Global
{E515C8B6-6282-4D8B-8523-7B3A13E4AF58} = {30FC2BE9-7397-445A-84AD-043CE70F4281}
{31FA8E5E-D642-4C43-A2B2-02B9832B2CEC} = {2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}
{73EA27F2-9F0C-443F-A5EE-2960C983A422} = {2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}
{43757AC2-2924-46CF-BCCD-80F1C1265B6A} = {2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0F3487F4-66CA-4034-AC66-1BC899C9B523}

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore;
public class ActivityEntityTests
{
/*[Fact]
[Fact]
public void Add_Activity_Success()
{
@ -30,7 +30,7 @@ public class ActivityEntityTests
AthleteId = 1
};
// Act
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
@ -38,22 +38,18 @@ public class ActivityEntityTests
context.SaveChanges();
}
// Assert
using (var context = new StubbedContext(options))
{
var savedActivity = context.Activities.First(a => a.Type == "Running");
Assert.NotNull(savedActivity);
}
Assert.Equal("Running", savedActivity.Type );
}*/
}
[Fact]
public void Update_Activity_Success()
{
// Arrange
var options = new DbContextOptionsBuilder<StubbedContext>()
.UseInMemoryDatabase(databaseName: "Update_Activity_Success")
.Options;
var activity = new ActivityEntity
{
Type = "Running",
@ -73,6 +69,7 @@ public class ActivityEntityTests
AthleteId = 1
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
@ -80,7 +77,6 @@ public class ActivityEntityTests
context.SaveChanges();
}
// Act
using (var context = new StubbedContext(options))
{
var savedActivity = context.Activities.First(a => a.Type == "Running");
@ -88,22 +84,18 @@ public class ActivityEntityTests
context.SaveChanges();
}
// Assert
using (var context = new StubbedContext(options))
{
var updatedActivity = context.Activities.First(a => a.Type == "Walking");
Assert.NotNull(updatedActivity);
}
Assert.Equal("Walking", updatedActivity.Type );
Assert.Equal(7, updatedActivity.EffortFelt );
}*/
}
[Fact]
public void Delete_Activity_Success()
{
// Arrange
var options = new DbContextOptionsBuilder<StubbedContext>()
.UseInMemoryDatabase(databaseName: "Delete_Activity_Success")
.Options;
var activity = new ActivityEntity
{
Type = "Running",
@ -123,6 +115,7 @@ public class ActivityEntityTests
AthleteId = 1
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
@ -130,7 +123,6 @@ public class ActivityEntityTests
context.SaveChanges();
}
// Act
using (var context = new StubbedContext(options))
{
var savedActivity = context.Activities.First(a => a.Type == "Running");
@ -138,12 +130,11 @@ public class ActivityEntityTests
context.SaveChanges();
}
// Assert
using (var context = new StubbedContext(options))
{
var deletedActivity = context.Activities.FirstOrDefault(a => a.Type == "Running");
Assert.Null(deletedActivity);
}
}*/
}
}

@ -0,0 +1,122 @@
namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
public class AthleteEntityTests
{
[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 StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(athlete);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedAthlete = context.Athletes.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 StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(athlete);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedAthlete = context.Athletes.First(a => a.Username == "jane_smith");
savedAthlete.Username = "jane_doe";
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var updatedAthlete = context.Athletes.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 StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(athlete);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedAthlete = context.Athletes.First(a => a.Username == "test_user");
context.Athletes.Remove(savedAthlete);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var deletedAthlete = context.Athletes.FirstOrDefault(a => a.Username == "test_user");
Assert.Null(deletedAthlete);
}*/
}
}

@ -0,0 +1,102 @@
namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
public class DataSourceEntityTests
{
[Fact]
public void Add_DataSource_Success()
{
var dataSource = new DataSourceEntity
{
Type = "GPS",
Model = "Garmin Forerunner 945",
Precision = 0.1f
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.DataSources.Add(dataSource);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedDataSource = context.DataSources.First(d => d.Type == "GPS");
Assert.NotNull(savedDataSource);
Assert.Equal("Garmin Forerunner 945", savedDataSource.Model);
}*/
}
[Fact]
public void Update_DataSource_Success()
{
var dataSource = new DataSourceEntity
{
Type = "Heart Rate Monitor",
Model = "Polar H10",
Precision = 0.2f
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.DataSources.Add(dataSource);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedDataSource = context.DataSources.First(d => d.Type == "Heart Rate Monitor");
savedDataSource.Model = "Polar H9";
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var updatedDataSource = context.DataSources.First(d => d.Model == "Polar H9");
Assert.NotNull(updatedDataSource);
Assert.Equal("Heart Rate Monitor", updatedDataSource.Type);
Assert.Equal(0.2f, updatedDataSource.Precision);
}*/
}
[Fact]
public void Delete_DataSource_Success()
{
var dataSource = new DataSourceEntity
{
Type = "Smartwatch",
Model = "Apple Watch Series 6",
Precision = 0.05f
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.DataSources.Add(dataSource);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedDataSource = context.DataSources.First(d => d.Type == "Smartwatch");
context.DataSources.Remove(savedDataSource);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var deletedDataSource = context.DataSources.FirstOrDefault(d => d.Type == "Smartwatch");
Assert.Null(deletedDataSource);
}*/
}
}

@ -0,0 +1,206 @@
namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
public class FriendshipEntityTests
{
[Fact]
public void Add_Friendship_Success()
{
var follower = new AthleteEntity
{
Username = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
var friendship = new FriendshipEntity
{
Follower = follower,
Following = following,
StartDate = DateTime.Now
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(follower);
context.Athletes.Add(following);
context.Friendships.Add(friendship);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedFriendship = context.Friendships.FirstOrDefault();
Assert.NotNull(savedFriendship);
Assert.Equal(follower.IdAthlete, savedFriendship.FollowerId);
Assert.Equal(following.IdAthlete, savedFriendship.FollowingId);
}*/
}
[Fact]
public void Update_Friendship_Success()
{
var follower = new AthleteEntity
{
Username = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
var thirdAthlete = new AthleteEntity
{
Username = "third_user",
LastName = "Third",
FirstName = "User",
Email = "third.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "thirdpassword",
DateOfBirth = new DateOnly(1988, 3, 15),
IsCoach = false
};
var friendship = new FriendshipEntity
{
Follower = follower,
Following = following,
StartDate = DateTime.Now
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(follower);
context.Athletes.Add(following);
context.Athletes.Add(thirdAthlete);
context.Friendships.Add(friendship);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedFriendship = context.Friendships.FirstOrDefault();
savedFriendship.Follower = thirdAthlete; // Update the follower
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var updatedFriendship = context.Friendships.FirstOrDefault();
Assert.NotNull(updatedFriendship);
Assert.Equal(thirdAthlete.IdAthlete, updatedFriendship.FollowerId);
}*/
}
[Fact]
public void Delete_Friendship_Success()
{
var follower = new AthleteEntity
{
Username = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
var friendship = new FriendshipEntity
{
Follower = follower,
Following = following,
StartDate = DateTime.Now
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(follower);
context.Athletes.Add(following);
context.Friendships.Add(friendship);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedFriendship = context.Friendships.FirstOrDefault();
context.Friendships.Remove(savedFriendship);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var deletedFriendship = context.Friendships.FirstOrDefault();
Assert.Null(deletedFriendship);
}*/
}
}

@ -0,0 +1,172 @@
namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
public class HeartRateEntityTests
{
[Fact]
public void Add_HeartRate_Success()
{
var activity = new ActivityEntity
{
Type = "Running",
Date = new DateOnly(2024, 3, 15),
StartTime = new TimeOnly(9, 0),
EndTime = new TimeOnly(10, 0),
EffortFelt = 7,
Variability = 0.5f,
Variance = 0.2f,
StandardDeviation = 0.3f,
Average = 0.4f,
Maximum = 200,
Minimum = 100,
AverageTemperature = 25.5f,
HasAutoPause = true,
DataSourceId = 1,
AthleteId = 1
};
var heartRateEntry = new HeartRateEntity
{
Altitude = 100.0,
Time = new TimeOnly(9, 30),
Temperature = 20.0f,
Bpm = 150,
Longitude = 45.12345f,
Latitude = 35.6789f,
Activity = activity
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Activities.Add(activity);
context.HeartRates.Add(heartRateEntry);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedHeartRate = context.HeartRates.First();
Assert.NotNull(savedHeartRate);
Assert.Equal(150, savedHeartRate.Bpm);
}*/
}
[Fact]
public void Update_HeartRate_Success()
{
var activity = new ActivityEntity
{
Type = "Running",
Date = new DateOnly(2024, 3, 15),
StartTime = new TimeOnly(9, 0),
EndTime = new TimeOnly(10, 0),
EffortFelt = 7,
Variability = 0.5f,
Variance = 0.2f,
StandardDeviation = 0.3f,
Average = 0.4f,
Maximum = 200,
Minimum = 100,
AverageTemperature = 25.5f,
HasAutoPause = true,
DataSourceId = 1,
AthleteId = 1
};
var heartRateEntry = new HeartRateEntity
{
Altitude = 100.0,
Time = new TimeOnly(9, 30),
Temperature = 20.0f,
Bpm = 150,
Longitude = 45.12345f,
Latitude = 35.6789f,
Activity = activity
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Activities.Add(activity);
context.HeartRates.Add(heartRateEntry);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedHeartRate = context.HeartRates.First();
savedHeartRate.Bpm = 160;
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var updatedHeartRate = context.HeartRates.First();
Assert.NotNull(updatedHeartRate);
Assert.Equal(160, updatedHeartRate.Bpm);
}*/
}
[Fact]
public void Delete_HeartRate_Success()
{
var activity = new ActivityEntity
{
Type = "Running",
Date = new DateOnly(2024, 3, 15),
StartTime = new TimeOnly(9, 0),
EndTime = new TimeOnly(10, 0),
EffortFelt = 7,
Variability = 0.5f,
Variance = 0.2f,
StandardDeviation = 0.3f,
Average = 0.4f,
Maximum = 200,
Minimum = 100,
AverageTemperature = 25.5f,
HasAutoPause = true,
DataSourceId = 1,
AthleteId = 1
};
var heartRateEntry = new HeartRateEntity
{
Altitude = 100.0,
Time = new TimeOnly(9, 30),
Temperature = 20.0f,
Bpm = 150,
Longitude = 45.12345f,
Latitude = 35.6789f,
Activity = activity
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Activities.Add(activity);
context.HeartRates.Add(heartRateEntry);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedHeartRate = context.HeartRates.First();
context.HeartRates.Remove(savedHeartRate);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var deletedHeartRate = context.HeartRates.FirstOrDefault();
Assert.Null(deletedHeartRate);
}*/
}
}

@ -0,0 +1,151 @@
namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
public class NotificationEntityTests
{
[Fact]
public void Add_Notification_Success()
{
var sender = new AthleteEntity
{
Username = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var notification = new NotificationEntity
{
Message = "Test notification",
Date = DateTime.Now,
Statut = false,
Urgence = "High",
Sender = sender
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(sender);
context.Notifications.Add(notification);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedNotification = context.Notifications.First();
Assert.NotNull(savedNotification);
Assert.Equal("Test notification", savedNotification.Message);
}*/
}
[Fact]
public void Update_Notification_Success()
{
var sender = new AthleteEntity
{
Username = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var notification = new NotificationEntity
{
Message = "Test notification",
Date = DateTime.Now,
Statut = false,
Urgence = "High",
Sender = sender
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(sender);
context.Notifications.Add(notification);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedNotification = context.Notifications.First();
savedNotification.Message = "Updated message";
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var updatedNotification = context.Notifications.First();
Assert.NotNull(updatedNotification);
Assert.Equal("Updated message", updatedNotification.Message);
}*/
}
[Fact]
public void Delete_Notification_Success()
{
var sender = new AthleteEntity
{
Username = "sender_user",
LastName = "Sender",
FirstName = "User",
Email = "sender.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "senderpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var notification = new NotificationEntity
{
Message = "Test notification",
Date = DateTime.Now,
Statut = false,
Urgence = "High",
Sender = sender
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(sender);
context.Notifications.Add(notification);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedNotification = context.Notifications.First();
context.Notifications.Remove(savedNotification);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var deletedNotification = context.Notifications.FirstOrDefault();
Assert.Null(deletedNotification);
}*/
}
}

@ -0,0 +1,155 @@
namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
public class StatisticEntityTests
{
[Fact]
public void Add_Statistic_Success()
{
var athlete = new AthleteEntity
{
Username = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var statistic = new StatisticEntity
{
Weight = 75.0f,
AverageHeartRate = 150.0,
MaximumHeartRate = 180.0,
AverageCaloriesBurned = 500.0,
Date = new DateOnly(2024, 3, 15),
Athlete = athlete
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(athlete);
context.Statistics.Add(statistic);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedStatistic = context.Statistics.First();
Assert.NotNull(savedStatistic);
Assert.Equal(75.0f, savedStatistic.Weight);
}*/
}
[Fact]
public void Update_Statistic_Success()
{
var athlete = new AthleteEntity
{
Username = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var statistic = new StatisticEntity
{
Weight = 75.0f,
AverageHeartRate = 150.0,
MaximumHeartRate = 180.0,
AverageCaloriesBurned = 500.0,
Date = new DateOnly(2024, 3, 15),
Athlete = athlete
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(athlete);
context.Statistics.Add(statistic);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedStatistic = context.Statistics.First();
savedStatistic.Weight = 80.0f;
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var updatedStatistic = context.Statistics.First();
Assert.NotNull(updatedStatistic);
Assert.Equal(80.0f, updatedStatistic.Weight);
}*/
}
[Fact]
public void Delete_Statistic_Success()
{
var athlete = new AthleteEntity
{
Username = "athlete_user",
LastName = "Athlete",
FirstName = "User",
Email = "athlete.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "athletepassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var statistic = new StatisticEntity
{
Weight = 75.0f,
AverageHeartRate = 150.0,
MaximumHeartRate = 180.0,
AverageCaloriesBurned = 500.0,
Date = new DateOnly(2024, 3, 15),
Athlete = athlete
};
/*
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
context.Athletes.Add(athlete);
context.Statistics.Add(statistic);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var savedStatistic = context.Statistics.First();
context.Statistics.Remove(savedStatistic);
context.SaveChanges();
}
using (var context = new StubbedContext(options))
{
var deletedStatistic = context.Statistics.FirstOrDefault();
Assert.Null(deletedStatistic);
}*/
}
}

@ -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);
}*/
}
}
Loading…
Cancel
Save