You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.1 KiB
141 lines
4.1 KiB
namespace UnitTestsEntities;
|
|
using Xunit;
|
|
using System.Linq;
|
|
using Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using StubbedContextLib;
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
public class ActivityEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
|
|
{
|
|
[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
|
|
};
|
|
/*
|
|
using (var context = new TrainingStubbedContext(fixture._options))
|
|
{
|
|
context.Database.EnsureCreated();
|
|
context.Activities.Add(activity);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
using (var context = new TrainingStubbedContext(options))
|
|
{
|
|
var savedActivity = context.Activities.First(a => a.Type == "Running");
|
|
Assert.NotNull(savedActivity);
|
|
Assert.Equal("Running", savedActivity.Type );
|
|
|
|
}*/
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_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
|
|
};
|
|
|
|
/*
|
|
using (var context = new StubbedContext(options))
|
|
{
|
|
context.Database.EnsureCreated();
|
|
context.Activities.Add(activity);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
using (var context = new StubbedContext(options))
|
|
{
|
|
var savedActivity = context.Activities.First(a => a.Type == "Running");
|
|
savedActivity.Type = "Walking";
|
|
context.SaveChanges();
|
|
}
|
|
|
|
using (var context = new StubbedContext(options))
|
|
{
|
|
var updatedActivity = context.Activities.First(a => a.Type == "Walking");
|
|
Assert.NotNull(updatedActivity);
|
|
Assert.Equal("Walking", updatedActivity.Type );
|
|
Assert.Equal(7, updatedActivity.EffortFelt );
|
|
}*/
|
|
}
|
|
|
|
[Fact]
|
|
public void Delete_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
|
|
};
|
|
|
|
/*
|
|
using (var context = new StubbedContext(options))
|
|
{
|
|
context.Database.EnsureCreated();
|
|
context.Activities.Add(activity);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
using (var context = new StubbedContext(options))
|
|
{
|
|
var savedActivity = context.Activities.First(a => a.Type == "Running");
|
|
context.Activities.Remove(savedActivity);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
using (var context = new StubbedContext(options))
|
|
{
|
|
var deletedActivity = context.Activities.FirstOrDefault(a => a.Type == "Running");
|
|
Assert.Null(deletedActivity);
|
|
}*/
|
|
}
|
|
}
|
|
|