From c0b5d1e4c55160780febcbeb0d342006fa9ab16d Mon Sep 17 00:00:00 2001 From: Damien Nortier Date: Tue, 12 Mar 2024 14:39:27 +0100 Subject: [PATCH] feat : context stubber --- .../StubbedDbContext.cs | 28 +++++++++++++++++++ .../StubbedDbContextLibrary.csproj | 14 ++++++++++ 2 files changed, 42 insertions(+) create mode 100644 WebApi/StubbedDbContextLibrary/StubbedDbContext.cs create mode 100644 WebApi/StubbedDbContextLibrary/StubbedDbContextLibrary.csproj diff --git a/WebApi/StubbedDbContextLibrary/StubbedDbContext.cs b/WebApi/StubbedDbContextLibrary/StubbedDbContext.cs new file mode 100644 index 0000000..75c192b --- /dev/null +++ b/WebApi/StubbedDbContextLibrary/StubbedDbContext.cs @@ -0,0 +1,28 @@ +using DbConnectionLibrairie; +using Entities; +using Microsoft.EntityFrameworkCore; + +namespace StubbedDbContextLibrary +{ + public class StubbedDbContext : MyDbContext + { + public StubbedDbContext() + { } + + public StubbedDbContext(DbContextOptions contextOptions) : + base(contextOptions) + { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + var fakeDatas = fakeAnswers.datas; + foreach (var datas in fakeDatas) + { + modelBuilder.Entity().HasData(fakeDatas); + } + } + + } +} diff --git a/WebApi/StubbedDbContextLibrary/StubbedDbContextLibrary.csproj b/WebApi/StubbedDbContextLibrary/StubbedDbContextLibrary.csproj new file mode 100644 index 0000000..d3677a5 --- /dev/null +++ b/WebApi/StubbedDbContextLibrary/StubbedDbContextLibrary.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + +