Merge remote-tracking branch 'origin/tests_merging' into tests_merging
continuous-integration/drone/push Build is passing Details

WORK-KMO2
David D'ALMEIDA 1 year ago
commit 0b0033f51c

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -3,7 +3,7 @@
// PROJECT: Entities
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
// AUTHOR: HeartTeam
//-----------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;

@ -41,6 +41,8 @@ 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}") = "UnitTestsModel", "Tests\UnitTestsModel\UnitTestsModel.csproj", "{508D380F-145C-437E-A7DF-7A17C526B2F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -115,6 +117,10 @@ 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
{508D380F-145C-437E-A7DF-7A17C526B2F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{508D380F-145C-437E-A7DF-7A17C526B2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{508D380F-145C-437E-A7DF-7A17C526B2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{508D380F-145C-437E-A7DF-7A17C526B2F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -127,6 +133,7 @@ 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}
{508D380F-145C-437E-A7DF-7A17C526B2F3} = {2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0F3487F4-66CA-4034-AC66-1BC899C9B523}

@ -32,7 +32,7 @@ public class UsersController : Controller
/// <summary>
/// Récupère une page d'utilisateurs en fonction des critères de pagination et de tri fournis.
/// </summary>
/// <param name="request">Les critères de pagination et de tri pour les utilisateurs.</param>
/// <param name="request">Les critères de pagination et de tri pour les utilisateurs. Met None par defaut et/ou si le critère n'est pas correct</param>
/// <returns>Une page de données utilisateur selon les critères spécifiés.</returns>
/// <response code="200">Retourne la page demandée d'utilisateurs.</response>
/// <response code="400">La demande de pagination est invalide.</response>

@ -3,13 +3,20 @@ namespace Shared;
public enum ActivityOrderCriteria
{
None,
ByIdActivity,
ByType,
ByDate,
ByDuration,
ByDistance,
ByElevation,
ByAverageSpeed,
ByAverageHeartRate,
ByCalories,
ByDescription
ByStartTime,
ByEndTime,
ByEffortFelt,
ByVariability,
ByVariance,
ByStandardDeviation,
ByAverage,
ByMaximum,
ByMinimum,
ByAverageTemperature,
ByHasAutoPause,
ByDataSourceId,
ByAthleteId
}

@ -0,0 +1,166 @@
//-----------------------------------------------------------------------
// FILENAME: ActivityTests.cs
// PROJECT: UnitTestsModel
// DATE CREATED: 16/03/2024
// AUTHOR: HeartTeam
// PURPOSE: Contains unit tests for the Activity class in the Model namespace.
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Model;
using Xunit;
namespace UnitTestsModel
{
/// <summary>
/// Contains unit tests for the <see cref="Activity"/> class.
/// </summary>
public class ActivityTests
{
/// <summary>
/// Verifies that the constructor sets the effort property correctly when a valid effort is provided.
/// </summary>
[Fact]
public void Constructor_WithValidEffort_SetsEffort()
{
var date = DateTime.Now;
var validEffort = 3;
var activity = new Activity(
id: 1,
type: "Running",
date: date,
startTime: date.AddHours(1),
endTime: date.AddHours(2),
effort: validEffort,
variability: 0.5f,
variance: 0.3f,
standardDeviation: 0.2f,
average: 150,
maximum: 180,
minimum: 120,
averageTemperature: 25.5f,
hasAutoPause: false,
user: new User(),
dataSource: new DataSource(1, "Type", "Model", 0.1f, new List<User>(), new List<Activity>()),
heartRates: null
);
Assert.Equal(validEffort, activity.Effort);
}
/// <summary>
/// Verifies that the constructor throws an ArgumentException when an invalid effort is provided.
/// </summary>
[Fact]
public void Constructor_WithInvalidEffort_ThrowsArgumentException()
{
var date = DateTime.Now;
var invalidEffort = 6;
Assert.Throws<ArgumentException>(() => new Activity(
id: 1,
type: "Running",
date: date,
startTime: date.AddHours(1),
endTime: date.AddHours(2),
effort: invalidEffort,
variability: 0.5f,
variance: 0.3f,
standardDeviation: 0.2f,
average: 150,
maximum: 180,
minimum: 120,
averageTemperature: 25.5f,
hasAutoPause: false,
user: new User(),
dataSource: new DataSource(1, "Type", "Model", 0.1f, new List<User>(), new List<Activity>()),
heartRates: null
));
}
/// <summary>
/// Verifies that the ToString method returns the expected string representation of the activity.
/// </summary>
[Fact]
public void ToString_ReturnsExpectedString()
{
var date = new DateTime(2023, 3, 16, 10, 0, 0);
var activity = new Activity(
id: 1,
type: "Running",
date: date,
startTime: date.AddHours(1),
endTime: date.AddHours(2),
effort: 3,
variability: 0.5f,
variance: 0.3f,
standardDeviation: 0.2f,
average: 150,
maximum: 180,
minimum: 120,
averageTemperature: 25.5f,
hasAutoPause: false,
user: new User(),
dataSource: new DataSource(1, "Type", "Model", 0.1f, new List<User>(), new List<Activity>()),
heartRates: null
);
var result = activity.ToString();
Assert.Contains("Activity #1: Running on 16/3/2023 from 11:00:00 to 12:00:00", result);
}
/// <summary>
/// Verifies that the constructor sets all properties correctly.
/// </summary>
[Fact]
public void Constructor_SetsPropertiesCorrectly()
{
var date = DateTime.Now;
var user = new User();
var dataSource = new DataSource(1, "Type", "Model", 0.1f, new List<User>(), new List<Activity>());
var heartRates = new List<HeartRate>();
var activity = new Activity(
id: 1,
type: "Running",
date: date,
startTime: date.AddHours(1),
endTime: date.AddHours(2),
effort: 3,
variability: 0.5f,
variance: 0.3f,
standardDeviation: 0.2f,
average: 150,
maximum: 180,
minimum: 120,
averageTemperature: 25.5f,
hasAutoPause: false,
user: user,
dataSource: dataSource,
heartRates: heartRates
);
Assert.Equal(1, activity.Id);
Assert.Equal("Running", activity.Type);
Assert.Equal(date, activity.Date);
Assert.Equal(date.AddHours(1), activity.StartTime);
Assert.Equal(date.AddHours(2), activity.EndTime);
Assert.Equal(3, activity.Effort);
Assert.Equal(0.5f, activity.Variability);
Assert.Equal(0.3f, activity.Variance);
Assert.Equal(0.2f, activity.StandardDeviation);
Assert.Equal(150, activity.Average);
Assert.Equal(180, activity.Maximum);
Assert.Equal(120, activity.Minimum);
Assert.Equal(25.5f, activity.AverageTemperature);
Assert.False(activity.HasAutoPause);
Assert.Equal(user, activity.Athlete);
Assert.Equal(dataSource, activity.DataSource);
Assert.Equal(heartRates, activity.HeartRates);
}
}
}

@ -0,0 +1,35 @@
using Model;
using Xunit;
namespace Model.Tests
{
public class AthleteTests
{
[Fact]
public void CheckAdd_ValidUser_ReturnsTrue()
{
// Arrange
var athlete = new Athlete();
// Act
var user = new User("hello13", "dkjd.png", "John", "Doe", "john@exemple.com", "password", "Male", 180.5f, 75.3f, new System.DateTime(1990, 5, 15), new Athlete());
var result = athlete.CheckAdd(user);
// Assert
Assert.True(result);
}
[Fact]
public void CheckAdd_CoachUser_ReturnsFalse()
{
// Arrange
var athlete = new Athlete();
var user = new User("hello13", "dkjd.png", "John", "Doe", "john@exemple.com", "password", "Male", 180.5f, 75.3f, new System.DateTime(1990, 5, 15), new Coach());
var result = athlete.CheckAdd(user);
// Assert
Assert.False(result);
}
}
}

@ -0,0 +1,36 @@
using Model;
using Xunit;
namespace Model.Tests
{
public class CoachTests
{
[Fact]
public void CheckAdd_AthleteUser_ReturnsTrue()
{
// Arrange
var coach = new Coach();
// Act
var user = new User { Role = new Athlete() };
var result = coach.CheckAdd(user);
// Assert
Assert.True(result);
}
[Fact]
public void CheckAdd_NonAthleteUser_ReturnsFalse()
{
// Arrange
var coach = new Coach();
// Act
var user = new User { Role = new Coach() };
var result = coach.CheckAdd(user);
// Assert
Assert.False(result);
}
}
}

@ -0,0 +1,32 @@
using Model;
using System.Collections.Generic;
using Xunit;
namespace Model.Tests
{
public class DataSourceTests
{
[Fact]
public void Constructor_WithArguments_InitializesProperties()
{
// Arrange
var id = 1;
var type = "Type";
var model = "Model";
var precision = 0.5f;
var athletes = new List<User>();
var activities = new List<Activity>();
// Act
var dataSource = new DataSource(id, type, model, precision, athletes, activities);
// Assert
Assert.Equal(id, dataSource.Id);
Assert.Equal(type, dataSource.Type);
Assert.Equal(model, dataSource.Model);
Assert.Equal(precision, dataSource.Precision);
Assert.Same(athletes, dataSource.Athletes);
Assert.Same(activities, dataSource.Activities);
}
}
}

@ -0,0 +1,73 @@
using Xunit;
using System;
namespace Model.Tests
{
public class HeartRateTests
{
[Fact]
public void HeartRate_Constructor_WithValidParameters()
{
// Arrange
int id = 1;
int bpm = 80;
TimeOnly timestamp = new TimeOnly(12, 30, 0);
Activity activity = new Activity();
double? latitude = 40.7128;
double? longitude = -74.0060;
double? altitude = 10.5;
int? cadence = 120;
double? distance = 5.2;
double? speed = 10.5;
int? power = 200;
double? temperature = 25.5;
// Act
var heartRate = new HeartRate(id, bpm, timestamp, activity, latitude, longitude, altitude, cadence, distance, speed, power, temperature);
// Assert
Assert.Equal(id, heartRate.Id);
Assert.Equal(bpm, heartRate.Bpm);
Assert.Equal(timestamp, heartRate.Timestamp);
Assert.Equal(activity, heartRate.Activity);
Assert.Equal(latitude, heartRate.Latitude);
Assert.Equal(longitude, heartRate.Longitude);
Assert.Equal(altitude, heartRate.Altitude);
Assert.Equal(cadence, heartRate.Cadence);
Assert.Equal(distance, heartRate.Distance);
Assert.Equal(speed, heartRate.Speed);
Assert.Equal(power, heartRate.Power);
Assert.Equal(temperature, heartRate.Temperature);
}
[Fact]
public void HeartRate_ToString_ReturnsExpectedString()
{
// Arrange
int id = 1;
int bpm = 80;
TimeOnly timestamp = new TimeOnly(12, 30, 0);
Activity activity = new Activity();
double? latitude = 40.7128;
double? longitude = -74.0060;
double? altitude = 10.5;
int? cadence = 120;
double? distance = 5.2;
double? speed = 10.5;
int? power = 200;
double? temperature = 25.5;
var heartRate = new HeartRate(id, bpm, timestamp, activity, latitude, longitude, altitude, cadence, distance, speed, power, temperature);
// Act
var result = heartRate.ToString();
// Assert
Assert.Contains($"HeartRate #{id}", result);
Assert.Contains($"{bpm} bpm", result);
Assert.Contains($"{timestamp:HH:mm:ss}", result);
Assert.Contains($"temperature of {temperature}°C", result);
Assert.Contains($"altitude of {altitude}m", result);
Assert.Contains($"at {longitude}°E and {latitude}°N", result);
}
}
}

@ -0,0 +1,38 @@
using Xunit;
namespace Model.Tests
{
public class LargeImageTests
{
[Fact]
public void Equals_ReturnsTrue_WhenBase64StringsAreEqual()
{
// Arrange
var base64String = "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHN0cmluZw==";
var image1 = new LargeImage(base64String);
var image2 = new LargeImage(base64String);
// Act
var result = image1.Equals(image2);
// Assert
Assert.True(result);
}
[Fact]
public void Equals_ReturnsFalse_WhenBase64StringsAreDifferent()
{
// Arrange
var base64String1 = "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHN0cmluZw==";
var base64String2 = "VGhpcyBpcyBhIGJhc2U2NSBlbmNvZGVkIHN0cmluZw==";
var image1 = new LargeImage(base64String1);
var image2 = new LargeImage(base64String2);
// Act
var result = image1.Equals(image2);
// Assert
Assert.False(result);
}
}
}

@ -0,0 +1,30 @@
using Xunit;
namespace Model.Tests
{
public class NotificationTests
{
[Fact]
public void Constructor_InitializesPropertiesCorrectly()
{
// Arrange
int id = 1;
string message = "Test notification";
DateTime date = DateTime.Now;
bool status = false;
string urgency = "High";
int toUserId = 10;
// Act
var notification = new Notification(id, message, date, status, urgency, toUserId);
// Assert
Assert.Equal(id, notification.IdNotif);
Assert.Equal(message, notification.Message);
Assert.Equal(date, notification.Date);
Assert.Equal(status, notification.Statut);
Assert.Equal(urgency, notification.Urgence);
Assert.Equal(toUserId, notification.ToUserId);
}
}
}

@ -0,0 +1,29 @@
using Xunit;
namespace Model.Tests
{
public class RelationshipRequestTests
{
[Fact]
public void Constructor_InitializesPropertiesCorrectly()
{
// Arrange
int id = 1;
int fromUserId = 2;
int toUserId = 3;
// Act
var request = new RelationshipRequest
{
Id = id,
FromUser = fromUserId,
ToUser = toUserId
};
// Assert
Assert.Equal(id, request.Id);
Assert.Equal(fromUserId, request.FromUser);
Assert.Equal(toUserId, request.ToUser);
}
}
}

@ -0,0 +1,36 @@
using Xunit;
namespace Model.Tests
{
public class RoleTests
{
[Fact]
public void AddUser_WithValidUser_ReturnsTrue()
{
// Arrange
var role = new Athlete(); // Vous pouvez utiliser Athlete ou Coach selon votre besoin
var user = new User("hello13", "dkjd.png", "John", "Doe", "john@exemple.com", "password", "M", 180.5f, 75.3f, new System.DateTime(1990, 5, 15), new Athlete());
// Act
bool result = role.AddUser(user);
// Assert
Assert.True(result);
}
[Fact]
public void AddUser_WithInvalidUser_ReturnsFalse()
{
// Arrange
var role = new Athlete(); // Vous pouvez utiliser Athlete ou Coach selon votre besoin
var user = new User(); // Créez un objet User invalide
// Act
bool result = role.AddUser(user);
// Assert
Assert.False(result);
}
}
}

@ -1,23 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>
<ProjectReference Include="..\..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,41 @@
using Xunit;
namespace Model.Tests
{
public class UserTests
{
[Fact]
public void UserConstructor_ValidParameters_ConstructsObject()
{
// Arrange
string username = "john_doe";
string profilePicture = "profile.jpg";
string lastName = "Doe";
string firstName = "John";
string email = "john.doe@example.com";
string password = "password";
string sex = "Male";
float length = 180.5f;
float weight = 75.3f;
DateTime dateOfBirth = new DateTime(1990, 5, 15);
Role role = new Athlete(); // You can change this to the appropriate role
// Act
User user = new User(username, profilePicture, lastName, firstName, email, password, sex, length, weight, dateOfBirth, role);
// Assert
Assert.NotNull(user);
Assert.Equal(username, user.Username);
Assert.Equal(profilePicture, user.ProfilePicture);
Assert.Equal(lastName, user.LastName);
Assert.Equal(firstName, user.FirstName);
Assert.Equal(email, user.Email);
Assert.Equal(password, user.MotDePasse);
Assert.Equal(sex, user.Sexe);
Assert.Equal(length, user.Lenght);
Assert.Equal(weight, user.Weight);
Assert.Equal(dateOfBirth, user.DateOfBirth);
Assert.Equal(role, user.Role);
}
}
}

@ -1,11 +0,0 @@
namespace UnitTestsEntities2
{
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
}
Loading…
Cancel
Save