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.
Dotnet-WebAPI/StubContext/StubAppContext.cs

40 lines
1.1 KiB

using AppContext.Entities;
using Microsoft.EntityFrameworkCore;
namespace StubContext;
using AppContext;
public class StubAppContext(DbContextOptions<AppContext> options) : AppContext(options)
{
public StubAppContext() : this(
new DbContextOptionsBuilder<AppContext>()
.UseSqlite("DataSource=database.db")
.Options
)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
var users = new[] { "maxime", "mael", "yanis", "simon", "vivien" }.ToList();
var i = 0;
builder.Entity<UserEntity>()
.HasData(users.ConvertAll(name => new UserEntity
{
Id = ++i,
Email = $"{name}@mail.com",
Name = name,
Password = "123456",
IsAdmin = true,
ProfilePicture =
"https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png",
}));
builder.Entity<MemberEntity>()
.HasKey("TeamId", "UserId");
}
}