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.
API/src/Tests/UnitTestsEntities/FriendshipEntityTests.cs

205 lines
6.3 KiB

namespace UnitTestsEntities;
using Xunit;
using System.Linq;
using Entities;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
public class FriendshipEntityTests (DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
{
[Fact]
public void Add_Friendship_Success()
{
var follower = new AthleteEntity
{
Username = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
var friendship = new FriendshipEntity
{
Follower = follower,
Following = following,
StartDate = DateTime.Now
};/*
using (var context = new TrainingStubbedContext(fixture._options))
{
context.Database.EnsureCreated();
context.AthletesSet.Add(follower);
context.AthletesSet.Add(following);
context.Friendships.Add(friendship);
context.SaveChanges();
}
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedFriendship = context.Friendships.FirstOrDefault();
Assert.NotNull(savedFriendship);
Assert.Equal(follower.IdAthlete, savedFriendship.FollowerId);
Assert.Equal(following.IdAthlete, savedFriendship.FollowingId);
}*/
}
[Fact]
public void Update_Friendship_Success()
{
var follower = new AthleteEntity
{
Username = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
var thirdAthlete = new AthleteEntity
{
Username = "third_user",
LastName = "Third",
FirstName = "User",
Email = "third.user@example.com",
Sexe = "M",
Length = 180.0,
Weight = 75.0f,
Password = "thirdpassword",
DateOfBirth = new DateOnly(1988, 3, 15),
IsCoach = false
};
var friendship = new FriendshipEntity
{
Follower = follower,
Following = following,
StartDate = DateTime.Now
};/*
using (var context = new TrainingStubbedContext(fixture._options))
{
context.Database.EnsureCreated();
context.AthletesSet.Add(follower);
context.AthletesSet.Add(following);
context.AthletesSet.Add(thirdAthlete);
context.Friendships.Add(friendship);
context.SaveChanges();
}
using (var context = new TrainingStubbedContext(fixture._options))
{
var savedFriendship = context.Friendships.FirstOrDefault();
savedFriendship.Follower = thirdAthlete; // Update the follower
context.SaveChanges();
}
using (var context = new TrainingStubbedContext(fixture._options))
{
var updatedFriendship = context.Friendships.FirstOrDefault();
Assert.NotNull(updatedFriendship);
Assert.Equal(thirdAthlete.IdAthlete, updatedFriendship.FollowerId);
}*/
}
[Fact]
public void Delete_Friendship_Success()
{
// Act
var follower = new AthleteEntity
{
Username = "follower_user",
LastName = "Follower",
FirstName = "User",
Email = "follower.user@example.com",
Sexe = "M",
Length = 170.0,
Weight = 70.0f,
Password = "followerpassword",
DateOfBirth = new DateOnly(1990, 1, 1),
IsCoach = false
};
var following = new AthleteEntity
{
Username = "following_user",
LastName = "Following",
FirstName = "User",
Email = "following.user@example.com",
Sexe = "F",
Length = 165.0,
Weight = 60.0f,
Password = "followingpassword",
DateOfBirth = new DateOnly(1995, 5, 10),
IsCoach = false
};
/*
using (var context = new TrainingStubbedContext(fixture._options))
{
context.Database.EnsureCreated();
context.AthletesSet.Add(follower);
context.AthletesSet.Add(following);
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 TrainingStubbedContext(fixture._options))
{
var savedFriendship = context.Friendships.FirstOrDefault();
context.Friendships.Remove(savedFriendship);
context.SaveChanges();
}
using (var context = new TrainingStubbedContext(fixture._options))
{
var deletedFriendship = context.Friendships.FirstOrDefault();
Assert.Null(deletedFriendship);
}*/
}
}