Tests
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
a3d86c625b
commit
205fb3882a
@ -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<StubbedContext>()
|
||||
.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<StubbedContext>()
|
||||
.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);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
namespace UnitTestsEntities;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
namespace UnitTestsEntities2
|
||||
{
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<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="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>
|
Loading…
Reference in new issue