🚑💥 Tests in memory Entities 14/24
continuous-integration/drone/push Build is failing Details

WORK-KEV
Kevin MONTEIRO 1 year ago
parent 681ab41800
commit bbb66c6059

@ -30,21 +30,20 @@ public class ActivityEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
DataSourceId = 1, DataSourceId = 1,
AthleteId = 1 AthleteId = 1
}; };
/*
using (var context = new TrainingStubbedContext(fixture._options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Activities.Add(activity); context.ActivitiesSet.Add(activity);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new TrainingStubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedActivity = context.Activities.First(a => a.Type == "Running"); var savedActivity = context.ActivitiesSet.First(a => a.Type == "Running");
Assert.NotNull(savedActivity); Assert.NotNull(savedActivity);
Assert.Equal("Running", savedActivity.Type ); Assert.Equal("Running", savedActivity.Type );
}
}*/
} }
[Fact] [Fact]
@ -69,28 +68,27 @@ public class ActivityEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
AthleteId = 1 AthleteId = 1
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Activities.Add(activity); context.ActivitiesSet.Add(activity);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedActivity = context.Activities.First(a => a.Type == "Running"); var savedActivity = context.ActivitiesSet.First(a => a.Type == "Running");
savedActivity.Type = "Walking"; savedActivity.Type = "Walking";
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedActivity = context.Activities.First(a => a.Type == "Walking"); var updatedActivity = context.ActivitiesSet.First(a => a.Type == "Walking");
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 );
}*/ }
} }
[Fact] [Fact]
@ -115,26 +113,26 @@ public class ActivityEntityTests (DatabaseFixture fixture) : IClassFixture<Datab
AthleteId = 1 AthleteId = 1
}; };
/*
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Activities.Add(activity); context.ActivitiesSet.Add(activity);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedActivity = context.Activities.First(a => a.Type == "Running"); var savedActivity = context.ActivitiesSet.First(a => a.Type == "Running");
context.Activities.Remove(savedActivity); context.ActivitiesSet.Remove(savedActivity);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedActivity = context.Activities.FirstOrDefault(a => a.Type == "Running"); var deletedActivity = context.ActivitiesSet.FirstOrDefault(a => a.Type == "Running");
Assert.Null(deletedActivity); Assert.Null(deletedActivity);
}*/ }
} }
} }

@ -3,8 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class AthleteEntityTests public class AthleteEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
{ {
[Fact] [Fact]
public void Add_Athlete_Success() public void Add_Athlete_Success()
@ -23,20 +24,20 @@ public class AthleteEntityTests
IsCoach = false IsCoach = false
}; };
/*
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedAthlete = context.Athletes.First(a => a.Username == "john_doe"); var savedAthlete = context.AthletesSet.First(a => a.Username == "john_doe");
Assert.NotNull(savedAthlete); Assert.NotNull(savedAthlete);
Assert.Equal("john_doe", savedAthlete.Username); Assert.Equal("john_doe", savedAthlete.Username);
}*/ }
} }
[Fact] [Fact]
@ -56,28 +57,27 @@ public class AthleteEntityTests
IsCoach = false IsCoach = false
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedAthlete = context.Athletes.First(a => a.Username == "jane_smith"); var savedAthlete = context.AthletesSet.First(a => a.Username == "jane_smith");
savedAthlete.Username = "jane_doe"; savedAthlete.Username = "jane_doe";
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedAthlete = context.Athletes.First(a => a.Username == "jane_doe"); var updatedAthlete = context.AthletesSet.First(a => a.Username == "jane_doe");
Assert.NotNull(updatedAthlete); Assert.NotNull(updatedAthlete);
Assert.Equal("jane_doe", updatedAthlete.Username); Assert.Equal("jane_doe", updatedAthlete.Username);
Assert.Equal("Smith", updatedAthlete.LastName); Assert.Equal("Smith", updatedAthlete.LastName);
}*/ }
} }
[Fact] [Fact]
@ -97,26 +97,25 @@ public class AthleteEntityTests
IsCoach = false IsCoach = false
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedAthlete = context.Athletes.First(a => a.Username == "test_user"); var savedAthlete = context.AthletesSet.First(a => a.Username == "test_user");
context.Athletes.Remove(savedAthlete); context.AthletesSet.Remove(savedAthlete);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedAthlete = context.Athletes.FirstOrDefault(a => a.Username == "test_user"); var deletedAthlete = context.AthletesSet.FirstOrDefault(a => a.Username == "test_user");
Assert.Null(deletedAthlete); Assert.Null(deletedAthlete);
}*/ }
} }
} }

@ -3,9 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class DataSourceEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
public class DataSourceEntityTests
{ {
[Fact] [Fact]
public void Add_DataSource_Success() public void Add_DataSource_Success()
@ -17,20 +17,19 @@ public class DataSourceEntityTests
Precision = 0.1f Precision = 0.1f
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.DataSources.Add(dataSource); context.DataSourcesSet.Add(dataSource);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedDataSource = context.DataSources.First(d => d.Type == "GPS"); var savedDataSource = context.DataSourcesSet.First(d => d.Type == "GPS");
Assert.NotNull(savedDataSource); Assert.NotNull(savedDataSource);
Assert.Equal("Garmin Forerunner 945", savedDataSource.Model); Assert.Equal("Garmin Forerunner 945", savedDataSource.Model);
}*/ }
} }
[Fact] [Fact]
@ -43,28 +42,27 @@ public class DataSourceEntityTests
Precision = 0.2f Precision = 0.2f
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.DataSources.Add(dataSource); context.DataSourcesSet.Add(dataSource);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedDataSource = context.DataSources.First(d => d.Type == "Heart Rate Monitor"); var savedDataSource = context.DataSourcesSet.First(d => d.Type == "Heart Rate Monitor");
savedDataSource.Model = "Polar H9"; savedDataSource.Model = "Polar H9";
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedDataSource = context.DataSources.First(d => d.Model == "Polar H9"); var updatedDataSource = context.DataSourcesSet.First(d => d.Model == "Polar H9");
Assert.NotNull(updatedDataSource); Assert.NotNull(updatedDataSource);
Assert.Equal("Heart Rate Monitor", updatedDataSource.Type); Assert.Equal("Heart Rate Monitor", updatedDataSource.Type);
Assert.Equal(0.2f, updatedDataSource.Precision); Assert.Equal(0.2f, updatedDataSource.Precision);
}*/ }
} }
[Fact] [Fact]
@ -77,26 +75,25 @@ public class DataSourceEntityTests
Precision = 0.05f Precision = 0.05f
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.DataSources.Add(dataSource); context.DataSourcesSet.Add(dataSource);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedDataSource = context.DataSources.First(d => d.Type == "Smartwatch"); var savedDataSource = context.DataSourcesSet.First(d => d.Type == "Smartwatch");
context.DataSources.Remove(savedDataSource); context.DataSourcesSet.Remove(savedDataSource);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedDataSource = context.DataSources.FirstOrDefault(d => d.Type == "Smartwatch"); var deletedDataSource = context.DataSourcesSet.FirstOrDefault(d => d.Type == "Smartwatch");
Assert.Null(deletedDataSource); Assert.Null(deletedDataSource);
}*/ }
} }
} }

