// Returns NON MOCKED DBContext that points to the real SQL Database private static TuiDbContext SqlTuiContext() { var webHostBuilder = new WebHostBuilder(); var env = webHostBuilder.GetSetting("environment"); var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env}.json", true) .AddEnvironmentVariables(); var config = builder.Build(); var connstr = config.GetConnectionString("TUIDatabase"); Assert.IsNotNull(connstr); var options = new DbContextOptionsBuilder <TuiDbContext>() .UseSqlServer(connstr) .Options; Assert.IsNotNull(options); var context = new TuiDbContext(options); Assert.IsNotNull(context); return(context); }
/// <summary> /// MockContext /// </summary> /// <returns>void</returns> public static TuiDbContext MockContext() { // In-memory database by GUID. This is to make sure that every test run has new database. var options = new DbContextOptionsBuilder <TuiDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new TuiDbContext(options); var flights = new List <Core.Models.Flights> { new Core.Models.Flights { Id = 1, FlightId = "13584", DepartureAirport = "Paris", ArrivalAirport = "Doubaï", StartDate = Convert.ToDateTime("1/1/2018", CultureInfo.InvariantCulture), EndDate = Convert.ToDateTime("1/2/2018", CultureInfo.InvariantCulture) }, new Core.Models.Flights { Id = 3, FlightId = "13585", DepartureAirport = "Paris", ArrivalAirport = "Marrackech", StartDate = Convert.ToDateTime("1/2/2018", CultureInfo.InvariantCulture), EndDate = Convert.ToDateTime("1/3/2018", CultureInfo.InvariantCulture) }, new Core.Models.Flights { Id = 2, FlightId = "13586", DepartureAirport = "Paris", StartDate = Convert.ToDateTime("1/3/2018", CultureInfo.InvariantCulture), EndDate = Convert.ToDateTime("1/4/2018", CultureInfo.InvariantCulture) } }; // Load InMemory Mock-Flights with Data foreach (var flight in flights) { context.Flights.Add(flight); } context.SaveChanges(); return(context); }
/// <summary> /// Initializes a new instance of the <see cref="FlightRepository"/> class. /// FlightRepository /// </summary> /// <param name="tuiContext">qngContext</param> /// <param name="logger">logger</param> public FlightRepository(TuiDbContext tuiContext, ILogger <FlightRepository> logger) : base(tuiContext) { this._tuiContext = tuiContext ?? throw new ArgumentNullException(nameof(tuiContext)); this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="FlightRepository"/> class. /// FlightRepository /// </summary> /// <param name="tuiContext">qngContext</param> public FlightRepository(TuiDbContext tuiContext) : base(tuiContext) { this._tuiContext = tuiContext ?? throw new ArgumentNullException(nameof(tuiContext)); }
public ReportController(TuiDbContext dbContext) { this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="TuiUnitOfWork"/> class. /// UnitOfWork /// </summary> /// <param name="dbContext">dbContext</param> public TuiUnitOfWork(TuiDbContext dbContext) { this._context = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); this.FlightRepository = this._context.GetService <IFlightRepository>(); }
/// <summary> /// Initializes a new instance of the <see cref="GenericRepository{TEntity}"/> class. /// GenericRepository /// </summary> /// <param name="context">context</param> public GenericRepository(TuiDbContext context) { this.Context = context ?? throw new ArgumentNullException(nameof(context)); this.DbSet = context.Set <TEntity>(); }
public HomeController(TuiDbContext dbContext) { this.DbContext = dbContext; }
public ValuesController(TuiDbContext dbContext) { this.DbContext = dbContext; }
public FlightController(TuiDbContext dbContext, IAirportDistanceResolver distanceResolver, IFuelConsumptionService fuelService) { this.DbContext = dbContext; this.DistanceResolver = distanceResolver; this.FuelService = fuelService; }