Skip to content
Snippets Groups Projects
Commit c5f466fe authored by Nahodil, Petr's avatar Nahodil, Petr
Browse files

fix of test generator (stop using DateTime.Now) and final fix of export.csv

parent 29c1bb11
No related branches found
No related tags found
No related merge requests found
FlightID,TakeoffTime,LandingTime,Immatriculation,Type,Pilot,Copilot,Task,TowplaneID,GliderID FlightID,TakeoffTime,LandingTime,Immatriculation,Type,Pilot,Copilot,Task,TowplaneID,GliderID
1,19.11.24 16:54:52,,OK-V23428,Zlín Z-42M,Lenka Kiasová,,VLEK,, 1,19.11.24 17:06:47,,OK-V23428,Zlín Z-42M,Lenka Kiasová,,VLEK,,
4,19.11.24 16:54:52,,OK-B128,L-13A Blaník,Silvie Hronová,,Tahac,2,2 4,19.11.24 17:06:47,,OK-B128,L-13A Blaník,Silvie Hronová,,Tahac,2,2
444,07.01.20 16:47:10,07.01.20 17:17:10,OK-B128,L-13A Blaník,Lenka Kiasová,,Tahac,2,2 444,07.01.20 16:47:10,07.01.20 17:17:10,OK-B128,L-13A Blaník,Lenka Kiasová,,Tahac,2,2
24057,19.11.24 15:24:52,,OK-V23428,Zlín Z-42M,Petr Hrubec,,VLEK,, 24057,19.11.24 15:36:47,,OK-V23428,Zlín Z-42M,Petr Hrubec,,VLEK,,
24058,19.11.24 15:24:52,,OK-B128,L-13A Blaník,Silvie Hronová,,Tahac,2,2 24058,19.11.24 15:36:47,,OK-B128,L-13A Blaník,Silvie Hronová,,Tahac,2,2
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
{ {
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using Models; using Models;
using Repositories; using Repositories;
using Repositories.Entities; using Repositories.Entities;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
internal static class TestDatabaseGenerator internal static class TestDatabaseGenerator
...@@ -14,7 +12,7 @@ ...@@ -14,7 +12,7 @@
internal static void RenewDatabase(IConfiguration configuration) internal static void RenewDatabase(IConfiguration configuration)
{ {
DeleteOldDatabase(configuration); DeleteOldDatabase(configuration);
CreateTestDatabaseWithFixedTime(DateTime.Now, configuration); CreateTestDatabaseWithFixedTime(new DateTime(2024, 11, 19, 17, 16, 47, DateTimeKind.Utc), configuration);
} }
public static void DeleteOldDatabase(IConfiguration configuration) public static void DeleteOldDatabase(IConfiguration configuration)
...@@ -26,8 +24,8 @@ ...@@ -26,8 +24,8 @@
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "StringLiteralTypo", Justification = "This is test data.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "StringLiteralTypo", Justification = "This is test data.")]
public static void CreateTestDatabaseWithFixedTime(DateTime now, IConfiguration configuration) public static void CreateTestDatabaseWithFixedTime(DateTime now, IConfiguration configuration)
{ {
using var dbContext = new LocalDatabaseContext(configuration); using var dbContext = new LocalDatabaseContext(configuration);
bool newCreated = dbContext.Database.EnsureCreated(); bool newCreated = dbContext.Database.EnsureCreated();
if (!newCreated) if (!newCreated)
{ {
...@@ -38,96 +36,145 @@ ...@@ -38,96 +36,145 @@
InitializeDatabase(configuration); InitializeDatabase(configuration);
dbContext.Persons.AddRange( dbContext.Persons.AddRange(
new Person { FirstName = "Kamila", LastName = "Spoustová", Address = null },
new Person { FirstName = "Naděžda", LastName = "Pavelková", Address = null },
new Person { FirstName = "Silvie", LastName = "Hronová", Address = null, Id = 103 },
new Person { FirstName = "Miloš", LastName = "Korbel", Address = null },
new Person { FirstName = "Petr", LastName = "Hrubec", Address = null, Id = 105 },
new Person { FirstName = "Michal", LastName = "Vyvlečka", Address = null },
new Person new Person
{ {
Id = 112, FirstName = "Kamila",
LastName = "Spoustová",
Address = null
},
new Person
{
FirstName = "Naděžda",
LastName = "Pavelková",
Address = null
},
new Person
{
FirstName = "Silvie",
LastName = "Hronová",
Address = null,
Id = 103
},
new Person
{
FirstName = "Miloš",
LastName = "Korbel",
Address = null
},
new Person
{
FirstName = "Petr",
LastName = "Hrubec",
Address = null,
Id = 105
},
new Person
{
FirstName = "Michal",
LastName = "Vyvlečka",
Address = null
},
new Person
{
Id = 112,
FirstName = "Lenka", FirstName = "Lenka",
LastName = "Kiasová", LastName = "Kiasová",
Address = new Address { City = null, Country = null, PostalCode = null, Street = null } Address = new Address
}); {
City = null,
Country = null,
PostalCode = null,
Street = null
}
}
);
dbContext.Airplanes.AddRange( dbContext.Airplanes.AddRange(
new Airplane { Id = 2, GuestAirplaneImmatriculation = "OK-B128", GuestAirplaneType = "L-13A Blaník" }, new Airplane
new Airplane { Id = 1, GuestAirplaneImmatriculation = "OK-V23428", GuestAirplaneType = "Zlín Z-42M" }); {
Id = 2,
GuestAirplaneImmatriculation = "OK-B128",
GuestAirplaneType = "L-13A Blaník"
},
new Airplane
{
Id = 1,
GuestAirplaneImmatriculation = "OK-V23428",
GuestAirplaneType = "Zlín Z-42M"
}
);
dbContext.Flights.AddRange( dbContext.Flights.AddRange(
new Flight new Flight
{ {
Id = 1, Id = 1,
TakeoffTime = now.AddMinutes(-10), TakeoffTime = now.AddMinutes(-10),
LandingTime = null, LandingTime = null,
Airplane = dbContext.Airplanes.Find(1L), Airplane = dbContext.Airplanes.Find(1L),
Pilot = dbContext.Persons.Find(112L), Pilot = dbContext.Persons.Find(112L),
Copilot = null, Copilot = null,
Task = "VLEK", Task = "VLEK",
Type = FlightType.Glider Type = FlightType.Glider
}, },
new Flight new Flight
{ {
Id = 4, Id = 4,
TakeoffTime = now.AddMinutes(-10), TakeoffTime = now.AddMinutes(-10),
LandingTime = null, LandingTime = null,
Airplane = dbContext.Airplanes.Find(2L), Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(103L), Pilot = dbContext.Persons.Find(103L),
Copilot = null, Copilot = null,
Task = "Tahac", Task = "Tahac",
Type = FlightType.Towplane Type = FlightType.Towplane
}, },
new Flight new Flight
{ {
Id = 24057, Id = 24057,
TakeoffTime = now.AddMinutes(-100), TakeoffTime = now.AddMinutes(-100),
LandingTime = null, LandingTime = null,
Airplane = dbContext.Airplanes.Find(1L), Airplane = dbContext.Airplanes.Find(1L),
Pilot = dbContext.Persons.Find(105L), Pilot = dbContext.Persons.Find(105L),
Copilot = null, Copilot = null,
Task = "VLEK", Task = "VLEK",
Type = FlightType.Glider Type = FlightType.Glider
}, },
new Flight new Flight
{ {
Id = 24058, Id = 24058,
TakeoffTime = now.AddMinutes(-100), TakeoffTime = now.AddMinutes(-100),
LandingTime = null, LandingTime = null,
Airplane = dbContext.Airplanes.Find(2L), Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(103L), Pilot = dbContext.Persons.Find(103L),
Copilot = null, Copilot = null,
Task = "Tahac", Task = "Tahac",
Type = FlightType.Towplane Type = FlightType.Towplane
}, },
new Flight new Flight
{ {
Id = 444, Id = 444,
TakeoffTime = new DateTime(2020, 1, 7, 16, 47, 10), TakeoffTime = new DateTime(2020, 1, 7, 16, 47, 10),
LandingTime = new DateTime(2020, 1, 7, 17, 17, 10), LandingTime = new DateTime(2020, 1, 7, 17, 17, 10),
Airplane = dbContext.Airplanes.Find(2L), Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(112L), Pilot = dbContext.Persons.Find(112L),
Copilot = null, Copilot = null,
Task = "Tahac", Task = "Tahac",
Type = FlightType.Towplane Type = FlightType.Towplane
}); }
);
dbContext.FlightStarts.AddRange( dbContext.FlightStarts.AddRange(
new FlightStart new FlightStart
{ {
Glider = dbContext.Flights.Find(1L), Glider = dbContext.Flights.Find(1L),
Towplane = dbContext.Flights.Find(4L) Towplane = dbContext.Flights.Find(4L)
}, },
new FlightStart new FlightStart
{ {
Glider = dbContext.Flights.Find(24057L), Glider = dbContext.Flights.Find(24057L),
Towplane = dbContext.Flights.Find(24058L) Towplane = dbContext.Flights.Find(24058L)
}, },
new FlightStart new FlightStart { Towplane = dbContext.Flights.Find(444L) }
{ );
Towplane = dbContext.Flights.Find(444L)
});
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
...@@ -139,16 +186,17 @@ ...@@ -139,16 +186,17 @@
dbContext.ClubAirplanes.AddRange( dbContext.ClubAirplanes.AddRange(
new ClubAirplane new ClubAirplane
{ {
Id = 2, Id = 2,
Immatriculation = "OK-B123", Immatriculation = "OK-B123",
AirplaneType = new AirplaneType { Type = "L-13A Blaník" } AirplaneType = new AirplaneType { Type = "L-13A Blaník" }
}, },
new ClubAirplane new ClubAirplane
{ {
Id = 1, Id = 1,
Immatriculation = "OK-V23424", Immatriculation = "OK-V23424",
AirplaneType = new AirplaneType { Type = "Zlín Z-42M" } AirplaneType = new AirplaneType { Type = "Zlín Z-42M" }
}); }
);
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment