🚨 Correction tests exitants, 20/24 manque Friendship et un Delete dans HeartRateEntityTests qui ne passent pas ...
continuous-integration/drone/push Build is failing Details

WORK-KEV
Kevin MONTEIRO 1 year ago
parent bbb66c6059
commit 84ffc5c8fa

@ -77,14 +77,14 @@ public class ActivityEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedActivity = context.ActivitiesSet.First(a => a.Type == "Running"); var savedActivity = context.ActivitiesSet.FirstOrDefault(a => a.Type == "Running" && a.Maximum == 200);
savedActivity.Type = "Walking"; savedActivity.Type = "Walking";
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedActivity = context.ActivitiesSet.First(a => a.Type == "Walking"); var updatedActivity = context.ActivitiesSet.First(a => a.Type == "Walking" && a.Maximum == 200);
Assert.NotNull(updatedActivity); Assert.NotNull(updatedActivity);
Assert.Equal("Walking", updatedActivity.Type ); Assert.Equal("Walking", updatedActivity.Type );
Assert.Equal(7, updatedActivity.EffortFelt ); Assert.Equal(7, updatedActivity.EffortFelt );
@ -123,14 +123,14 @@ public class ActivityEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedActivity = context.ActivitiesSet.First(a => a.Type == "Running"); var savedActivity = context.ActivitiesSet.FirstOrDefault(a => a.Type == "Running" && a.EffortFelt == 7);
context.ActivitiesSet.Remove(savedActivity); context.ActivitiesSet.Remove(savedActivity);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedActivity = context.ActivitiesSet.FirstOrDefault(a => a.Type == "Running"); var deletedActivity = context.ActivitiesSet.FirstOrDefault(a => a.Type == "Running" && a.EffortFelt == 7);
Assert.Null(deletedActivity); Assert.Null(deletedActivity);
} }
} }

@ -84,14 +84,14 @@ public class DataSourceEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedDataSource = context.DataSourcesSet.First(d => d.Type == "Smartwatch"); var savedDataSource = context.DataSourcesSet.First(d => d.Type == "Smartwatch" && d.Model == "Apple Watch Series 6");
context.DataSourcesSet.Remove(savedDataSource); context.DataSourcesSet.Remove(savedDataSource);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedDataSource = context.DataSourcesSet.FirstOrDefault(d => d.Type == "Smartwatch"); var deletedDataSource = context.DataSourcesSet.FirstOrDefault(d => d.Type == "Smartwatch" && d.Model == "Apple Watch Series 6");
Assert.Null(deletedDataSource); Assert.Null(deletedDataSource);
} }
} }

@ -12,7 +12,7 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
{ {
var follower = new AthleteEntity var follower = new AthleteEntity
{ {
Username = "follower_user", Username = "follower_user1",
LastName = "Follower", LastName = "Follower",
FirstName = "User", FirstName = "User",
Email = "follower.user@example.com", Email = "follower.user@example.com",
@ -26,7 +26,7 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
var following = new AthleteEntity var following = new AthleteEntity
{ {
Username = "following_user", Username = "following_user1",
LastName = "Following", LastName = "Following",
FirstName = "User", FirstName = "User",
Email = "following.user@example.com", Email = "following.user@example.com",
@ -35,7 +35,8 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
Weight = 60.0f, Weight = 60.0f,
Password = "followingpassword", Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10), DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false IsCoach = false,
Followers = (ICollection<FriendshipEntity>)follower
}; };
var friendship = new FriendshipEntity var friendship = new FriendshipEntity
@ -43,24 +44,25 @@ public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<Dat
Follower = follower, Follower = follower,
Following = following, Following = following,
StartDate = DateTime.Now StartDate = DateTime.Now
};/* };
//Cast impossible entre Entities.AthleteEntity & System.Collections.Generic.ICollection ; Idem pour Update et Delete mais pas modif vu que ca ne fonctionne pas
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.AthletesSet.Add(follower); context.AthletesSet.Add(follower);
context.AthletesSet.Add(following); context.AthletesSet.Add(following);
context.Friendships.Add(friendship); var follow = context.AthletesSet.FirstOrDefault(a => a.Username == "following_user1");
follow.Followings = (ICollection<FriendshipEntity>)following;
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedFriendship = context.Friendships.FirstOrDefault(); var savedAth1 = context.AthletesSet.FirstOrDefault(a => a.Username == "following_user1");
Assert.NotNull(savedFriendship); var savedAth2 = context.AthletesSet.FirstOrDefault(a => a.Username == "follower_user1");
Assert.Equal(follower.IdAthlete, savedFriendship.FollowerId); Assert.Equal(savedAth2, friendship.Follower);
Assert.Equal(following.IdAthlete, savedFriendship.FollowingId); Assert.Equal(savedAth1, friendship.Following);
}*/ }
} }
[Fact] [Fact]

