🚨 Unite all DbSets in one context

pull/52/head
Alexis Drai 2 years ago
parent 87e39504f7
commit 76e9f4de32

@ -31,20 +31,20 @@ namespace cat_cafe.Controllers.Tests
private readonly MapperConfiguration mapperConf = new(mapper => mapper.AddProfile(typeof(CatMapper)));
private readonly DbContextOptions<CatContext> options = new DbContextOptionsBuilder<CatContext>()
private readonly DbContextOptions<CatCafeContext> options = new DbContextOptionsBuilder<CatCafeContext>()
.UseInMemoryDatabase(databaseName: "CatCafeTests")
.Options;
private readonly IMapper mapper;
private readonly CatContext context;
private readonly CatCafeContext context;
private readonly CatsController controller;
public CatsControllerTest()
{
mapper = mapperConf.CreateMapper();
context = new CatContext(options);
context = new CatCafeContext(options);
controller = new CatsController(context, mapper, logger);
}

@ -18,11 +18,11 @@ namespace cat_cafe.Controllers
[ApiController]
public class BarsController : ControllerBase
{
private readonly BarContext _context;
private readonly CatCafeContext _context;
private readonly IMapper _mapper;
private readonly ILogger <BarsController> _logger;
public BarsController(BarContext context,IMapper mapper, ILogger<BarsController> logger)
public BarsController(CatCafeContext context,IMapper mapper, ILogger<BarsController> logger)
{
_context = context;
_mapper = mapper;

@ -19,11 +19,11 @@ namespace cat_cafe.Controllers
[ApiController]
public class CatsController : ControllerBase
{
private readonly CatContext _context;
private readonly CatCafeContext _context;
private readonly IMapper _mapper;
private readonly ILogger<CatsController> _logger;
public CatsController(CatContext context, IMapper mapper, ILogger<CatsController> logger)
public CatsController(CatCafeContext context, IMapper mapper, ILogger<CatsController> logger)
{
_mapper = mapper;
_context = context;

@ -18,11 +18,11 @@ namespace cat_cafe.Controllers
[ApiController]
public class CustomersController : ControllerBase
{
private readonly CustomerContext _context;
private readonly CatCafeContext _context;
private readonly IMapper _mapper;
private readonly ILogger<CustomersController> _logger;
public CustomersController(CustomerContext context,IMapper mapper,ILogger<CustomersController> logger)
public CustomersController(CatCafeContext context,IMapper mapper,ILogger<CustomersController> logger)
{
_context = context;
_mapper = mapper;

@ -10,7 +10,7 @@ Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.File("
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddDbContext<CatContext>(opt => opt.UseInMemoryDatabase("CatCafe"));
builder.Services.AddDbContext<CatCafeContext>(opt => opt.UseInMemoryDatabase("CatCafe"));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddAutoMapper(typeof(Program));

@ -1,17 +0,0 @@
using cat_cafe.Entities;
using Microsoft.EntityFrameworkCore;
using System;
namespace cat_cafe.Repositories
{
public class BarContext : DbContext
{
public BarContext(DbContextOptions<BarContext> options)
: base(options)
{
}
public DbSet<Bar> Bars { get; set; } = null!;
}
}

@ -3,9 +3,9 @@ using Microsoft.EntityFrameworkCore;
namespace cat_cafe.Repositories
{
public class CatContext : DbContext
public class CatCafeContext : DbContext
{
public CatContext(DbContextOptions<CatContext> options)
public CatCafeContext(DbContextOptions<CatCafeContext> options)
: base(options)
{
}

@ -1,14 +0,0 @@
using System;
using cat_cafe.Entities;
using Microsoft.EntityFrameworkCore;
namespace cat_cafe.Repositories
{
public class CustomerContext:DbContext
{
public CustomerContext(DbContextOptions<CustomerContext> options)
: base(options)
{ }
public DbSet<Customer> Customers { get; set; } = null!;
}
}
Loading…
Cancel
Save