diff --git a/src/StubbedContextLib/StubbedContextLib.csproj b/src/StubbedContextLib/StubbedContextLib.csproj index bdd147f..0c5f479 100644 --- a/src/StubbedContextLib/StubbedContextLib.csproj +++ b/src/StubbedContextLib/StubbedContextLib.csproj @@ -13,6 +13,10 @@ + + + + net8.0 enable diff --git a/src/Tests/UnitTestsEntities/ActivityEntityTests.cs b/src/Tests/UnitTestsEntities/ActivityEntityTests.cs new file mode 100644 index 0000000..bc8e091 --- /dev/null +++ b/src/Tests/UnitTestsEntities/ActivityEntityTests.cs @@ -0,0 +1,149 @@ +namespace UnitTestsEntities; +using Xunit; +using System.Linq; +using Entities; +using Microsoft.EntityFrameworkCore; + +public class ActivityEntityTests +{ + /*[Fact] + public void Add_Activity_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 + }; + + // Act + using (var context = new StubbedContext(options)) + { + context.Database.EnsureCreated(); + context.Activities.Add(activity); + context.SaveChanges(); + } + + // Assert + using (var context = new StubbedContext(options)) + { + var savedActivity = context.Activities.First(a => a.Type == "Running"); + Assert.NotNull(savedActivity); + } + } + + [Fact] + public void Update_Activity_Success() + { + // Arrange + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Update_Activity_Success") + .Options; + + 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 + }; + + using (var context = new StubbedContext(options)) + { + context.Database.EnsureCreated(); + context.Activities.Add(activity); + context.SaveChanges(); + } + + // Act + using (var context = new StubbedContext(options)) + { + var savedActivity = context.Activities.First(a => a.Type == "Running"); + savedActivity.Type = "Walking"; + context.SaveChanges(); + } + + // Assert + using (var context = new StubbedContext(options)) + { + var updatedActivity = context.Activities.First(a => a.Type == "Walking"); + Assert.NotNull(updatedActivity); + } + } + + [Fact] + public void Delete_Activity_Success() + { + // Arrange + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Activity_Success") + .Options; + + 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 + }; + + using (var context = new StubbedContext(options)) + { + context.Database.EnsureCreated(); + context.Activities.Add(activity); + context.SaveChanges(); + } + + // Act + using (var context = new StubbedContext(options)) + { + var savedActivity = context.Activities.First(a => a.Type == "Running"); + context.Activities.Remove(savedActivity); + context.SaveChanges(); + } + + // Assert + using (var context = new StubbedContext(options)) + { + var deletedActivity = context.Activities.FirstOrDefault(a => a.Type == "Running"); + Assert.Null(deletedActivity); + } + }*/ +} + diff --git a/src/Tests/UnitTestsEntities/UnitTest1.cs b/src/Tests/UnitTestsEntities/UnitTest1.cs deleted file mode 100644 index 4494897..0000000 --- a/src/Tests/UnitTestsEntities/UnitTest1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace UnitTestsEntities; - -public class UnitTest1 -{ - [Fact] - public void Test1() - { - - } -} \ No newline at end of file diff --git a/src/Tests/UnitTestsEntities/UnitTestsEntities.csproj b/src/Tests/UnitTestsEntities/UnitTestsEntities.csproj index 22b0134..e372137 100644 --- a/src/Tests/UnitTestsEntities/UnitTestsEntities.csproj +++ b/src/Tests/UnitTestsEntities/UnitTestsEntities.csproj @@ -10,6 +10,7 @@ + @@ -22,4 +23,8 @@ + + + + diff --git a/src/UnitTestsEntities2/UnitTest1.cs b/src/UnitTestsEntities2/UnitTest1.cs new file mode 100644 index 0000000..8b121a7 --- /dev/null +++ b/src/UnitTestsEntities2/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace UnitTestsEntities2 +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} \ No newline at end of file diff --git a/src/UnitTestsEntities2/UnitTestsEntities2.csproj b/src/UnitTestsEntities2/UnitTestsEntities2.csproj new file mode 100644 index 0000000..9c5b30a --- /dev/null +++ b/src/UnitTestsEntities2/UnitTestsEntities2.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + +