diff --git a/src/FlightRecorder.BusinessLogic/Logic/AircraftManager.cs b/src/FlightRecorder.BusinessLogic/Logic/AircraftManager.cs
index 6573bc0..191d351 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/AircraftManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/AircraftManager.cs
@@ -15,7 +15,7 @@ internal class AircraftManager : IAircraftManager
{
private const int AllModelsPageSize = 1000000;
- private FlightRecorderFactory _factory;
+ private readonly FlightRecorderFactory _factory;
internal AircraftManager(FlightRecorderFactory factory)
{
diff --git a/src/FlightRecorder.BusinessLogic/Logic/AirlineManager.cs b/src/FlightRecorder.BusinessLogic/Logic/AirlineManager.cs
index 03c7985..3a6c211 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/AirlineManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/AirlineManager.cs
@@ -1,136 +1,136 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Linq.Expressions;
-using System.Threading.Tasks;
-using FlightRecorder.BusinessLogic.Extensions;
-using FlightRecorder.Data;
-using FlightRecorder.Entities.Db;
-using FlightRecorder.Entities.Interfaces;
-using Microsoft.EntityFrameworkCore;
-
-namespace FlightRecorder.BusinessLogic.Logic
-{
- internal class AirlineManager : IAirlineManager
- {
- private FlightRecorderDbContext _context;
-
- internal AirlineManager(FlightRecorderDbContext context)
- {
- _context = context;
- }
-
- ///
- /// Return the first entity matching the specified criteria
- ///
- ///
- ///
- public Airline Get(Expression> predicate)
- => List(predicate, 1, 1).FirstOrDefault();
-
- ///
- /// Get the first airline matching the specified criteria
- ///
- ///
- ///
- public async Task GetAsync(Expression> predicate)
- {
- List airlines = await _context.Airlines
- .Where(predicate)
- .ToListAsync();
- return airlines.FirstOrDefault();
- }
-
- ///
- /// Return all entities matching the specified criteria
- ///
- ///
- ///
- ///
- ///
- public IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
- {
- IEnumerable results;
- if (predicate == null)
- {
- results = _context.Airlines;
- results = results.Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- }
- else
- {
- results = _context.Airlines
- .Where(predicate)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize); ;
- }
-
- return results;
- }
-
- ///
- /// Return all entities matching the specified criteria
- ///
- ///
- ///
- ///
- ///
- public IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
- {
- IAsyncEnumerable results;
- if (predicate == null)
- {
- results = _context.Airlines
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
- else
- {
- results = _context.Airlines.Where(predicate).AsAsyncEnumerable();
- }
-
- return results;
- }
-
- ///
- /// Add a named airline, if it doesn't already exist
- ///
- ///
- ///
- public Airline Add(string name)
- {
- name = name.CleanString();
- Airline airline = Get(a => a.Name == name);
-
- if (airline == null)
- {
- airline = new Airline { Name = name };
- _context.Airlines.Add(airline);
- _context.SaveChanges();
- }
-
- return airline;
- }
-
- ///
- /// Add a named airline, if it doesn't already exist
- ///
- ///
- ///
- public async Task AddAsync(string name)
- {
- name = name.CleanString();
- Airline airline = await GetAsync(a => a.Name == name);
-
- if (airline == null)
- {
- airline = new Airline { Name = name };
- await _context.Airlines.AddAsync(airline);
- await _context.SaveChangesAsync();
- }
-
- return airline;
- }
- }
-}
+using System.Threading.Tasks;
+using FlightRecorder.BusinessLogic.Extensions;
+using FlightRecorder.Data;
+using FlightRecorder.Entities.Db;
+using FlightRecorder.Entities.Interfaces;
+using Microsoft.EntityFrameworkCore;
+
+namespace FlightRecorder.BusinessLogic.Logic
+{
+ internal class AirlineManager : IAirlineManager
+ {
+ private readonly FlightRecorderDbContext _context;
+
+ internal AirlineManager(FlightRecorderDbContext context)
+ {
+ _context = context;
+ }
+
+ ///
+ /// Return the first entity matching the specified criteria
+ ///
+ ///
+ ///
+ public Airline Get(Expression> predicate)
+ => List(predicate, 1, 1).FirstOrDefault();
+
+ ///
+ /// Get the first airline matching the specified criteria
+ ///
+ ///
+ ///
+ public async Task GetAsync(Expression> predicate)
+ {
+ List airlines = await _context.Airlines
+ .Where(predicate)
+ .ToListAsync();
+ return airlines.FirstOrDefault();
+ }
+
+ ///
+ /// Return all entities matching the specified criteria
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IEnumerable results;
+ if (predicate == null)
+ {
+ results = _context.Airlines;
+ results = results.Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+ else
+ {
+ results = _context.Airlines
+ .Where(predicate)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+
+ return results;
+ }
+
+ ///
+ /// Return all entities matching the specified criteria
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IAsyncEnumerable results;
+ if (predicate == null)
+ {
+ results = _context.Airlines
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+ else
+ {
+ results = _context.Airlines.Where(predicate).AsAsyncEnumerable();
+ }
+
+ return results;
+ }
+
+ ///
+ /// Add a named airline, if it doesn't already exist
+ ///
+ ///
+ ///
+ public Airline Add(string name)
+ {
+ name = name.CleanString();
+ Airline airline = Get(a => a.Name == name);
+
+ if (airline == null)
+ {
+ airline = new Airline { Name = name };
+ _context.Airlines.Add(airline);
+ _context.SaveChanges();
+ }
+
+ return airline;
+ }
+
+ ///
+ /// Add a named airline, if it doesn't already exist
+ ///
+ ///
+ ///
+ public async Task AddAsync(string name)
+ {
+ name = name.CleanString();
+ Airline airline = await GetAsync(a => a.Name == name);
+
+ if (airline == null)
+ {
+ airline = new Airline { Name = name };
+ await _context.Airlines.AddAsync(airline);
+ await _context.SaveChangesAsync();
+ }
+
+ return airline;
+ }
+ }
+}
diff --git a/src/FlightRecorder.BusinessLogic/Logic/FlightManager.cs b/src/FlightRecorder.BusinessLogic/Logic/FlightManager.cs
index 501b73e..291aeec 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/FlightManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/FlightManager.cs
@@ -13,7 +13,7 @@ namespace FlightRecorder.BusinessLogic.Logic
{
internal class FlightManager : IFlightManager
{
- private FlightRecorderFactory _factory;
+ private readonly FlightRecorderFactory _factory;
internal FlightManager(FlightRecorderFactory factory)
{
diff --git a/src/FlightRecorder.BusinessLogic/Logic/LocationManager.cs b/src/FlightRecorder.BusinessLogic/Logic/LocationManager.cs
index 126f3e4..a1c09f9 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/LocationManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/LocationManager.cs
@@ -1,140 +1,140 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Linq.Expressions;
-using System.Threading.Tasks;
-using FlightRecorder.BusinessLogic.Extensions;
-using FlightRecorder.Data;
-using FlightRecorder.Entities.Db;
-using FlightRecorder.Entities.Interfaces;
-using Microsoft.EntityFrameworkCore;
-
-namespace FlightRecorder.BusinessLogic.Logic
-{
- internal class LocationManager : ILocationManager
- {
- private FlightRecorderDbContext _context;
-
- internal LocationManager(FlightRecorderDbContext context)
- {
- _context = context;
- }
-
- ///
- /// Return the first entity matching the specified criteria
- ///
- ///
- ///
- public Location Get(Expression> predicate)
- => List(predicate, 1, 1).FirstOrDefault();
-
- ///
- /// Return the first entity matching the specified criteria
- ///
- ///
- ///
- public async Task GetAsync(Expression> predicate)
- {
- List locations = await _context.Locations
- .Where(predicate)
- .ToListAsync();
- return locations.FirstOrDefault();
- }
-
- ///
- /// Return all entities matching the specified criteria
- ///
- ///
- ///
- ///
- ///
- public virtual IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
- {
- IEnumerable results;
- if (predicate == null)
- {
- results = _context.Locations;
- results = results.Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- }
- else
- {
- results = _context.Locations
- .Where(predicate)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- }
-
- return results;
- }
-
- ///
- /// Return all entities matching the specified criteria
- ///
- ///
- ///
- ///
- ///
- public virtual IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
- {
- IAsyncEnumerable results;
- if (predicate == null)
- {
- results = _context.Locations
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
- else
- {
- results = _context.Locations
- .Where(predicate)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
-
- return results;
- }
-
- ///
- /// Add a named location, if it doesn't already exist
- ///
- ///
- ///
- public Location Add(string name)
- {
- name = name.CleanString();
- Location location = Get(a => a.Name == name);
-
- if (location == null)
- {
- location = new Location { Name = name };
- _context.Locations.Add(location);
- _context.SaveChanges();
- }
-
- return location;
- }
-
- ///
- /// Add a named location, if it doesn't already exist
- ///
- ///
- ///
- public async Task AddAsync(string name)
- {
- name = name.CleanString();
- Location location = await GetAsync(a => a.Name == name);
-
- if (location == null)
- {
- location = new Location { Name = name };
- await _context.Locations.AddAsync(location);
- await _context.SaveChangesAsync();
- }
-
- return location;
- }
- }
-}
+using System.Threading.Tasks;
+using FlightRecorder.BusinessLogic.Extensions;
+using FlightRecorder.Data;
+using FlightRecorder.Entities.Db;
+using FlightRecorder.Entities.Interfaces;
+using Microsoft.EntityFrameworkCore;
+
+namespace FlightRecorder.BusinessLogic.Logic
+{
+ internal class LocationManager : ILocationManager
+ {
+ private readonly FlightRecorderDbContext _context;
+
+ internal LocationManager(FlightRecorderDbContext context)
+ {
+ _context = context;
+ }
+
+ ///
+ /// Return the first entity matching the specified criteria
+ ///
+ ///
+ ///
+ public Location Get(Expression> predicate)
+ => List(predicate, 1, 1).FirstOrDefault();
+
+ ///
+ /// Return the first entity matching the specified criteria
+ ///
+ ///
+ ///
+ public async Task GetAsync(Expression> predicate)
+ {
+ List locations = await _context.Locations
+ .Where(predicate)
+ .ToListAsync();
+ return locations.FirstOrDefault();
+ }
+
+ ///
+ /// Return all entities matching the specified criteria
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IEnumerable results;
+ if (predicate == null)
+ {
+ results = _context.Locations;
+ results = results.Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+ else
+ {
+ results = _context.Locations
+ .Where(predicate)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+
+ return results;
+ }
+
+ ///
+ /// Return all entities matching the specified criteria
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IAsyncEnumerable results;
+ if (predicate == null)
+ {
+ results = _context.Locations
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+ else
+ {
+ results = _context.Locations
+ .Where(predicate)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+
+ return results;
+ }
+
+ ///
+ /// Add a named location, if it doesn't already exist
+ ///
+ ///
+ ///
+ public Location Add(string name)
+ {
+ name = name.CleanString();
+ Location location = Get(a => a.Name == name);
+
+ if (location == null)
+ {
+ location = new Location { Name = name };
+ _context.Locations.Add(location);
+ _context.SaveChanges();
+ }
+
+ return location;
+ }
+
+ ///
+ /// Add a named location, if it doesn't already exist
+ ///
+ ///
+ ///
+ public async Task AddAsync(string name)
+ {
+ name = name.CleanString();
+ Location location = await GetAsync(a => a.Name == name);
+
+ if (location == null)
+ {
+ location = new Location { Name = name };
+ await _context.Locations.AddAsync(location);
+ await _context.SaveChangesAsync();
+ }
+
+ return location;
+ }
+ }
+}
diff --git a/src/FlightRecorder.BusinessLogic/Logic/ManufacturerManager.cs b/src/FlightRecorder.BusinessLogic/Logic/ManufacturerManager.cs
index 131b026..e5e64a4 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/ManufacturerManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/ManufacturerManager.cs
@@ -1,140 +1,140 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Linq.Expressions;
-using System.Threading.Tasks;
-using FlightRecorder.BusinessLogic.Extensions;
-using FlightRecorder.Data;
-using FlightRecorder.Entities.Db;
-using FlightRecorder.Entities.Interfaces;
-using Microsoft.EntityFrameworkCore;
-
-namespace FlightRecorder.BusinessLogic.Logic
-{
- internal class ManufacturerManager : IManufacturerManager
- {
- private FlightRecorderDbContext _context;
-
- internal ManufacturerManager(FlightRecorderDbContext context)
- {
- _context = context;
- }
-
- ///
- /// Return the first entity matching the specified criteria
- ///
- ///
- ///
- public Manufacturer Get(Expression> predicate) =>
- _context.Manufacturers.FirstOrDefault(predicate);
-
- ///
- /// Return the first entity matching the specified criteria
- ///
- ///
- ///
- public async Task GetAsync(Expression> predicate)
- {
- List manufacturers = await _context.Manufacturers
- .Where(predicate)
- .ToListAsync();
- return manufacturers.FirstOrDefault();
- }
-
- ///
- /// Return all entities matching the specified criteria
- ///
- ///
- ///
- ///
- ///
- public IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
- {
- IEnumerable results;
- if (predicate == null)
- {
- results = _context.Manufacturers;
- results = results.Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- }
- else
- {
- results = _context.Manufacturers
- .Where(predicate)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- }
-
- return results;
- }
-
- ///
- /// Return all entities matching the specified criteria
- ///
- ///
- ///
- ///
- ///
- public IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
- {
- IAsyncEnumerable results;
- if (predicate == null)
- {
- results = _context.Manufacturers
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
- else
- {
- results = _context.Manufacturers
- .Where(predicate)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
-
- return results;
- }
-
- ///
- /// Add a named manufacturer, if it doesn't already exist
- ///
- ///
- ///
- public Manufacturer Add(string name)
- {
- name = name.CleanString();
- Manufacturer manufacturer = Get(a => a.Name == name);
-
- if (manufacturer == null)
- {
- manufacturer = new Manufacturer { Name = name };
- _context.Manufacturers.Add(manufacturer);
- _context.SaveChanges();
- }
-
- return manufacturer;
- }
-
- ///
- /// Add a named manufacturer, if it doesn't already exist
- ///
- ///
- ///
- public async Task AddAsync(string name)
- {
- name = name.CleanString();
- Manufacturer manufacturer = await GetAsync(a => a.Name == name);
-
- if (manufacturer == null)
- {
- manufacturer = new Manufacturer { Name = name };
- await _context.Manufacturers.AddAsync(manufacturer);
- await _context.SaveChangesAsync();
- }
-
- return manufacturer;
- }
- }
-}
+using System.Threading.Tasks;
+using FlightRecorder.BusinessLogic.Extensions;
+using FlightRecorder.Data;
+using FlightRecorder.Entities.Db;
+using FlightRecorder.Entities.Interfaces;
+using Microsoft.EntityFrameworkCore;
+
+namespace FlightRecorder.BusinessLogic.Logic
+{
+ internal class ManufacturerManager : IManufacturerManager
+ {
+ private readonly FlightRecorderDbContext _context;
+
+ internal ManufacturerManager(FlightRecorderDbContext context)
+ {
+ _context = context;
+ }
+
+ ///
+ /// Return the first entity matching the specified criteria
+ ///
+ ///
+ ///
+ public Manufacturer Get(Expression> predicate) =>
+ _context.Manufacturers.FirstOrDefault(predicate);
+
+ ///
+ /// Return the first entity matching the specified criteria
+ ///
+ ///
+ ///
+ public async Task GetAsync(Expression> predicate)
+ {
+ List manufacturers = await _context.Manufacturers
+ .Where(predicate)
+ .ToListAsync();
+ return manufacturers.FirstOrDefault();
+ }
+
+ ///
+ /// Return all entities matching the specified criteria
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IEnumerable results;
+ if (predicate == null)
+ {
+ results = _context.Manufacturers;
+ results = results.Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+ else
+ {
+ results = _context.Manufacturers
+ .Where(predicate)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+
+ return results;
+ }
+
+ ///
+ /// Return all entities matching the specified criteria
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IAsyncEnumerable results;
+ if (predicate == null)
+ {
+ results = _context.Manufacturers
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+ else
+ {
+ results = _context.Manufacturers
+ .Where(predicate)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+
+ return results;
+ }
+
+ ///
+ /// Add a named manufacturer, if it doesn't already exist
+ ///
+ ///
+ ///
+ public Manufacturer Add(string name)
+ {
+ name = name.CleanString();
+ Manufacturer manufacturer = Get(a => a.Name == name);
+
+ if (manufacturer == null)
+ {
+ manufacturer = new Manufacturer { Name = name };
+ _context.Manufacturers.Add(manufacturer);
+ _context.SaveChanges();
+ }
+
+ return manufacturer;
+ }
+
+ ///
+ /// Add a named manufacturer, if it doesn't already exist
+ ///
+ ///
+ ///
+ public async Task AddAsync(string name)
+ {
+ name = name.CleanString();
+ Manufacturer manufacturer = await GetAsync(a => a.Name == name);
+
+ if (manufacturer == null)
+ {
+ manufacturer = new Manufacturer { Name = name };
+ await _context.Manufacturers.AddAsync(manufacturer);
+ await _context.SaveChangesAsync();
+ }
+
+ return manufacturer;
+ }
+ }
+}
diff --git a/src/FlightRecorder.BusinessLogic/Logic/ModelManager.cs b/src/FlightRecorder.BusinessLogic/Logic/ModelManager.cs
index c18ced6..94f0979 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/ModelManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/ModelManager.cs
@@ -1,189 +1,189 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Linq.Expressions;
-using System.Threading.Tasks;
-using FlightRecorder.BusinessLogic.Extensions;
-using FlightRecorder.BusinessLogic.Factory;
-using FlightRecorder.Entities.Db;
-using FlightRecorder.Entities.Interfaces;
-using Microsoft.EntityFrameworkCore;
-
-namespace FlightRecorder.BusinessLogic.Logic
-{
- internal class ModelManager : IModelManager
- {
- private FlightRecorderFactory _factory;
-
- internal ModelManager(FlightRecorderFactory factory)
- {
- _factory = factory;
- }
-
- ///
- /// Get the first model matching the specified criteria along with the associated manufacturer
- ///
- ///
- ///
- public Model Get(Expression> predicate)
- => List(predicate, 1, 1).FirstOrDefault();
-
- ///
- /// Get the first model matching the specified criteria along with the associated manufacturer
- ///
- ///
- ///
- public async Task GetAsync(Expression> predicate)
- {
- List models = await _factory.Context.Models
- .Where(predicate)
- .ToListAsync();
- return models.FirstOrDefault();
- }
-
- ///
- /// Get the models matching the specified criteria along with the associated manufacturers
- ///
- ///
- ///
- ///
- ///
- public IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
- {
- IEnumerable models;
-
- if (predicate == null)
- {
- models = _factory.Context.Models
- .Include(m => m.Manufacturer)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- }
- else
- {
- models = _factory.Context.Models
- .Include(m => m.Manufacturer)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .Where(predicate);
- }
-
- return models;
- }
-
- ///
- /// Get the models matching the specified criteria along with the associated manufacturers
- ///
- ///
- ///
- ///
- ///
- public IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
- {
- IAsyncEnumerable models;
-
- if (predicate == null)
- {
- models = _factory.Context.Models
- .Include(m => m.Manufacturer)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
- else
- {
- models = _factory.Context.Models
- .Include(m => m.Manufacturer)
- .Where(predicate)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- }
-
- return models;
- }
-
- ///
- /// Get the models for a named manufacturer
- ///
- ///
- ///
- ///
- ///
- public IEnumerable ListByManufacturer(string manufacturerName, int pageNumber, int pageSize)
- {
- manufacturerName = manufacturerName.CleanString();
- IEnumerable models = _factory.Context.Models
- .Include(m => m.Manufacturer)
- .Where(m => m.Manufacturer.Name == manufacturerName)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize);
- return models;
- }
-
- ///
- /// Get the models for a named manufacturer
- ///
- ///
- ///
- ///
- ///
- public IAsyncEnumerable ListByManufacturerAsync(string manufacturerName, int pageNumber, int pageSize)
- {
- manufacturerName = manufacturerName.CleanString();
- IAsyncEnumerable models = _factory.Context.Models
- .Include(m => m.Manufacturer)
- .Where(m => m.Manufacturer.Name == manufacturerName)
- .Skip((pageNumber - 1) * pageSize)
- .Take(pageSize)
- .AsAsyncEnumerable();
- return models;
- }
-
- ///
- /// Add a named model associated with the specified manufacturer, if it doesn't already exist
- ///
- ///
- ///
- ///
- public Model Add(string name, string manufacturerName)
- {
- name = name.CleanString();
- Model model = Get(a => a.Name == name);
-
- if (model == null)
- {
- Manufacturer manufacturer = _factory.Manufacturers.Add(manufacturerName);
- model = new Model { Name = name, ManufacturerId = manufacturer.Id };
- _factory.Context.Models.Add(model);
- _factory.Context.SaveChanges();
- _factory.Context.Entry(model).Reference(m => m.Manufacturer).Load();
- }
-
- return model;
- }
-
- ///
- /// Add a named model associated with the specified manufacturer, if it doesn't already exist
- ///
- ///
- ///
- ///
- public async Task AddAsync(string name, string manufacturerName)
- {
- name = name.CleanString();
- Model model = await GetAsync(a => a.Name == name);
-
- if (model == null)
- {
- Manufacturer manufacturer = await _factory.Manufacturers.AddAsync(manufacturerName);
- model = new Model { Name = name, ManufacturerId = manufacturer.Id };
- await _factory.Context.Models.AddAsync(model);
- await _factory.Context.SaveChangesAsync();
- await _factory.Context.Entry(model).Reference(m => m.Manufacturer).LoadAsync();
- }
-
- return model;
- }
- }
-}
+using System.Threading.Tasks;
+using FlightRecorder.BusinessLogic.Extensions;
+using FlightRecorder.BusinessLogic.Factory;
+using FlightRecorder.Entities.Db;
+using FlightRecorder.Entities.Interfaces;
+using Microsoft.EntityFrameworkCore;
+
+namespace FlightRecorder.BusinessLogic.Logic
+{
+ internal class ModelManager : IModelManager
+ {
+ private readonly FlightRecorderFactory _factory;
+
+ internal ModelManager(FlightRecorderFactory factory)
+ {
+ _factory = factory;
+ }
+
+ ///
+ /// Get the first model matching the specified criteria along with the associated manufacturer
+ ///
+ ///
+ ///
+ public Model Get(Expression> predicate)
+ => List(predicate, 1, 1).FirstOrDefault();
+
+ ///
+ /// Get the first model matching the specified criteria along with the associated manufacturer
+ ///
+ ///
+ ///
+ public async Task GetAsync(Expression> predicate)
+ {
+ List models = await _factory.Context.Models
+ .Where(predicate)
+ .ToListAsync();
+ return models.FirstOrDefault();
+ }
+
+ ///
+ /// Get the models matching the specified criteria along with the associated manufacturers
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IEnumerable List(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IEnumerable models;
+
+ if (predicate == null)
+ {
+ models = _factory.Context.Models
+ .Include(m => m.Manufacturer)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ }
+ else
+ {
+ models = _factory.Context.Models
+ .Include(m => m.Manufacturer)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .Where(predicate);
+ }
+
+ return models;
+ }
+
+ ///
+ /// Get the models matching the specified criteria along with the associated manufacturers
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IAsyncEnumerable ListAsync(Expression> predicate, int pageNumber, int pageSize)
+ {
+ IAsyncEnumerable models;
+
+ if (predicate == null)
+ {
+ models = _factory.Context.Models
+ .Include(m => m.Manufacturer)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+ else
+ {
+ models = _factory.Context.Models
+ .Include(m => m.Manufacturer)
+ .Where(predicate)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ }
+
+ return models;
+ }
+
+ ///
+ /// Get the models for a named manufacturer
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IEnumerable ListByManufacturer(string manufacturerName, int pageNumber, int pageSize)
+ {
+ manufacturerName = manufacturerName.CleanString();
+ IEnumerable models = _factory.Context.Models
+ .Include(m => m.Manufacturer)
+ .Where(m => m.Manufacturer.Name == manufacturerName)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize);
+ return models;
+ }
+
+ ///
+ /// Get the models for a named manufacturer
+ ///
+ ///
+ ///
+ ///
+ ///
+ public IAsyncEnumerable ListByManufacturerAsync(string manufacturerName, int pageNumber, int pageSize)
+ {
+ manufacturerName = manufacturerName.CleanString();
+ IAsyncEnumerable models = _factory.Context.Models
+ .Include(m => m.Manufacturer)
+ .Where(m => m.Manufacturer.Name == manufacturerName)
+ .Skip((pageNumber - 1) * pageSize)
+ .Take(pageSize)
+ .AsAsyncEnumerable();
+ return models;
+ }
+
+ ///
+ /// Add a named model associated with the specified manufacturer, if it doesn't already exist
+ ///
+ ///
+ ///
+ ///
+ public Model Add(string name, string manufacturerName)
+ {
+ name = name.CleanString();
+ Model model = Get(a => a.Name == name);
+
+ if (model == null)
+ {
+ Manufacturer manufacturer = _factory.Manufacturers.Add(manufacturerName);
+ model = new Model { Name = name, ManufacturerId = manufacturer.Id };
+ _factory.Context.Models.Add(model);
+ _factory.Context.SaveChanges();
+ _factory.Context.Entry(model).Reference(m => m.Manufacturer).Load();
+ }
+
+ return model;
+ }
+
+ ///
+ /// Add a named model associated with the specified manufacturer, if it doesn't already exist
+ ///
+ ///
+ ///
+ ///
+ public async Task AddAsync(string name, string manufacturerName)
+ {
+ name = name.CleanString();
+ Model model = await GetAsync(a => a.Name == name);
+
+ if (model == null)
+ {
+ Manufacturer manufacturer = await _factory.Manufacturers.AddAsync(manufacturerName);
+ model = new Model { Name = name, ManufacturerId = manufacturer.Id };
+ await _factory.Context.Models.AddAsync(model);
+ await _factory.Context.SaveChangesAsync();
+ await _factory.Context.Entry(model).Reference(m => m.Manufacturer).LoadAsync();
+ }
+
+ return model;
+ }
+ }
+}
diff --git a/src/FlightRecorder.BusinessLogic/Logic/SightingManager.cs b/src/FlightRecorder.BusinessLogic/Logic/SightingManager.cs
index 504ee2d..f9257f5 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/SightingManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/SightingManager.cs
@@ -16,7 +16,7 @@ internal class SightingManager : ISightingManager
{
private const int AllFlightsPageSize = 1000000;
- private FlightRecorderFactory _factory;
+ private readonly FlightRecorderFactory _factory;
internal SightingManager(FlightRecorderFactory factory)
{
diff --git a/src/FlightRecorder.BusinessLogic/Logic/UserManager.cs b/src/FlightRecorder.BusinessLogic/Logic/UserManager.cs
index 7cb4410..8e5a756 100644
--- a/src/FlightRecorder.BusinessLogic/Logic/UserManager.cs
+++ b/src/FlightRecorder.BusinessLogic/Logic/UserManager.cs
@@ -14,7 +14,7 @@ namespace FlightRecorder.BusinessLogic.Logic
{
public class UserManager : IUserManager
{
- private Lazy> _hasher;
+ private readonly Lazy> _hasher;
private readonly FlightRecorderDbContext _context;
public UserManager(FlightRecorderDbContext context)
@@ -215,7 +215,7 @@ public async Task DeleteUserAsync(string userName)
///
///
[ExcludeFromCodeCoverage]
- private void ThrowIfUserNotFound(User user, object userId)
+ private static void ThrowIfUserNotFound(User user, object userId)
{
if (user == null)
{
@@ -230,7 +230,7 @@ private void ThrowIfUserNotFound(User user, object userId)
///
///
[ExcludeFromCodeCoverage]
- private void ThrowIfUserFound(User user, object userId)
+ private static void ThrowIfUserFound(User user, object userId)
{
if (user != null)
{
diff --git a/src/FlightRecorder.Data/FlightRecorderDbContextFactory.cs b/src/FlightRecorder.Data/FlightRecorderDbContextFactory.cs
index 5a9d2a2..98cdf8f 100644
--- a/src/FlightRecorder.Data/FlightRecorderDbContextFactory.cs
+++ b/src/FlightRecorder.Data/FlightRecorderDbContextFactory.cs
@@ -35,7 +35,7 @@ public FlightRecorderDbContext CreateDbContext(string[] args)
/// Create an in-memory context for unit testing
///
///
- public FlightRecorderDbContext CreateInMemoryDbContext()
+ public static FlightRecorderDbContext CreateInMemoryDbContext()
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
diff --git a/src/FlightRecorder.Entities/Exceptions/InvalidRecordFormatException.cs b/src/FlightRecorder.Entities/Exceptions/InvalidRecordFormatException.cs
index ca2e330..5d2b016 100644
--- a/src/FlightRecorder.Entities/Exceptions/InvalidRecordFormatException.cs
+++ b/src/FlightRecorder.Entities/Exceptions/InvalidRecordFormatException.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.Serialization;
namespace FlightRecorder.Entities.Exceptions
{
@@ -18,6 +19,15 @@ public InvalidRecordFormatException(string message) : base(message)
public InvalidRecordFormatException(string message, Exception inner) : base(message, inner)
{
}
+
+ protected InvalidRecordFormatException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
+ {
+ }
+
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ }
}
}
diff --git a/src/FlightRecorder.Entities/Exceptions/UserExistsException.cs b/src/FlightRecorder.Entities/Exceptions/UserExistsException.cs
index b1c540d..c459ce9 100644
--- a/src/FlightRecorder.Entities/Exceptions/UserExistsException.cs
+++ b/src/FlightRecorder.Entities/Exceptions/UserExistsException.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.Serialization;
namespace FlightRecorder.Entities.Exceptions
{
@@ -18,5 +19,14 @@ public UserExistsException(string message) : base(message)
public UserExistsException(string message, Exception inner) : base(message, inner)
{
}
+
+ protected UserExistsException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
+ {
+ }
+
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ }
}
}
diff --git a/src/FlightRecorder.Entities/Exceptions/UserNotFoundException.cs b/src/FlightRecorder.Entities/Exceptions/UserNotFoundException.cs
index 1f1a245..6fe1098 100644
--- a/src/FlightRecorder.Entities/Exceptions/UserNotFoundException.cs
+++ b/src/FlightRecorder.Entities/Exceptions/UserNotFoundException.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.Serialization;
namespace FlightRecorder.Entities.Exceptions
{
@@ -18,6 +19,15 @@ public UserNotFoundException(string message) : base(message)
public UserNotFoundException(string message, Exception inner) : base(message, inner)
{
}
+
+ protected UserNotFoundException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
+ {
+ }
+
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ }
}
}
diff --git a/src/FlightRecorder.Manager/FlightRecorder.Manager.csproj b/src/FlightRecorder.Manager/FlightRecorder.Manager.csproj
index 62b4d05..e7badca 100644
--- a/src/FlightRecorder.Manager/FlightRecorder.Manager.csproj
+++ b/src/FlightRecorder.Manager/FlightRecorder.Manager.csproj
@@ -4,6 +4,7 @@
Exe
net6.0
1.0.1.0
+ Release;Debug
diff --git a/src/FlightRecorder.Manager/Logic/CommandParser.cs b/src/FlightRecorder.Manager/Logic/CommandParser.cs
index 775983c..363204c 100644
--- a/src/FlightRecorder.Manager/Logic/CommandParser.cs
+++ b/src/FlightRecorder.Manager/Logic/CommandParser.cs
@@ -19,22 +19,19 @@ public Operation ParseCommandLine(string[] args)
{
Operation op = new Operation();
- if (args.Length > 0)
+ // Attempt to parse out the operation type from the first argument
+ if ((args.Length > 0) && (Enum.TryParse(args[0], out OperationType type)))
{
- // Attempt to parse out the operation type from the first argument
- if (Enum.TryParse(args[0], out OperationType type))
- {
- // Check there are sufficient arguments for this operation
- op.Type = type;
- int requiredArgumentCount = _requiredArgumentCount[(int)type];
+ // Check there are sufficient arguments for this operation
+ op.Type = type;
+ int requiredArgumentCount = _requiredArgumentCount[(int)type];
- // All is OK at this point if the argument count is correct
- op.Valid = (args.Length == requiredArgumentCount);
- if (op.Valid)
- {
- // Extract the arguments
- AssignOperationParameters(op, args);
- }
+ // All is OK at this point if the argument count is correct
+ op.Valid = (args.Length == requiredArgumentCount);
+ if (op.Valid)
+ {
+ // Extract the arguments
+ AssignOperationParameters(op, args);
}
}
@@ -47,10 +44,11 @@ public Operation ParseCommandLine(string[] args)
///
///
///
- private void AssignOperationParameters(Operation op, string[] args)
+ private static void AssignOperationParameters(Operation op, string[] args)
{
switch (op.Type)
{
+ case OperationType.setpassword:
case OperationType.add:
op.UserName = args[1];
op.Password = args[2];
@@ -58,10 +56,6 @@ private void AssignOperationParameters(Operation op, string[] args)
case OperationType.delete:
op.UserName = args[1];
break;
- case OperationType.setpassword:
- op.UserName = args[1];
- op.Password = args[2];
- break;
case OperationType.import:
op.FileName = args[1];
break;
diff --git a/src/FlightRecorder.Manager/Program.cs b/src/FlightRecorder.Manager/Program.cs
index 9e48974..63b9747 100644
--- a/src/FlightRecorder.Manager/Program.cs
+++ b/src/FlightRecorder.Manager/Program.cs
@@ -1,81 +1,81 @@
-using System;
-using System.Collections.Generic;
-using Microsoft.EntityFrameworkCore;
-using FlightRecorder.BusinessLogic.Factory;
-using FlightRecorder.Data;
-using FlightRecorder.Entities.Db;
+using System;
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore;
+using FlightRecorder.BusinessLogic.Factory;
+using FlightRecorder.Data;
+using FlightRecorder.Entities.Db;
using FlightRecorder.Manager.Entities;
-using FlightRecorder.Manager.Logic;
-using FlightRecorder.DataExchange;
-
+using FlightRecorder.Manager.Logic;
+using FlightRecorder.DataExchange;
+
namespace FlightRecorder.Manager
-{
- class Program
- {
- static void Main(string[] args)
- {
- string version = typeof(Program).Assembly.GetName().Version.ToString();
- Console.WriteLine($"Flight Recorder Database Management {version}");
-
- Operation op = new CommandParser().ParseCommandLine(args);
- if (op.Valid)
- {
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateDbContext(null);
- FlightRecorderFactory factory = new FlightRecorderFactory(context);
-
- try
- {
- switch (op.Type)
- {
- case OperationType.add:
- factory.Users.AddUser(op.UserName, op.Password);
- Console.WriteLine($"Added user {op.UserName}");
- break;
- case OperationType.setpassword:
- factory.Users.SetPassword(op.UserName, op.Password);
- Console.WriteLine($"Set password for user {op.UserName}");
- break;
- case OperationType.delete:
- factory.Users.DeleteUser(op.UserName);
- Console.WriteLine($"Deleted user {op.UserName}");
- break;
- case OperationType.import:
- CsvImporter importer = new CsvImporter();
- importer.Import(op.FileName, factory);
- Console.WriteLine($"Imported data from {op.FileName}");
- break;
- case OperationType.export:
- // The third parameter is an arbitrary large number intended to capture all
- // sightings
- IEnumerable sightings = factory.Sightings.List(null, 1, 99999999);
- CsvExporter exporter = new CsvExporter();
- exporter.Export(sightings, op.FileName);
- Console.WriteLine($"Exported the database to {op.FileName}");
- break;
- case OperationType.update:
- context.Database.Migrate();
- Console.WriteLine($"Applied the latest database migrations");
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Error : {ex.Message}");
- }
- }
- else
- {
- string executable = AppDomain.CurrentDomain.FriendlyName;
- Console.WriteLine("Usage:");
- Console.WriteLine($"[1] {executable} add username password");
- Console.WriteLine($"[2] {executable} setpassword username password");
- Console.WriteLine($"[3] {executable} delete username");
- Console.WriteLine($"[4] {executable} import csv_file_path");
- Console.WriteLine($"[5] {executable} export csv_file_path");
- Console.WriteLine($"[6] {executable} update");
- }
- }
- }
-}
+{
+ static class Program
+ {
+ static void Main(string[] args)
+ {
+ string version = typeof(Program).Assembly.GetName().Version.ToString();
+ Console.WriteLine($"Flight Recorder Database Management {version}");
+
+ Operation op = new CommandParser().ParseCommandLine(args);
+ if (op.Valid)
+ {
+ FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateDbContext(null);
+ FlightRecorderFactory factory = new FlightRecorderFactory(context);
+
+ try
+ {
+ switch (op.Type)
+ {
+ case OperationType.add:
+ factory.Users.AddUser(op.UserName, op.Password);
+ Console.WriteLine($"Added user {op.UserName}");
+ break;
+ case OperationType.setpassword:
+ factory.Users.SetPassword(op.UserName, op.Password);
+ Console.WriteLine($"Set password for user {op.UserName}");
+ break;
+ case OperationType.delete:
+ factory.Users.DeleteUser(op.UserName);
+ Console.WriteLine($"Deleted user {op.UserName}");
+ break;
+ case OperationType.import:
+ CsvImporter importer = new CsvImporter();
+ importer.Import(op.FileName, factory);
+ Console.WriteLine($"Imported data from {op.FileName}");
+ break;
+ case OperationType.export:
+ // The third parameter is an arbitrary large number intended to capture all
+ // sightings
+ IEnumerable sightings = factory.Sightings.List(null, 1, 99999999);
+ CsvExporter exporter = new CsvExporter();
+ exporter.Export(sightings, op.FileName);
+ Console.WriteLine($"Exported the database to {op.FileName}");
+ break;
+ case OperationType.update:
+ context.Database.Migrate();
+ Console.WriteLine($"Applied the latest database migrations");
+ break;
+ default:
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error : {ex.Message}");
+ }
+ }
+ else
+ {
+ string executable = AppDomain.CurrentDomain.FriendlyName;
+ Console.WriteLine("Usage:");
+ Console.WriteLine($"[1] {executable} add username password");
+ Console.WriteLine($"[2] {executable} setpassword username password");
+ Console.WriteLine($"[3] {executable} delete username");
+ Console.WriteLine($"[4] {executable} import csv_file_path");
+ Console.WriteLine($"[5] {executable} export csv_file_path");
+ Console.WriteLine($"[6] {executable} update");
+ }
+ }
+ }
+}
diff --git a/src/FlightRecorder.Manager/appsettings.json b/src/FlightRecorder.Manager/appsettings.json
index e0888ba..8ce7697 100644
--- a/src/FlightRecorder.Manager/appsettings.json
+++ b/src/FlightRecorder.Manager/appsettings.json
@@ -1,5 +1,5 @@
{
- "ConnectionStrings": {
- "FlightRecorderDB": "Data Source=flightrecorder.db"
- }
+ "ConnectionStrings": {
+ "FlightRecorderDB": "Data Source=/Users/dave/Dropbox/Documents/Aviation/FlightRecorder/Data/flightrecorder_dev.db"
+ }
}
diff --git a/src/FlightRecorder.Tests/AircraftManagerTest.cs b/src/FlightRecorder.Tests/AircraftManagerTest.cs
index 46fa4a8..77b6374 100644
--- a/src/FlightRecorder.Tests/AircraftManagerTest.cs
+++ b/src/FlightRecorder.Tests/AircraftManagerTest.cs
@@ -25,7 +25,7 @@ public class AircraftManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_factory.Aircraft.Add(Registration, SerialNumber, YearOfManufacture, ModelName, ManufacturerName);
}
@@ -94,7 +94,7 @@ public async Task ListAllAsyncTest()
List aircraft = await _factory.Aircraft
.ListAsync(null, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, aircraft.Count());
+ Assert.AreEqual(1, aircraft.Count);
Assert.AreEqual(Registration, aircraft.First().Registration);
Assert.AreEqual(ModelName, aircraft.First().Model.Name);
Assert.AreEqual(ManufacturerName, aircraft.First().Model.Manufacturer.Name);
@@ -116,7 +116,7 @@ public async Task FilteredListAsyncTest()
List aircraft = await _factory.Aircraft
.ListAsync(e => e.Registration == Registration, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, aircraft.Count());
+ Assert.AreEqual(1, aircraft.Count);
Assert.AreEqual(Registration, aircraft.First().Registration);
Assert.AreEqual(ModelName, aircraft.First().Model.Name);
Assert.AreEqual(ManufacturerName, aircraft.First().Model.Manufacturer.Name);
@@ -138,7 +138,7 @@ public async Task FilterByModelAsyncTest()
IAsyncEnumerable matches = await _factory.Aircraft
.ListByModelAsync(ModelName, 1, 100);
List aircraft = await matches.ToListAsync();
- Assert.AreEqual(1, aircraft.Count());
+ Assert.AreEqual(1, aircraft.Count);
Assert.AreEqual(Registration, aircraft.First().Registration);
Assert.AreEqual(ModelName, aircraft.First().Model.Name);
Assert.AreEqual(ManufacturerName, aircraft.First().Model.Manufacturer.Name);
@@ -160,7 +160,7 @@ public async Task FilterByManufacturerAsyncTest()
IAsyncEnumerable matches = await _factory.Aircraft
.ListByManufacturerAsync(ManufacturerName, 1, 100);
List aircraft = await matches.ToListAsync();
- Assert.AreEqual(1, aircraft.Count());
+ Assert.AreEqual(1, aircraft.Count);
Assert.AreEqual(Registration, aircraft.First().Registration);
Assert.AreEqual(ModelName, aircraft.First().Model.Name);
Assert.AreEqual(ManufacturerName, aircraft.First().Model.Manufacturer.Name);
diff --git a/src/FlightRecorder.Tests/AirlineManagerTest.cs b/src/FlightRecorder.Tests/AirlineManagerTest.cs
index cc95840..6894726 100644
--- a/src/FlightRecorder.Tests/AirlineManagerTest.cs
+++ b/src/FlightRecorder.Tests/AirlineManagerTest.cs
@@ -19,7 +19,7 @@ public class AirlineManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_factory.Airlines.Add(EntityName);
}
@@ -72,7 +72,7 @@ public async Task ListAllAsyncTest()
List entities = await _factory.Airlines
.ListAsync(null, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, entities.Count());
+ Assert.AreEqual(1, entities.Count);
Assert.AreEqual(EntityName, entities.First().Name);
}
@@ -90,7 +90,7 @@ public async Task FilteredListAsyncTest()
List entities = await _factory.Airlines
.ListAsync(e => e.Name == EntityName, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, entities.Count());
+ Assert.AreEqual(1, entities.Count);
Assert.AreEqual(EntityName, entities.First().Name);
}
diff --git a/src/FlightRecorder.Tests/DataExchangeTests.cs b/src/FlightRecorder.Tests/DataExchangeTests.cs
index 5ec7f98..b84f7ef 100644
--- a/src/FlightRecorder.Tests/DataExchangeTests.cs
+++ b/src/FlightRecorder.Tests/DataExchangeTests.cs
@@ -35,7 +35,7 @@ public class DataExchangeTests
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_sightingId = _factory.Sightings.Add(new FlattenedSighting
{
diff --git a/src/FlightRecorder.Tests/FlightManagerTest.cs b/src/FlightRecorder.Tests/FlightManagerTest.cs
index 1f504f5..84ee04d 100644
--- a/src/FlightRecorder.Tests/FlightManagerTest.cs
+++ b/src/FlightRecorder.Tests/FlightManagerTest.cs
@@ -24,7 +24,7 @@ public class FlightManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_factory.Flights.Add(FlightNumber, Embarkation, Destination, AirlineName);
}
@@ -92,7 +92,7 @@ public async Task ListAllAsyncTest()
List flights = await _factory.Flights
.ListAsync(null, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, flights.Count());
+ Assert.AreEqual(1, flights.Count);
Assert.AreEqual(FlightNumber, flights.First().Number);
Assert.AreEqual(AirlineName, flights.First().Airline.Name);
}
@@ -112,7 +112,7 @@ public async Task FilteredListAsyncTest()
List flights = await _factory.Flights
.ListAsync(e => e.Number == FlightNumber, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, flights.Count());
+ Assert.AreEqual(1, flights.Count);
Assert.AreEqual(FlightNumber, flights.First().Number);
Assert.AreEqual(AirlineName, flights.First().Airline.Name);
}
@@ -139,7 +139,7 @@ public async Task ListByAirlineAsyncTest()
IAsyncEnumerable matches = await _factory.Flights
.ListByAirlineAsync(AirlineName, 1, 100);
List flights = await matches.ToListAsync();
- Assert.AreEqual(1, flights.Count());
+ Assert.AreEqual(1, flights.Count);
Assert.AreEqual(FlightNumber, flights.First().Number);
Assert.AreEqual(AirlineName, flights.First().Airline.Name);
}
diff --git a/src/FlightRecorder.Tests/LocationManagerTest.cs b/src/FlightRecorder.Tests/LocationManagerTest.cs
index ab0bbe4..31cb255 100644
--- a/src/FlightRecorder.Tests/LocationManagerTest.cs
+++ b/src/FlightRecorder.Tests/LocationManagerTest.cs
@@ -19,7 +19,7 @@ public class LocationManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_factory.Locations.Add(EntityName);
}
@@ -71,7 +71,7 @@ public async Task ListAllAsyncTest()
List entities = await _factory.Locations
.ListAsync(null, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, entities.Count());
+ Assert.AreEqual(1, entities.Count);
Assert.AreEqual(EntityName, entities.First().Name);
}
@@ -89,7 +89,7 @@ public async Task FilteredListAsyncTest()
List entities = await _factory.Locations
.ListAsync(e => e.Name == EntityName, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, entities.Count());
+ Assert.AreEqual(1, entities.Count);
Assert.AreEqual(EntityName, entities.First().Name);
}
diff --git a/src/FlightRecorder.Tests/ManufacturerTest.cs b/src/FlightRecorder.Tests/ManufacturerTest.cs
index 939ae95..3116cb4 100644
--- a/src/FlightRecorder.Tests/ManufacturerTest.cs
+++ b/src/FlightRecorder.Tests/ManufacturerTest.cs
@@ -19,7 +19,7 @@ public class ManufacturerManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_factory.Manufacturers.Add(EntityName);
}
@@ -75,7 +75,7 @@ public async Task ListAllAsyncTest()
List entities = await _factory.Manufacturers
.ListAsync(null, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, entities.Count());
+ Assert.AreEqual(1, entities.Count);
Assert.AreEqual(EntityName, entities.First().Name);
}
@@ -94,7 +94,7 @@ public async Task FilteredListAsyncTest()
List entities = await _factory.Manufacturers
.ListAsync(e => e.Name == EntityName, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, entities.Count());
+ Assert.AreEqual(1, entities.Count);
Assert.AreEqual(EntityName, entities.First().Name);
}
diff --git a/src/FlightRecorder.Tests/ModelManagerTest.cs b/src/FlightRecorder.Tests/ModelManagerTest.cs
index 38c4f52..0494090 100644
--- a/src/FlightRecorder.Tests/ModelManagerTest.cs
+++ b/src/FlightRecorder.Tests/ModelManagerTest.cs
@@ -20,7 +20,7 @@ public class ModelManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
_factory.Models.Add(ModelName, ManufacturerName);
}
@@ -84,7 +84,7 @@ public async Task ListAllAsyncTest()
List models = await _factory.Models
.ListAsync(null, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, models.Count());
+ Assert.AreEqual(1, models.Count);
Assert.AreEqual(ModelName, models.First().Name);
Assert.AreEqual(ManufacturerName, models.First().Manufacturer.Name);
}
@@ -105,7 +105,7 @@ public async Task FilteredListAsyncTest()
List models = await _factory.Models
.ListAsync(e => e.Name == ModelName, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, models.Count());
+ Assert.AreEqual(1, models.Count);
Assert.AreEqual(ModelName, models.First().Name);
Assert.AreEqual(ManufacturerName, models.First().Manufacturer.Name);
}
@@ -132,7 +132,7 @@ public async Task ListByManufacturerAsyncTest()
List models = await _factory.Models
.ListByManufacturerAsync(ManufacturerName, 1, 100)
.ToListAsync();
- Assert.AreEqual(1, models.Count());
+ Assert.AreEqual(1, models.Count);
Assert.AreEqual(ModelName, models.First().Name);
Assert.AreEqual(ManufacturerName, models.First().Manufacturer.Name);
}
diff --git a/src/FlightRecorder.Tests/SightingManagerTest.cs b/src/FlightRecorder.Tests/SightingManagerTest.cs
index b0737ae..27d7025 100644
--- a/src/FlightRecorder.Tests/SightingManagerTest.cs
+++ b/src/FlightRecorder.Tests/SightingManagerTest.cs
@@ -1,280 +1,280 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using FlightRecorder.BusinessLogic.Factory;
-using FlightRecorder.Data;
-using FlightRecorder.Entities.Db;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace FlightRecorder.Tests
-{
- [TestClass]
- public class SightingManagerTest
- {
- private const string LocationName = "Murcia Corvera International Airport";
-
- private const string FlightNumber = "U28551";
- private const string Embarkation = "LGW";
- private const string Destination = "RMU";
- private const string AirlineName = "EasyJet";
-
- private const string ModelName = "A319-111";
- private const string ManufacturerName = "Airbus";
- private const string Registration = "G-EZFY";
- private const string SerialNumber = "4418";
- private const long YearOfManufacture = 2010;
-
- private const long Altitude = 930;
- private readonly DateTime SightingDate = new DateTime(2019, 9, 22);
- private readonly DateTime AsyncSightingDate = new DateTime(2020, 4, 11);
-
- private FlightRecorderFactory _factory;
- private long _locationId;
- private long _flightId;
- private long _aircraftId;
- private long _sightingId;
-
- [TestInitialize]
- public void TestInitialize()
- {
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
- _factory = new FlightRecorderFactory(context);
-
- _locationId = _factory.Locations.Add(LocationName).Id;
- _flightId = _factory.Flights.Add(FlightNumber, Embarkation, Destination, AirlineName).Id;
- _aircraftId = _factory.Aircraft.Add(Registration, SerialNumber, YearOfManufacture, ModelName, ManufacturerName).Id;
- _sightingId = _factory.Sightings.Add(Altitude, SightingDate, _locationId, _flightId, _aircraftId).Id;
- }
-
- [TestMethod]
- public void AddAndGetTest()
- {
- Sighting sighting = _factory.Sightings.Get(a => a.Id == _sightingId);
-
- Assert.IsNotNull(sighting);
- Assert.AreEqual(_sightingId, sighting.Id);
- Assert.AreEqual(Altitude, sighting.Altitude);
- Assert.AreEqual(SightingDate, sighting.Date);
-
- Assert.IsNotNull(sighting.Location);
- Assert.AreEqual(_locationId, sighting.Location.Id);
- Assert.AreEqual(LocationName, sighting.Location.Name);
-
- Assert.IsNotNull(sighting.Flight);
- Assert.AreEqual(_flightId, sighting.Flight.Id);
- Assert.AreEqual(FlightNumber, sighting.Flight.Number);
- Assert.AreEqual(Embarkation, sighting.Flight.Embarkation);
- Assert.AreEqual(Destination, sighting.Flight.Destination);
-
- Assert.IsNotNull(sighting.Flight.Airline);
- Assert.AreEqual(AirlineName, sighting.Flight.Airline.Name);
-
- Assert.IsNotNull(sighting.Aircraft);
- Assert.AreEqual(_aircraftId, sighting.Aircraft.Id);
- Assert.AreEqual(Registration, sighting.Aircraft.Registration);
- Assert.AreEqual(SerialNumber, sighting.Aircraft.SerialNumber);
- Assert.AreEqual(YearOfManufacture, sighting.Aircraft.Manufactured);
-
- Assert.IsNotNull(sighting.Aircraft.Model);
- Assert.AreEqual(ModelName, sighting.Aircraft.Model.Name);
-
- Assert.IsNotNull(sighting.Aircraft.Model.Manufacturer);
- Assert.AreEqual(ManufacturerName, sighting.Aircraft.Model.Manufacturer.Name);
- }
-
- [TestMethod]
- public async Task AddAndGetAsyncTest()
- {
- long sightingId = (await _factory.Sightings.AddAsync(Altitude, AsyncSightingDate, _locationId, _flightId, _aircraftId)).Id;
- Sighting sighting = await _factory.Sightings.GetAsync(a => a.Id == sightingId);
-
- Assert.IsNotNull(sighting);
- Assert.AreEqual(sightingId, sighting.Id);
- Assert.AreEqual(Altitude, sighting.Altitude);
- Assert.AreEqual(AsyncSightingDate, sighting.Date);
-
- Assert.IsNotNull(sighting.Location);
- Assert.AreEqual(_locationId, sighting.Location.Id);
- Assert.AreEqual(LocationName, sighting.Location.Name);
-
- Assert.IsNotNull(sighting.Flight);
- Assert.AreEqual(_flightId, sighting.Flight.Id);
- Assert.AreEqual(FlightNumber, sighting.Flight.Number);
- Assert.AreEqual(Embarkation, sighting.Flight.Embarkation);
- Assert.AreEqual(Destination, sighting.Flight.Destination);
-
- Assert.IsNotNull(sighting.Flight.Airline);
- Assert.AreEqual(AirlineName, sighting.Flight.Airline.Name);
-
- Assert.IsNotNull(sighting.Aircraft);
- Assert.AreEqual(_aircraftId, sighting.Aircraft.Id);
- Assert.AreEqual(Registration, sighting.Aircraft.Registration);
- Assert.AreEqual(SerialNumber, sighting.Aircraft.SerialNumber);
- Assert.AreEqual(YearOfManufacture, sighting.Aircraft.Manufactured);
-
- Assert.IsNotNull(sighting.Aircraft.Model);
- Assert.AreEqual(ModelName, sighting.Aircraft.Model.Name);
-
- Assert.IsNotNull(sighting.Aircraft.Model.Manufacturer);
- Assert.AreEqual(ManufacturerName, sighting.Aircraft.Model.Manufacturer.Name);
- }
-
- [TestMethod]
- public void GetMissingTest()
- {
- Sighting sighting = _factory.Sightings.Get(a => a.FlightId == 0);
- Assert.IsNull(sighting);
- }
-
- [TestMethod]
- public void ListAllTest()
- {
- IEnumerable sightings = _factory.Sightings.List(null, 1, 100);
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public async Task ListAllAsyncTest()
- {
- List sightings = await _factory.Sightings
- .ListAsync(null, 1, 100)
- .ToListAsync();
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public void ListByAircraftTest()
- {
- IEnumerable sightings = _factory.Sightings.ListByAircraft(Registration, 1, 100);
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public async Task ListByAircraftAsyncTest()
- {
- IAsyncEnumerable matches = await _factory.Sightings
- .ListByAircraftAsync(Registration, 1, 100);
- List sightings = await matches.ToListAsync();
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public void ListByAircraftWithNoSightingsTest()
- {
- _factory.Aircraft.Add("G-EZEH", "2184", 2004, ModelName, ManufacturerName);
- IEnumerable sightings = _factory.Sightings.ListByAircraft("G-EZEH", 1, 100);
- Assert.AreEqual(0, sightings.Count());
- }
-
- [TestMethod]
- public void ListByMissingAircraftTest()
- {
- IEnumerable sightings = _factory.Sightings.ListByAircraft("Missing", 1, 100);
- Assert.IsNull(sightings);
- }
-
- [TestMethod]
- public void ListByRouteTest()
- {
- IEnumerable sightings = _factory.Sightings.ListByRoute(Embarkation, Destination, 1, 100);
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public async Task ListByRouteAsyncTest()
- {
- IAsyncEnumerable matches = await _factory.Sightings
- .ListByRouteAsync(Embarkation, Destination, 1, 100);
- List sightings = await matches.ToListAsync();
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public void ListByRouteWithNoSightingsTest()
- {
- _factory.Flights.Add("BA92", "YYZ", "LHR", "British Airways");
- IEnumerable sightings = _factory.Sightings.ListByRoute("YYZ", "LHR", 1, 100);
- Assert.AreEqual(0, sightings.Count());
- }
-
- [TestMethod]
- public void ListByMissingRoute()
- {
- IEnumerable sightings = _factory.Sightings.ListByRoute("RMU", "MAN", 1, 100);
- Assert.IsNull(sightings);
- }
-
- [TestMethod]
- public void ListByAirlineTest()
- {
- IEnumerable sightings = _factory.Sightings.ListByAirline(AirlineName, 1, 100);
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public async Task ListByAirlineAsyncTest()
- {
- IAsyncEnumerable matches = await _factory.Sightings
- .ListByAirlineAsync(AirlineName, 1, 100);
- List sightings = await matches.ToListAsync();
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public void ListByAirlineWithNoSightingsTest()
- {
- _factory.Airlines.Add("British Airways");
- IEnumerable sightings = _factory.Sightings.ListByAirline("British Airways", 1, 100);
- Assert.IsNull(sightings);
- }
-
- [TestMethod]
- public void ListByMissingAirline()
- {
- IEnumerable sightings = _factory.Sightings.ListByAirline("Missing", 1, 100);
- Assert.IsNull(sightings);
- }
-
- [TestMethod]
- public void ListByLocationTest()
- {
- IEnumerable sightings = _factory.Sightings.ListByLocation(LocationName, 1, 100);
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public async Task ListByLocationAsyncTest()
- {
- IAsyncEnumerable matches = await _factory.Sightings
- .ListByLocationAsync(LocationName, 1, 100);
- List sightings = await matches.ToListAsync();
- Assert.AreEqual(1, sightings.Count());
- Assert.AreEqual(_sightingId, sightings.First().Id);
- }
-
- [TestMethod]
- public void ListByLocationWithNoSightingsTest()
- {
- _factory.Airlines.Add("Gatwick Airport");
- IEnumerable sightings = _factory.Sightings.ListByLocation("Gatwick Airport", 1, 100);
- Assert.IsNull(sightings);
- }
-
- [TestMethod]
- public void ListByMissingLocation()
- {
- IEnumerable sightings = _factory.Sightings.ListByLocation("Missing", 1, 100);
- Assert.IsNull(sightings);
- }
- }
-}
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using FlightRecorder.BusinessLogic.Factory;
+using FlightRecorder.Data;
+using FlightRecorder.Entities.Db;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace FlightRecorder.Tests
+{
+ [TestClass]
+ public class SightingManagerTest
+ {
+ private const string LocationName = "Murcia Corvera International Airport";
+
+ private const string FlightNumber = "U28551";
+ private const string Embarkation = "LGW";
+ private const string Destination = "RMU";
+ private const string AirlineName = "EasyJet";
+
+ private const string ModelName = "A319-111";
+ private const string ManufacturerName = "Airbus";
+ private const string Registration = "G-EZFY";
+ private const string SerialNumber = "4418";
+ private const long YearOfManufacture = 2010;
+
+ private const long Altitude = 930;
+ private readonly DateTime SightingDate = new DateTime(2019, 9, 22);
+ private readonly DateTime AsyncSightingDate = new DateTime(2020, 4, 11);
+
+ private FlightRecorderFactory _factory;
+ private long _locationId;
+ private long _flightId;
+ private long _aircraftId;
+ private long _sightingId;
+
+ [TestInitialize]
+ public void TestInitialize()
+ {
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
+ _factory = new FlightRecorderFactory(context);
+
+ _locationId = _factory.Locations.Add(LocationName).Id;
+ _flightId = _factory.Flights.Add(FlightNumber, Embarkation, Destination, AirlineName).Id;
+ _aircraftId = _factory.Aircraft.Add(Registration, SerialNumber, YearOfManufacture, ModelName, ManufacturerName).Id;
+ _sightingId = _factory.Sightings.Add(Altitude, SightingDate, _locationId, _flightId, _aircraftId).Id;
+ }
+
+ [TestMethod]
+ public void AddAndGetTest()
+ {
+ Sighting sighting = _factory.Sightings.Get(a => a.Id == _sightingId);
+
+ Assert.IsNotNull(sighting);
+ Assert.AreEqual(_sightingId, sighting.Id);
+ Assert.AreEqual(Altitude, sighting.Altitude);
+ Assert.AreEqual(SightingDate, sighting.Date);
+
+ Assert.IsNotNull(sighting.Location);
+ Assert.AreEqual(_locationId, sighting.Location.Id);
+ Assert.AreEqual(LocationName, sighting.Location.Name);
+
+ Assert.IsNotNull(sighting.Flight);
+ Assert.AreEqual(_flightId, sighting.Flight.Id);
+ Assert.AreEqual(FlightNumber, sighting.Flight.Number);
+ Assert.AreEqual(Embarkation, sighting.Flight.Embarkation);
+ Assert.AreEqual(Destination, sighting.Flight.Destination);
+
+ Assert.IsNotNull(sighting.Flight.Airline);
+ Assert.AreEqual(AirlineName, sighting.Flight.Airline.Name);
+
+ Assert.IsNotNull(sighting.Aircraft);
+ Assert.AreEqual(_aircraftId, sighting.Aircraft.Id);
+ Assert.AreEqual(Registration, sighting.Aircraft.Registration);
+ Assert.AreEqual(SerialNumber, sighting.Aircraft.SerialNumber);
+ Assert.AreEqual(YearOfManufacture, sighting.Aircraft.Manufactured);
+
+ Assert.IsNotNull(sighting.Aircraft.Model);
+ Assert.AreEqual(ModelName, sighting.Aircraft.Model.Name);
+
+ Assert.IsNotNull(sighting.Aircraft.Model.Manufacturer);
+ Assert.AreEqual(ManufacturerName, sighting.Aircraft.Model.Manufacturer.Name);
+ }
+
+ [TestMethod]
+ public async Task AddAndGetAsyncTest()
+ {
+ long sightingId = (await _factory.Sightings.AddAsync(Altitude, AsyncSightingDate, _locationId, _flightId, _aircraftId)).Id;
+ Sighting sighting = await _factory.Sightings.GetAsync(a => a.Id == sightingId);
+
+ Assert.IsNotNull(sighting);
+ Assert.AreEqual(sightingId, sighting.Id);
+ Assert.AreEqual(Altitude, sighting.Altitude);
+ Assert.AreEqual(AsyncSightingDate, sighting.Date);
+
+ Assert.IsNotNull(sighting.Location);
+ Assert.AreEqual(_locationId, sighting.Location.Id);
+ Assert.AreEqual(LocationName, sighting.Location.Name);
+
+ Assert.IsNotNull(sighting.Flight);
+ Assert.AreEqual(_flightId, sighting.Flight.Id);
+ Assert.AreEqual(FlightNumber, sighting.Flight.Number);
+ Assert.AreEqual(Embarkation, sighting.Flight.Embarkation);
+ Assert.AreEqual(Destination, sighting.Flight.Destination);
+
+ Assert.IsNotNull(sighting.Flight.Airline);
+ Assert.AreEqual(AirlineName, sighting.Flight.Airline.Name);
+
+ Assert.IsNotNull(sighting.Aircraft);
+ Assert.AreEqual(_aircraftId, sighting.Aircraft.Id);
+ Assert.AreEqual(Registration, sighting.Aircraft.Registration);
+ Assert.AreEqual(SerialNumber, sighting.Aircraft.SerialNumber);
+ Assert.AreEqual(YearOfManufacture, sighting.Aircraft.Manufactured);
+
+ Assert.IsNotNull(sighting.Aircraft.Model);
+ Assert.AreEqual(ModelName, sighting.Aircraft.Model.Name);
+
+ Assert.IsNotNull(sighting.Aircraft.Model.Manufacturer);
+ Assert.AreEqual(ManufacturerName, sighting.Aircraft.Model.Manufacturer.Name);
+ }
+
+ [TestMethod]
+ public void GetMissingTest()
+ {
+ Sighting sighting = _factory.Sightings.Get(a => a.FlightId == 0);
+ Assert.IsNull(sighting);
+ }
+
+ [TestMethod]
+ public void ListAllTest()
+ {
+ IEnumerable sightings = _factory.Sightings.List(null, 1, 100);
+ Assert.AreEqual(1, sightings.Count());
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public async Task ListAllAsyncTest()
+ {
+ List sightings = await _factory.Sightings
+ .ListAsync(null, 1, 100)
+ .ToListAsync();
+ Assert.AreEqual(1, sightings.Count);
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public void ListByAircraftTest()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByAircraft(Registration, 1, 100);
+ Assert.AreEqual(1, sightings.Count());
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public async Task ListByAircraftAsyncTest()
+ {
+ IAsyncEnumerable matches = await _factory.Sightings
+ .ListByAircraftAsync(Registration, 1, 100);
+ List sightings = await matches.ToListAsync();
+ Assert.AreEqual(1, sightings.Count);
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public void ListByAircraftWithNoSightingsTest()
+ {
+ _factory.Aircraft.Add("G-EZEH", "2184", 2004, ModelName, ManufacturerName);
+ IEnumerable sightings = _factory.Sightings.ListByAircraft("G-EZEH", 1, 100);
+ Assert.AreEqual(0, sightings.Count());
+ }
+
+ [TestMethod]
+ public void ListByMissingAircraftTest()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByAircraft("Missing", 1, 100);
+ Assert.IsNull(sightings);
+ }
+
+ [TestMethod]
+ public void ListByRouteTest()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByRoute(Embarkation, Destination, 1, 100);
+ Assert.AreEqual(1, sightings.Count());
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public async Task ListByRouteAsyncTest()
+ {
+ IAsyncEnumerable matches = await _factory.Sightings
+ .ListByRouteAsync(Embarkation, Destination, 1, 100);
+ List sightings = await matches.ToListAsync();
+ Assert.AreEqual(1, sightings.Count);
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public void ListByRouteWithNoSightingsTest()
+ {
+ _factory.Flights.Add("BA92", "YYZ", "LHR", "British Airways");
+ IEnumerable sightings = _factory.Sightings.ListByRoute("YYZ", "LHR", 1, 100);
+ Assert.AreEqual(0, sightings.Count());
+ }
+
+ [TestMethod]
+ public void ListByMissingRoute()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByRoute("RMU", "MAN", 1, 100);
+ Assert.IsNull(sightings);
+ }
+
+ [TestMethod]
+ public void ListByAirlineTest()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByAirline(AirlineName, 1, 100);
+ Assert.AreEqual(1, sightings.Count());
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public async Task ListByAirlineAsyncTest()
+ {
+ IAsyncEnumerable matches = await _factory.Sightings
+ .ListByAirlineAsync(AirlineName, 1, 100);
+ List sightings = await matches.ToListAsync();
+ Assert.AreEqual(1, sightings.Count);
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public void ListByAirlineWithNoSightingsTest()
+ {
+ _factory.Airlines.Add("British Airways");
+ IEnumerable sightings = _factory.Sightings.ListByAirline("British Airways", 1, 100);
+ Assert.IsNull(sightings);
+ }
+
+ [TestMethod]
+ public void ListByMissingAirline()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByAirline("Missing", 1, 100);
+ Assert.IsNull(sightings);
+ }
+
+ [TestMethod]
+ public void ListByLocationTest()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByLocation(LocationName, 1, 100);
+ Assert.AreEqual(1, sightings.Count());
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public async Task ListByLocationAsyncTest()
+ {
+ IAsyncEnumerable matches = await _factory.Sightings
+ .ListByLocationAsync(LocationName, 1, 100);
+ List sightings = await matches.ToListAsync();
+ Assert.AreEqual(1, sightings.Count());
+ Assert.AreEqual(_sightingId, sightings.First().Id);
+ }
+
+ [TestMethod]
+ public void ListByLocationWithNoSightingsTest()
+ {
+ _factory.Airlines.Add("Gatwick Airport");
+ IEnumerable sightings = _factory.Sightings.ListByLocation("Gatwick Airport", 1, 100);
+ Assert.IsNull(sightings);
+ }
+
+ [TestMethod]
+ public void ListByMissingLocation()
+ {
+ IEnumerable sightings = _factory.Sightings.ListByLocation("Missing", 1, 100);
+ Assert.IsNull(sightings);
+ }
+ }
+}
diff --git a/src/FlightRecorder.Tests/UserManagerTest.cs b/src/FlightRecorder.Tests/UserManagerTest.cs
index 3a486b1..ca44704 100644
--- a/src/FlightRecorder.Tests/UserManagerTest.cs
+++ b/src/FlightRecorder.Tests/UserManagerTest.cs
@@ -23,7 +23,7 @@ public class UserManagerTest
[TestInitialize]
public void TestInitialize()
{
- FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
+ FlightRecorderDbContext context = FlightRecorderDbContextFactory.CreateInMemoryDbContext();
_factory = new FlightRecorderFactory(context);
User user = _factory.Users.AddUser(UserName, Password);
@@ -110,7 +110,7 @@ public void GetAllUsersTest()
public async Task GetAllUsersAsyncTest()
{
List users = await _factory.Users.GetUsersAsync().ToListAsync();
- Assert.AreEqual(1, users.Count());
+ Assert.AreEqual(1, users.Count);
Assert.AreEqual(UserName, _factory.Context.Users.First().UserName);
Assert.AreNotEqual(Password, _factory.Context.Users.First().Password);
}