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
1,19.11.24 16:54:52,,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
1,19.11.24 17:06:47,,OK-V23428,Zlín Z-42M,Lenka Kiasová,,VLEK,,
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
24057,19.11.24 15:24:52,,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
24057,19.11.24 15:36:47,,OK-V23428,Zlín Z-42M,Petr Hrubec,,VLEK,,
24058,19.11.24 15:36:47,,OK-B128,L-13A Blaník,Silvie Hronová,,Tahac,2,2
......@@ -2,11 +2,9 @@
{
using System;
using System.Diagnostics;
using Models;
using Repositories;
using Repositories.Entities;
using Microsoft.Extensions.Configuration;
internal static class TestDatabaseGenerator
......@@ -14,7 +12,7 @@
internal static void RenewDatabase(IConfiguration 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)
......@@ -26,8 +24,8 @@
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "StringLiteralTypo", Justification = "This is test data.")]
public static void CreateTestDatabaseWithFixedTime(DateTime now, IConfiguration configuration)
{
using var dbContext = new LocalDatabaseContext(configuration);
bool newCreated = dbContext.Database.EnsureCreated();
using var dbContext = new LocalDatabaseContext(configuration);
bool newCreated = dbContext.Database.EnsureCreated();
if (!newCreated)
{
......@@ -38,96 +36,145 @@
InitializeDatabase(configuration);
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
{
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",
LastName = "Kiasová",
Address = new Address { City = null, Country = null, PostalCode = null, Street = null }
});
LastName = "Kiasová",
Address = new Address
{
City = null,
Country = null,
PostalCode = null,
Street = null
}
}
);
dbContext.Airplanes.AddRange(
new Airplane { Id = 2, GuestAirplaneImmatriculation = "OK-B128", GuestAirplaneType = "L-13A Blaník" },
new Airplane { Id = 1, GuestAirplaneImmatriculation = "OK-V23428", GuestAirplaneType = "Zlín Z-42M" });
new Airplane
{
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(
new Flight
{
Id = 1,
Id = 1,
TakeoffTime = now.AddMinutes(-10),
LandingTime = null,
Airplane = dbContext.Airplanes.Find(1L),
Pilot = dbContext.Persons.Find(112L),
Copilot = null,
Task = "VLEK",
Type = FlightType.Glider
Airplane = dbContext.Airplanes.Find(1L),
Pilot = dbContext.Persons.Find(112L),
Copilot = null,
Task = "VLEK",
Type = FlightType.Glider
},
new Flight
{
Id = 4,
Id = 4,
TakeoffTime = now.AddMinutes(-10),
LandingTime = null,
Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(103L),
Copilot = null,
Task = "Tahac",
Type = FlightType.Towplane
Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(103L),
Copilot = null,
Task = "Tahac",
Type = FlightType.Towplane
},
new Flight
{
Id = 24057,
Id = 24057,
TakeoffTime = now.AddMinutes(-100),
LandingTime = null,
Airplane = dbContext.Airplanes.Find(1L),
Pilot = dbContext.Persons.Find(105L),
Copilot = null,
Task = "VLEK",
Type = FlightType.Glider
Airplane = dbContext.Airplanes.Find(1L),
Pilot = dbContext.Persons.Find(105L),
Copilot = null,
Task = "VLEK",
Type = FlightType.Glider
},
new Flight
{
Id = 24058,
Id = 24058,
TakeoffTime = now.AddMinutes(-100),
LandingTime = null,
Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(103L),
Copilot = null,
Task = "Tahac",
Type = FlightType.Towplane
Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(103L),
Copilot = null,
Task = "Tahac",
Type = FlightType.Towplane
},
new Flight
{
Id = 444,
Id = 444,
TakeoffTime = new DateTime(2020, 1, 7, 16, 47, 10),
LandingTime = new DateTime(2020, 1, 7, 17, 17, 10),
Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(112L),
Copilot = null,
Task = "Tahac",
Type = FlightType.Towplane
});
Airplane = dbContext.Airplanes.Find(2L),
Pilot = dbContext.Persons.Find(112L),
Copilot = null,
Task = "Tahac",
Type = FlightType.Towplane
}
);
dbContext.FlightStarts.AddRange(
new FlightStart
{
Glider = dbContext.Flights.Find(1L),
Glider = dbContext.Flights.Find(1L),
Towplane = dbContext.Flights.Find(4L)
},
new FlightStart
{
Glider = dbContext.Flights.Find(24057L),
Glider = dbContext.Flights.Find(24057L),
Towplane = dbContext.Flights.Find(24058L)
},
new FlightStart
{
Towplane = dbContext.Flights.Find(444L)
});
new FlightStart { Towplane = dbContext.Flights.Find(444L) }
);
dbContext.SaveChanges();
}
......@@ -139,16 +186,17 @@
dbContext.ClubAirplanes.AddRange(
new ClubAirplane
{
Id = 2,
Id = 2,
Immatriculation = "OK-B123",
AirplaneType = new AirplaneType { Type = "L-13A Blaník" }
AirplaneType = new AirplaneType { Type = "L-13A Blaník" }
},
new ClubAirplane
{
Id = 1,
Id = 1,
Immatriculation = "OK-V23424",
AirplaneType = new AirplaneType { Type = "Zlín Z-42M" }
});
AirplaneType = new AirplaneType { Type = "Zlín Z-42M" }
}
);
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