@ -1,4 +1,5 @@
using Microsoft.Data.Sqlite; using DbContextLib;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib; using StubbedContextLib;
@ -7,13 +8,13 @@ namespace UnitTestsEntities;
public class DatabaseFixture : IDisposable public class DatabaseFixture : IDisposable
{ {
private readonly SqliteConnection _connection; private readonly SqliteConnection _connection;
public readonly DbContextOptions<TrainingStubbedContext> _options; public readonly DbContextOptions<HeartTrackContext> _options;
public DatabaseFixture() public DatabaseFixture()
{ {
_connection = new SqliteConnection("DataSource=:memory:"); _connection = new SqliteConnection("DataSource=:memory:");
_connection.Open(); _connection.Open();
_options = new DbContextOptionsBuilder<TrainingStubbedContext>() _options = new DbContextOptionsBuilder<HeartTrackContext>()
.UseSqlite(_connection) .UseSqlite(_connection)
.Options; .Options;

@ -3,8 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class FriendshipEntityTests public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
{ {
[Fact] [Fact]
public void Add_Friendship_Success() public void Add_Friendship_Success()
@ -42,19 +43,18 @@ public class FriendshipEntityTests
Follower = follower, Follower = follower,
Following = following, Following = following,
StartDate = DateTime.Now StartDate = DateTime.Now
}; };/*
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(follower); context.AthletesSet.Add(follower);
context.Athletes.Add(following); context.AthletesSet.Add(following);
context.Friendships.Add(friendship); context.Friendships.Add(friendship);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedFriendship = context.Friendships.FirstOrDefault(); var savedFriendship = context.Friendships.FirstOrDefault();
Assert.NotNull(savedFriendship); Assert.NotNull(savedFriendship);
@ -113,27 +113,26 @@ public class FriendshipEntityTests
Follower = follower, Follower = follower,
Following = following, Following = following,
StartDate = DateTime.Now StartDate = DateTime.Now
}; };/*
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(follower); context.AthletesSet.Add(follower);
context.Athletes.Add(following); context.AthletesSet.Add(following);
context.Athletes.Add(thirdAthlete); context.AthletesSet.Add(thirdAthlete);
context.Friendships.Add(friendship); context.Friendships.Add(friendship);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedFriendship = context.Friendships.FirstOrDefault(); var savedFriendship = context.Friendships.FirstOrDefault();
savedFriendship.Follower = thirdAthlete; // Update the follower savedFriendship.Follower = thirdAthlete; // Update the follower
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedFriendship = context.Friendships.FirstOrDefault(); var updatedFriendship = context.Friendships.FirstOrDefault();
Assert.NotNull(updatedFriendship); Assert.NotNull(updatedFriendship);
@ -144,6 +143,7 @@ public class FriendshipEntityTests
[Fact] [Fact]
public void Delete_Friendship_Success() public void Delete_Friendship_Success()
{ {
// Act
var follower = new AthleteEntity var follower = new AthleteEntity
{ {
Username = "follower_user", Username = "follower_user",
@ -172,31 +172,29 @@ public class FriendshipEntityTests
IsCoach = false IsCoach = false
}; };
var friendship = new FriendshipEntity
{
Follower = follower,
Following = following,
StartDate = DateTime.Now
};
/* /*
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(follower); context.AthletesSet.Add(follower);
context.Athletes.Add(following); context.AthletesSet.Add(following);
context.Friendships.Add(friendship);
context.SaveChanges(); context.SaveChanges();
var user1 = context.AthletesSet.FirstOrDefault(a => a.IdAthlete == follower.IdAthlete);
var user2 = context.AthletesSet.FirstOrDefault(a => a.IdAthlete == following.IdAthlete);
user1.Followers = user2.IdAthlete;
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedFriendship = context.Friendships.FirstOrDefault(); var savedFriendship = context.Friendships.FirstOrDefault();
context.Friendships.Remove(savedFriendship); context.Friendships.Remove(savedFriendship);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedFriendship = context.Friendships.FirstOrDefault(); var deletedFriendship = context.Friendships.FirstOrDefault();
Assert.Null(deletedFriendship); Assert.Null(deletedFriendship);

@ -3,8 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class HeartRateEntityTests public class HeartRateEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
{ {
[Fact] [Fact]
public void Add_HeartRate_Success() public void Add_HeartRate_Success()
@ -39,21 +40,21 @@ public class HeartRateEntityTests
Activity = activity Activity = activity
}; };
/*
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Activities.Add(activity); context.ActivitiesSet.Add(activity);
context.HeartRates.Add(heartRateEntry); context.HeartRatesSet.Add(heartRateEntry);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedHeartRate = context.HeartRates.First(); var savedHeartRate = context.HeartRatesSet.First();
Assert.NotNull(savedHeartRate); Assert.NotNull(savedHeartRate);
Assert.Equal(150, savedHeartRate.Bpm); Assert.Equal(150, savedHeartRate.Bpm);
}*/ }
} }
[Fact] [Fact]
@ -89,28 +90,27 @@ public class HeartRateEntityTests
Activity = activity Activity = activity
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Activities.Add(activity); context.ActivitiesSet.Add(activity);
context.HeartRates.Add(heartRateEntry); context.HeartRatesSet.Add(heartRateEntry);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedHeartRate = context.HeartRates.First(); var savedHeartRate = context.HeartRatesSet.First();
savedHeartRate.Bpm = 160; savedHeartRate.Bpm = 160;
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedHeartRate = context.HeartRates.First(); var updatedHeartRate = context.HeartRatesSet.First();
Assert.NotNull(updatedHeartRate); Assert.NotNull(updatedHeartRate);
Assert.Equal(160, updatedHeartRate.Bpm); Assert.Equal(160, updatedHeartRate.Bpm);
}*/ }
} }
[Fact] [Fact]
@ -146,27 +146,26 @@ public class HeartRateEntityTests
Activity = activity Activity = activity
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Activities.Add(activity); context.ActivitiesSet.Add(activity);
context.HeartRates.Add(heartRateEntry); context.HeartRatesSet.Add(heartRateEntry);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedHeartRate = context.HeartRates.First(); var savedHeartRate = context.HeartRatesSet.First();
context.HeartRates.Remove(savedHeartRate); context.HeartRatesSet.Remove(savedHeartRate);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedHeartRate = context.HeartRates.FirstOrDefault(); var deletedHeartRate = context.HeartRatesSet.FirstOrDefault();
Assert.Null(deletedHeartRate); Assert.Null(deletedHeartRate);
}*/ }
} }
} }

@ -3,8 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class NotificationEntityTests public class NotificationEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
{ {
[Fact] [Fact]
public void Add_Notification_Success() public void Add_Notification_Success()
@ -32,21 +33,20 @@ public class NotificationEntityTests
Sender = sender Sender = sender
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(sender); context.AthletesSet.Add(sender);
context.Notifications.Add(notification); context.NotificationsSet.Add(notification);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedNotification = context.Notifications.First(); var savedNotification = context.NotificationsSet.First();
Assert.NotNull(savedNotification); Assert.NotNull(savedNotification);
Assert.Equal("Test notification", savedNotification.Message); Assert.Equal("Test notification", savedNotification.Message);
}*/ }
} }
[Fact] [Fact]
@ -75,28 +75,27 @@ public class NotificationEntityTests
Sender = sender Sender = sender
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(sender); context.AthletesSet.Add(sender);
context.Notifications.Add(notification); context.NotificationsSet.Add(notification);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedNotification = context.Notifications.First(); var savedNotification = context.NotificationsSet.First();
savedNotification.Message = "Updated message"; savedNotification.Message = "Updated message";
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedNotification = context.Notifications.First(); var updatedNotification = context.NotificationsSet.First();
Assert.NotNull(updatedNotification); Assert.NotNull(updatedNotification);
Assert.Equal("Updated message", updatedNotification.Message); Assert.Equal("Updated message", updatedNotification.Message);
}*/ }
} }
[Fact] [Fact]
@ -125,27 +124,26 @@ public class NotificationEntityTests
Sender = sender Sender = sender
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(sender); context.AthletesSet.Add(sender);
context.Notifications.Add(notification); context.NotificationsSet.Add(notification);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedNotification = context.Notifications.First(); var savedNotification = context.NotificationsSet.First();
context.Notifications.Remove(savedNotification); context.NotificationsSet.Remove(savedNotification);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedNotification = context.Notifications.FirstOrDefault(); var deletedNotification = context.NotificationsSet.FirstOrDefault();
Assert.Null(deletedNotification); Assert.Null(deletedNotification);
}*/ }
} }
} }

@ -3,9 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class StatisticEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
public class StatisticEntityTests
{ {
[Fact] [Fact]
public void Add_Statistic_Success() public void Add_Statistic_Success()
@ -34,21 +34,20 @@ public class StatisticEntityTests
Athlete = athlete Athlete = athlete
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.Statistics.Add(statistic); context.StatisticsSet.Add(statistic);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedStatistic = context.Statistics.First(); var savedStatistic = context.StatisticsSet.FirstOrDefault(s => s.AverageHeartRate == 150.0 && s.MaximumHeartRate == 180.0);
Assert.NotNull(savedStatistic); Assert.NotNull(savedStatistic);
Assert.Equal(75.0f, savedStatistic.Weight); Assert.Equal(75.0f, savedStatistic.Weight);
}*/ }
} }
[Fact] [Fact]
@ -78,28 +77,27 @@ public class StatisticEntityTests
Athlete = athlete Athlete = athlete
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.Statistics.Add(statistic); context.StatisticsSet.Add(statistic);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedStatistic = context.Statistics.First(); var savedStatistic = context.StatisticsSet.First();
savedStatistic.Weight = 80.0f; savedStatistic.Weight = 80.0f;
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedStatistic = context.Statistics.First(); var updatedStatistic = context.StatisticsSet.First();
Assert.NotNull(updatedStatistic); Assert.NotNull(updatedStatistic);
Assert.Equal(80.0f, updatedStatistic.Weight); Assert.Equal(80.0f, updatedStatistic.Weight);
}*/ }
} }
[Fact] [Fact]
@ -129,27 +127,26 @@ public class StatisticEntityTests
Athlete = athlete Athlete = athlete
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.Statistics.Add(statistic); context.StatisticsSet.Add(statistic);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedStatistic = context.Statistics.First(); var savedStatistic = context.StatisticsSet.FirstOrDefault(s => s.Weight == 75.0 && s.AverageHeartRate == 150.0 && s.MaximumHeartRate == 180.0);
context.Statistics.Remove(savedStatistic); context.StatisticsSet.Remove(savedStatistic);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedStatistic = context.Statistics.FirstOrDefault(); var deletedStatistic = context.StatisticsSet.FirstOrDefault(s => s.Weight == 75.0 && s.AverageHeartRate == 150.0 && s.MaximumHeartRate == 180.0);
Assert.Null(deletedStatistic); Assert.Null(deletedStatistic);
}*/ }
} }
} }

@ -3,9 +3,9 @@ using Xunit;
using System.Linq; using System.Linq;
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class TrainingEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
public class TrainingEntityTests
{ {
[Fact] [Fact]
public void Add_Training_Success() public void Add_Training_Success()
@ -49,22 +49,21 @@ public class TrainingEntityTests
Athletes = { athlete } Athletes = { athlete }
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(coach); context.AthletesSet.Add(coach);
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.Trainings.Add(training); context.TrainingsSet.Add(training);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedTraining = context.Trainings.First(); var savedTraining = context.TrainingsSet.First();
Assert.NotNull(savedTraining); Assert.NotNull(savedTraining);
Assert.Equal("Training description", savedTraining.Description); Assert.Equal("Training description", savedTraining.Description);
}*/ }
} }
[Fact] [Fact]
@ -109,29 +108,28 @@ public class TrainingEntityTests
Athletes = { athlete } Athletes = { athlete }
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(coach); context.AthletesSet.Add(coach);
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.Trainings.Add(training); context.TrainingsSet.Add(training);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedTraining = context.Trainings.First(); var savedTraining = context.TrainingsSet.First();
savedTraining.Description = "Updated training description"; savedTraining.Description = "Updated training description";
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var updatedTraining = context.Trainings.First(); var updatedTraining = context.TrainingsSet.First();
Assert.NotNull(updatedTraining); Assert.NotNull(updatedTraining);
Assert.Equal("Updated training description", updatedTraining.Description); Assert.Equal("Updated training description", updatedTraining.Description);
}*/ }
} }
[Fact] [Fact]
@ -176,27 +174,26 @@ public class TrainingEntityTests
Athletes = { athlete } Athletes = { athlete }
}; };
/* using (var context = new TrainingStubbedContext(fixture._options))
using (var context = new StubbedContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.Athletes.Add(coach); context.AthletesSet.Add(coach);
context.Athletes.Add(athlete); context.AthletesSet.Add(athlete);
context.Trainings.Add(training); context.TrainingsSet.Add(training);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var savedTraining = context.Trainings.First(); var savedTraining = context.TrainingsSet.First();
context.Trainings.Remove(savedTraining); context.TrainingsSet.Remove(savedTraining);
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new StubbedContext(options)) using (var context = new TrainingStubbedContext(fixture._options))
{ {
var deletedTraining = context.Trainings.FirstOrDefault(); var deletedTraining = context.TrainingsSet.FirstOrDefault();
Assert.Null(deletedTraining); Assert.Null(deletedTraining);
}*/ }
} }
} }

Loading…
Cancel
Save