@ -51,7 +51,7 @@ public class HeartRateEntityTests (DatabaseFixture fixture) : IClassFixture<Data
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedHeartRate = context.HeartRatesSet.First(); var savedHeartRate = context.HeartRatesSet.FirstOrDefault(h => h.Altitude == 100.0 && h.Temperature == 20.0f);
Assert.NotNull(savedHeartRate); Assert.NotNull(savedHeartRate);
Assert.Equal(150, savedHeartRate.Bpm); Assert.Equal(150, savedHeartRate.Bpm);
} }
@ -118,7 +118,7 @@ public class HeartRateEntityTests (DatabaseFixture fixture) : IClassFixture<Data
{ {
var activity = new ActivityEntity var activity = new ActivityEntity
{ {
Type = "Running", Type = "Run",
Date = new DateOnly(2024, 3, 15), Date = new DateOnly(2024, 3, 15),
StartTime = new TimeOnly(9, 0), StartTime = new TimeOnly(9, 0),
EndTime = new TimeOnly(10, 0), EndTime = new TimeOnly(10, 0),
@ -137,7 +137,7 @@ public class HeartRateEntityTests (DatabaseFixture fixture) : IClassFixture<Data
var heartRateEntry = new HeartRateEntity var heartRateEntry = new HeartRateEntity
{ {
Altitude = 100.0, Altitude = 105.0,
Time = new TimeOnly(9, 30), Time = new TimeOnly(9, 30),
Temperature = 20.0f, Temperature = 20.0f,
Bpm = 150, Bpm = 150,
@ -153,17 +153,19 @@ public class HeartRateEntityTests (DatabaseFixture fixture) : IClassFixture<Data
context.HeartRatesSet.Add(heartRateEntry); context.HeartRatesSet.Add(heartRateEntry);
context.SaveChanges(); context.SaveChanges();
} }
// Ne veut pas passer, si quelqu'un sait pourquoi ... Erreur : System.ArgumentNullException : Value cannot be null. (Parameter 'entity')
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedHeartRate = context.HeartRatesSet.First(); var savedHeartRate = context.HeartRatesSet.FirstOrDefault(h => h.Altitude == 105.0);
var savedActivity = context.ActivitiesSet.FirstOrDefault(a => a.Type == "Run" && a.EffortFelt == 7 && a.Average == 0.4f);
context.HeartRatesSet.Remove(savedHeartRate); context.HeartRatesSet.Remove(savedHeartRate);
context.ActivitiesSet.Remove(savedActivity);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedHeartRate = context.HeartRatesSet.FirstOrDefault(); var deletedHeartRate = context.HeartRatesSet.FirstOrDefault(h => h.Altitude == 105.0);
Assert.Null(deletedHeartRate); Assert.Null(deletedHeartRate);
} }
} }

@ -43,7 +43,7 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedNotification = context.NotificationsSet.First(); var savedNotification = context.NotificationsSet.FirstOrDefault(n => n.Message == "Test notification" && n.Statut == false && n.Urgence == "High");
Assert.NotNull(savedNotification); Assert.NotNull(savedNotification);
Assert.Equal("Test notification", savedNotification.Message); Assert.Equal("Test notification", savedNotification.Message);
} }
@ -117,7 +117,7 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
var notification = new NotificationEntity var notification = new NotificationEntity
{ {
Message = "Test notification", Message = "Test notification Suppression",
Date = DateTime.Now, Date = DateTime.Now,
Statut = false, Statut = false,
Urgence = "High", Urgence = "High",
@ -134,14 +134,14 @@ public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<D
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedNotification = context.NotificationsSet.First(); var savedNotification = context.NotificationsSet.FirstOrDefault(n => n.Message == "Test notification Suppression");
context.NotificationsSet.Remove(savedNotification); context.NotificationsSet.Remove(savedNotification);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedNotification = context.NotificationsSet.FirstOrDefault(); var deletedNotification = context.NotificationsSet.FirstOrDefault(n => n.Message == "Test notification Suppression");
Assert.Null(deletedNotification); Assert.Null(deletedNotification);
} }
} }

@ -119,7 +119,7 @@ public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<Data
var statistic = new StatisticEntity var statistic = new StatisticEntity
{ {
Weight = 75.0f, Weight = 85.0f,
AverageHeartRate = 150.0, AverageHeartRate = 150.0,
MaximumHeartRate = 180.0, MaximumHeartRate = 180.0,
AverageCaloriesBurned = 500.0, AverageCaloriesBurned = 500.0,
@ -137,14 +137,14 @@ public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<Data
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedStatistic = context.StatisticsSet.FirstOrDefault(s => s.Weight == 75.0 && s.AverageHeartRate == 150.0 && s.MaximumHeartRate == 180.0); var savedStatistic = context.StatisticsSet.FirstOrDefault(s => s.Weight == 85.0 );
context.StatisticsSet.Remove(savedStatistic); context.StatisticsSet.Remove(savedStatistic);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedStatistic = context.StatisticsSet.FirstOrDefault(s => s.Weight == 75.0 && s.AverageHeartRate == 150.0 && s.MaximumHeartRate == 180.0); var deletedStatistic = context.StatisticsSet.FirstOrDefault(s => s.Weight == 85.0 );
Assert.Null(deletedStatistic); Assert.Null(deletedStatistic);
} }
} }

@ -41,7 +41,7 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
var training = new TrainingEntity var training = new TrainingEntity
{ {
Date = new DateOnly(2024, 3, 15), Date = new DateOnly(2024, 3, 15),
Description = "Training description", Description = "Training Description",
Latitude = 40.12345f, Latitude = 40.12345f,
Longitude = -74.56789f, Longitude = -74.56789f,
FeedBack = "Training feedback", FeedBack = "Training feedback",
@ -60,9 +60,9 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedTraining = context.TrainingsSet.First(); var savedTraining = context.TrainingsSet.FirstOrDefault(t => t.Description == "Training Description" && t.FeedBack == "Training feedback");
Assert.NotNull(savedTraining); Assert.NotNull(savedTraining);
Assert.Equal("Training description", savedTraining.Description); Assert.Equal("Training Description", savedTraining.Description);
} }
} }
@ -166,10 +166,10 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
var training = new TrainingEntity var training = new TrainingEntity
{ {
Date = new DateOnly(2024, 3, 15), Date = new DateOnly(2024, 3, 15),
Description = "Training description", Description = "Training description suppression",
Latitude = 40.12345f, Latitude = 40.12345f,
Longitude = -74.56789f, Longitude = -74.56789f,
FeedBack = "Training feedback", FeedBack = "Training feedback suppression",
Coach = coach, Coach = coach,
Athletes = { athlete } Athletes = { athlete }
}; };
@ -185,14 +185,14 @@ public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedTraining = context.TrainingsSet.First(); var savedTraining = context.TrainingsSet.FirstOrDefault(t => t.Description == "Training description suppression" && t.FeedBack == "Training feedback suppression");
context.TrainingsSet.Remove(savedTraining); context.TrainingsSet.Remove(savedTraining);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedTraining = context.TrainingsSet.FirstOrDefault(); var deletedTraining = context.TrainingsSet.FirstOrDefault(t => t.Description == "Training description suppression" && t.FeedBack == "Training feedback suppression");
Assert.Null(deletedTraining); Assert.Null(deletedTraining);
} }
} }

Loading…
Cancel
Save