public void CreateBookingWithNoBooking() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "CreateBookingWithNoBooking") .Options; using (var flightContext = new FlightsContext(options)) { var bookingController = new BookingController(flightContext); var result = bookingController.Create(null); Assert.IsTrue(result is BadRequestResult); } }
private static async Task QueryData(FlightsContext flightsContext) { var query = "SELECT * FROM flights WHERE flights.Origin = 'SFO'"; var flights = await flightsContext.QueryDocumentAsync <Flight>( query, flightsContext.FlightsDocumentCollectionSelfLink); foreach (var flight in flights) { await Console.Out.WriteLineAsync( $"[{flight.Number}]\t{flight.Origin} -> {flight.Destination}"); } }
public HomeController() { _context = new FlightsContext(); _flightWriteRepository = new WriteRepository <Flight>(_context); _flightReadRepository = new ReadRepository <Flight>(_context); //_flightWriteRepository.Save(new Flight() //{ // Id = 1, // CityFrom = "Wrocław", // CityTo = "Oława", // DepartureTime = 1300, // ArrivalTime = 1400, // FreeSeats = 100, // Price = 39.99 //}); }
private bool Isvalid(string username, string password) { bool Isvalid = false; using (FlightsContext db = new FlightsContext()) { var user = db.FlyRegisters.FirstOrDefault(s => s.UserName == username); if (user != null) { if (user.Password == password) { Isvalid = true; } } } return(Isvalid); }
public async Task SeedAsync(FlightsContext context, ILogger <FlightsContextSeed> logger) { var policy = CreatePolicy(logger, nameof(FlightsContextSeed)); await policy.ExecuteAsync(async() => { using (context) { context.Database.Migrate(); if (!context.Flights.Any()) { context.Flights.AddRange(GetFlights()); await context.SaveChangesAsync(); } } }); }
public void AvailableFlightsWithEndDate() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "AvailableFlightsWithEndDate") .Options; using (var flightContext = new FlightsContext(options)) { var search = new Search(flightContext); try { search.GetAvailableFlights(DateTime.MinValue, new DateTime(2018, 5, 10), null); } catch (ArgumentException exception) { Assert.AreEqual("Missing required argument.", exception.Message); throw; } } }
public void SearchWithNoValidParameters() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "SearchWithNoValidParameters") .Options; using (var flightContext = new FlightsContext(options)) { var search = new Search(flightContext); try { search.SearchForBooking(string.Empty, DateTime.MinValue, null, string.Empty, string.Empty); } catch (ArgumentException exception) { Assert.AreEqual("At least one search argument is required", exception.Message); throw; } } }
public void GetInvalidFlight() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "GetInvalidFlight") .Options; using (var flightContext = new FlightsContext(options)) { flightContext.Add(new Flight { Number = 1, Capacity = 1 }); flightContext.SaveChanges(); } using (var flightContext = new FlightsContext(options)) { var flightController = new FlightController(flightContext); var result = flightController.Get(2); Assert.IsTrue(result is NotFoundResult); } }
public void AvailableFlightsWithToManyPassengers() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "AvailableFlightsWithToManyPassengers") .Options; using (var flightContext = new FlightsContext(options)) { flightContext.Add(new Flight { Number = 1, Capacity = 1 }); flightContext.SaveChanges(); } using (var flightContext = new FlightsContext(options)) { var search = new Search(flightContext); var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), 2); Assert.AreEqual(0, results.Count); } }
public void GetBookingInvalidId() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "GetBookingInvalidId") .Options; using (var flightContext = new FlightsContext(options)) { flightContext.AddRange( new Booking { Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10) }); flightContext.SaveChanges(); } using (var flightContext = new FlightsContext(options)) { var bookingController = new BookingController(flightContext); var result = bookingController.Get(2); Assert.IsTrue(result is NotFoundResult); } }
public void CreateBooking() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "CreateBooking") .Options; using (var flightContext = new FlightsContext(options)) { var flight = new Flight { Number = 1, Capacity = 1 }; flightContext.Add(flight); flightContext.SaveChanges(); } using (var flightContext = new FlightsContext(options)) { var bookingController = new BookingController(flightContext); var result = bookingController.Create(new Booking { PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10), FlightNumber = 1 }); Assert.IsTrue(result is CreatedAtRouteResult); var objectResult = result as CreatedAtRouteResult; Assert.IsTrue(objectResult.Value is Booking); var bookings = objectResult.Value as Booking; Assert.AreEqual(1, bookings.Id); Assert.AreEqual("Joe Bloggs", bookings.PassengerName); Assert.AreEqual(new DateTime(2018, 5, 10), bookings.Date); Assert.AreEqual(1, flightContext.Bookings.Count()); Assert.AreEqual(1, flightContext.Bookings.First().Id); Assert.AreEqual("Joe Bloggs", flightContext.Bookings.First().PassengerName); Assert.AreEqual(new DateTime(2018, 5, 10), flightContext.Bookings.First().Date); } }
public void CreateBookingNoCapacity() { var options = new DbContextOptionsBuilder <FlightsContext>() .UseInMemoryDatabase(databaseName: "CreateBookingNoCapacity") .Options; using (var flightContext = new FlightsContext(options)) { var flight = new Flight { Number = 1, Capacity = 1 }; flightContext.Add(flight); flightContext.Add( new Booking { Id = 1, FlightNumber = 1, Flight = flight, Date = new DateTime(2018, 5, 10), PassengerName = "Joe Bloggs" }); flightContext.SaveChanges(); } using (var flightContext = new FlightsContext(options)) { var bookingController = new BookingController(flightContext); var result = bookingController.Create(new Booking { PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10), FlightNumber = 1 }); Assert.IsTrue(result is BadRequestResult); } }
public BookingsController(FlightsContext context) { _context = context; }
public RouteRepository(FlightsContext flightsContext) : base(flightsContext) { }
public FlightController(FlightsContext flightsContext) { FlightsContext = flightsContext; }
public PassengerRepository(FlightsContext context) { _context = context; }
public WriteRepository(FlightsContext context) { _context = context; }
public Search(FlightsContext flightsContext) { FlightsContext = flightsContext; }
public ReservationsController(FlightsContext context) { _context = context; }
public FlightRepository() { this.flightsContext = FlightsContext.Instance; }
public PassengersController(FlightsContext context) { _context = context; }
public CountriesController(FlightsContext context) { _context = context; }
public ServersController(FlightsContext context) { serverContext = context; }
public AirportRepository(FlightsContext context) { _context = context; }
public BookingController(FlightsContext flightsContext) { FlightsContext = flightsContext; }
public AirportsController(FlightsContext context) { _context = context; }
public FlightsController(FlightsContext context) { _context = context; }
public FlightsSeeder(FlightsContext flightsContext) : base(flightsContext) { }
public RepositoryWrapper(FlightsContext flightsContext) { _flightsContext = flightsContext; }
public ClientRepository(FlightsContext flightsContext) : base(flightsContext) { }