From c5b95332b52a9bf1cb0276862813d318a81cf7de Mon Sep 17 00:00:00 2001 From: Factorino73 Date: Tue, 9 Apr 2024 13:48:30 +0400 Subject: [PATCH] Add tests --- .../BusinessLogics/DriverLogic.cs | 48 ++++ .../BusinessLogics/RouteLogic.cs | 47 ++++ .../BusinessLogics/ScheduleLogic.cs | 47 ++++ .../BusinessLogics/StopLogic.cs | 47 ++++ .../BusinessLogics/TransportLogic.cs | 47 ++++ .../BusinessLogicsContracts/IDriverLogic.cs | 19 ++ .../BusinessLogicsContracts/IRouteLogic.cs | 19 ++ .../BusinessLogicsContracts/IScheduleLogic.cs | 19 ++ .../BusinessLogicsContracts/IStopLogic.cs | 19 ++ .../ITransportLogic.cs | 19 ++ .../StoragesContracts/IDriverStorage.cs | 19 ++ .../StoragesContracts/IRouteStorage.cs | 19 ++ .../StoragesContracts/IScheduleStorage.cs | 19 ++ .../StoragesContracts/IStopStorage.cs | 19 ++ .../StoragesContracts/ITransportStorage.cs | 19 ++ .../Implements/DriverStorage.cs | 56 +++++ .../Implements/RouteStorage.cs | 59 +++++ .../Implements/ScheduleStorage.cs | 56 +++++ .../Implements/StopStorage.cs | 55 +++++ .../Implements/TransportStorage.cs | 56 +++++ .../FormDriversTests.Designer.cs | 230 ++++++++++++++++++ RouteGuide/RouteGuideView/FormDriversTests.cs | 143 +++++++++++ .../RouteGuideView/FormDriversTests.resx | 120 +++++++++ .../RouteGuideView/FormMain.Designer.cs | 64 ++++- RouteGuide/RouteGuideView/FormMain.cs | 70 ++++++ RouteGuide/RouteGuideView/FormRoutes.cs | 1 + .../FormRoutesTests.Designer.cs | 230 ++++++++++++++++++ RouteGuide/RouteGuideView/FormRoutesTests.cs | 150 ++++++++++++ .../RouteGuideView/FormRoutesTests.resx | 120 +++++++++ .../RouteGuideView/FormSchedule.Designer.cs | 20 +- .../FormSchedulesTests.Designer.cs | 230 ++++++++++++++++++ .../RouteGuideView/FormSchedulesTests.cs | 153 ++++++++++++ .../RouteGuideView/FormSchedulesTests.resx | 120 +++++++++ .../RouteGuideView/FormStopsTests.Designer.cs | 230 ++++++++++++++++++ RouteGuide/RouteGuideView/FormStopsTests.cs | 143 +++++++++++ RouteGuide/RouteGuideView/FormStopsTests.resx | 120 +++++++++ .../FormTransportTests.Designer.cs | 230 ++++++++++++++++++ .../RouteGuideView/FormTransportTests.cs | 152 ++++++++++++ .../RouteGuideView/FormTransportTests.resx | 120 +++++++++ RouteGuide/RouteGuideView/Program.cs | 12 +- 40 files changed, 3350 insertions(+), 16 deletions(-) create mode 100644 RouteGuide/RouteGuideView/FormDriversTests.Designer.cs create mode 100644 RouteGuide/RouteGuideView/FormDriversTests.cs create mode 100644 RouteGuide/RouteGuideView/FormDriversTests.resx create mode 100644 RouteGuide/RouteGuideView/FormRoutesTests.Designer.cs create mode 100644 RouteGuide/RouteGuideView/FormRoutesTests.cs create mode 100644 RouteGuide/RouteGuideView/FormRoutesTests.resx create mode 100644 RouteGuide/RouteGuideView/FormSchedulesTests.Designer.cs create mode 100644 RouteGuide/RouteGuideView/FormSchedulesTests.cs create mode 100644 RouteGuide/RouteGuideView/FormSchedulesTests.resx create mode 100644 RouteGuide/RouteGuideView/FormStopsTests.Designer.cs create mode 100644 RouteGuide/RouteGuideView/FormStopsTests.cs create mode 100644 RouteGuide/RouteGuideView/FormStopsTests.resx create mode 100644 RouteGuide/RouteGuideView/FormTransportTests.Designer.cs create mode 100644 RouteGuide/RouteGuideView/FormTransportTests.cs create mode 100644 RouteGuide/RouteGuideView/FormTransportTests.resx diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs index 555310a..0fab9b1 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/DriverLogic.cs @@ -7,6 +7,7 @@ using RouteGuideContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -58,6 +59,26 @@ namespace RouteGuideBusinessLogics.BusinessLogics return list; } + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + public List? ReadList(int count) + { + _logger.LogInformation("ReadList. Count: {Count}", count); + + var list = _driverStorage.GetList(count); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + /// /// Получение отдельной записи /// @@ -138,6 +159,33 @@ namespace RouteGuideBusinessLogics.BusinessLogics return true; } + /// + /// Удаление записи + /// + /// + public bool Delete() + { + _logger.LogInformation("Delete. Driver"); + + if (_driverStorage.Delete() == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Удаление всех записей + /// + /// + public int Clear() + { + int count = _driverStorage.Clear(); + _logger.LogInformation("Clear. Delete {Count} Drivers", count); + return count; + } + /// /// Проверка модели /// diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs index 7cef2bd..b719770 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/RouteLogic.cs @@ -58,6 +58,26 @@ namespace RouteGuideBusinessLogics.BusinessLogics return list; } + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + public List? ReadList(int count) + { + _logger.LogInformation("ReadList. Count: {Count}", count); + + var list = _routeStorage.GetList(count); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + /// /// Получение отдельной записи /// @@ -138,6 +158,33 @@ namespace RouteGuideBusinessLogics.BusinessLogics return true; } + /// + /// Удаление записи + /// + /// + public bool Delete() + { + _logger.LogInformation("Delete. Route"); + + if (_routeStorage.Delete() == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Удаление всех записей + /// + /// + public int Clear() + { + int count = _routeStorage.Clear(); + _logger.LogInformation("Clear. Delete {Count} Routes", count); + return count; + } + /// /// Проверка модели /// diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs index 00e9f52..156047c 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/ScheduleLogic.cs @@ -58,6 +58,26 @@ namespace RouteGuideBusinessLogics.BusinessLogics return list; } + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + public List? ReadList(int count) + { + _logger.LogInformation("ReadList. Count: {Count}", count); + + var list = _scheduleStorage.GetList(count); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + /// /// Получение отдельной записи /// @@ -138,6 +158,33 @@ namespace RouteGuideBusinessLogics.BusinessLogics return true; } + /// + /// Удаление записи + /// + /// + public bool Delete() + { + _logger.LogInformation("Delete. Schedule"); + + if (_scheduleStorage.Delete() == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Удаление всех записей + /// + /// + public int Clear() + { + int count = _scheduleStorage.Clear(); + _logger.LogInformation("Clear. Delete {Count} Schedules", count); + return count; + } + /// /// Проверка модели /// diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs index afa080f..4e2624d 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/StopLogic.cs @@ -58,6 +58,26 @@ namespace RouteGuideBusinessLogics.BusinessLogics return list; } + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + public List? ReadList(int count) + { + _logger.LogInformation("ReadList. Count: {Count}", count); + + var list = _stopStorage.GetList(count); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + /// /// Получение отдельной записи /// @@ -138,6 +158,33 @@ namespace RouteGuideBusinessLogics.BusinessLogics return true; } + /// + /// Удаление записи + /// + /// + public bool Delete() + { + _logger.LogInformation("Delete. Stop"); + + if (_stopStorage.Delete() == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Удаление всех записей + /// + /// + public int Clear() + { + int count = _stopStorage.Clear(); + _logger.LogInformation("Clear. Delete {Count} Stops", count); + return count; + } + /// /// Проверка модели /// diff --git a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs index d7a6714..afc18f3 100644 --- a/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs +++ b/RouteGuide/RouteGuideBusinessLogics/BusinessLogics/TransportLogic.cs @@ -58,6 +58,26 @@ namespace RouteGuideBusinessLogics.BusinessLogics return list; } + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + public List? ReadList(int count) + { + _logger.LogInformation("ReadList. Count: {Count}", count); + + var list = _transportStorage.GetList(count); + if (list == null) + { + _logger.LogWarning("ReadList. Returned null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + /// /// Получение отдельной записи /// @@ -138,6 +158,33 @@ namespace RouteGuideBusinessLogics.BusinessLogics return true; } + /// + /// Удаление записи + /// + /// + public bool Delete() + { + _logger.LogInformation("Delete. Transport"); + + if (_transportStorage.Delete() == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Удаление всех записей + /// + /// + public int Clear() + { + int count = _transportStorage.Clear(); + _logger.LogInformation("Clear. Delete {Count} Transports", count); + return count; + } + /// /// Проверка модели /// diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IDriverLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IDriverLogic.cs index 76e0674..4f358fa 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IDriverLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IDriverLogic.cs @@ -21,6 +21,13 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// List? ReadList(DriverSearchModel? model); + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + List? ReadList(int count); + /// /// Получение отдельной записи /// @@ -48,5 +55,17 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// /// bool Delete(DriverBindingModel model); + + /// + /// Удаление записи + /// + /// + bool Delete(); + + /// + /// Удаление всех записей + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IRouteLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IRouteLogic.cs index fd078b0..a1197a0 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IRouteLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IRouteLogic.cs @@ -21,6 +21,13 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// List? ReadList(RouteSearchModel? model); + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + List? ReadList(int count); + /// /// Получение отдельной записи /// @@ -48,5 +55,17 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// /// bool Delete(RouteBindingModel model); + + /// + /// Удаление записи + /// + /// + bool Delete(); + + /// + /// Удаление всех записей + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IScheduleLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IScheduleLogic.cs index 9b2932c..5cad8e0 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IScheduleLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IScheduleLogic.cs @@ -21,6 +21,13 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// List? ReadList(ScheduleSearchModel? model); + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + List? ReadList(int count); + /// /// Получение отдельной записи /// @@ -48,5 +55,17 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// /// bool Delete(ScheduleBindingModel model); + + /// + /// Удаление записи + /// + /// + bool Delete(); + + /// + /// Удаление всех записей + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs index 25da1ec..fda34c2 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/IStopLogic.cs @@ -21,6 +21,13 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// List? ReadList(StopSearchModel? model); + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + List? ReadList(int count); + /// /// Получение отдельной записи /// @@ -48,5 +55,17 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// /// bool Delete(StopBindingModel model); + + /// + /// Удаление записи + /// + /// + bool Delete(); + + /// + /// Удаление всех записей + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/ITransportLogic.cs b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/ITransportLogic.cs index bd530d5..23b08b3 100644 --- a/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/ITransportLogic.cs +++ b/RouteGuide/RouteGuideContracts/BusinessLogicsContracts/ITransportLogic.cs @@ -21,6 +21,13 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// List? ReadList(TransportSearchModel? model); + /// + /// Получение списка из заданного количества элементов + /// + /// + /// + List? ReadList(int count); + /// /// Получение отдельной записи /// @@ -48,5 +55,17 @@ namespace RouteGuideContracts.BusinessLogicsContracts /// /// bool Delete(TransportBindingModel model); + + /// + /// Удаление записи + /// + /// + bool Delete(); + + /// + /// Удаление всех записей + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/StoragesContracts/IDriverStorage.cs b/RouteGuide/RouteGuideContracts/StoragesContracts/IDriverStorage.cs index ba2797e..f727e30 100644 --- a/RouteGuide/RouteGuideContracts/StoragesContracts/IDriverStorage.cs +++ b/RouteGuide/RouteGuideContracts/StoragesContracts/IDriverStorage.cs @@ -27,6 +27,13 @@ namespace RouteGuideContracts.StoragesContracts /// List GetFilteredList(DriverSearchModel model); + /// + /// Получить список из заданного количества элементов + /// + /// + /// + List GetList(int count); + /// /// Получение элемента /// @@ -54,5 +61,17 @@ namespace RouteGuideContracts.StoragesContracts /// /// DriverViewModel? Delete(DriverBindingModel model); + + /// + /// Удаление элемента + /// + /// + DriverViewModel? Delete(); + + /// + /// Удаление всех элементов + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/StoragesContracts/IRouteStorage.cs b/RouteGuide/RouteGuideContracts/StoragesContracts/IRouteStorage.cs index 7f00cae..5b57950 100644 --- a/RouteGuide/RouteGuideContracts/StoragesContracts/IRouteStorage.cs +++ b/RouteGuide/RouteGuideContracts/StoragesContracts/IRouteStorage.cs @@ -27,6 +27,13 @@ namespace RouteGuideContracts.StoragesContracts /// List GetFilteredList(RouteSearchModel model); + /// + /// Получить список из заданного количества элементов + /// + /// + /// + List GetList(int count); + /// /// Получение элемента /// @@ -54,5 +61,17 @@ namespace RouteGuideContracts.StoragesContracts /// /// RouteViewModel? Delete(RouteBindingModel model); + + /// + /// Удаление элемента + /// + /// + RouteViewModel? Delete(); + + /// + /// Удаление всех элементов + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/StoragesContracts/IScheduleStorage.cs b/RouteGuide/RouteGuideContracts/StoragesContracts/IScheduleStorage.cs index ef6782a..653edcc 100644 --- a/RouteGuide/RouteGuideContracts/StoragesContracts/IScheduleStorage.cs +++ b/RouteGuide/RouteGuideContracts/StoragesContracts/IScheduleStorage.cs @@ -27,6 +27,13 @@ namespace RouteGuideContracts.StoragesContracts /// List GetFilteredList(ScheduleSearchModel model); + /// + /// Получить список из заданного количества элементов + /// + /// + /// + List GetList(int count); + /// /// Получение элемента /// @@ -54,5 +61,17 @@ namespace RouteGuideContracts.StoragesContracts /// /// ScheduleViewModel? Delete(ScheduleBindingModel model); + + /// + /// Удаление элемента + /// + /// + ScheduleViewModel? Delete(); + + /// + /// Удаление всех элементов + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/StoragesContracts/IStopStorage.cs b/RouteGuide/RouteGuideContracts/StoragesContracts/IStopStorage.cs index 56a18f1..8f105a3 100644 --- a/RouteGuide/RouteGuideContracts/StoragesContracts/IStopStorage.cs +++ b/RouteGuide/RouteGuideContracts/StoragesContracts/IStopStorage.cs @@ -27,6 +27,13 @@ namespace RouteGuideContracts.StoragesContracts /// List GetFilteredList(StopSearchModel model); + /// + /// Получить список из заданного количества элементов + /// + /// + /// + List GetList(int count); + /// /// Получение элемента /// @@ -54,5 +61,17 @@ namespace RouteGuideContracts.StoragesContracts /// /// StopViewModel? Delete(StopBindingModel model); + + /// + /// Удаление элемента + /// + /// + StopViewModel? Delete(); + + /// + /// Удаление всех элементов + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideContracts/StoragesContracts/ITransportStorage.cs b/RouteGuide/RouteGuideContracts/StoragesContracts/ITransportStorage.cs index 2e723bc..d2e45b2 100644 --- a/RouteGuide/RouteGuideContracts/StoragesContracts/ITransportStorage.cs +++ b/RouteGuide/RouteGuideContracts/StoragesContracts/ITransportStorage.cs @@ -27,6 +27,13 @@ namespace RouteGuideContracts.StoragesContracts /// List GetFilteredList(TransportSearchModel model); + /// + /// Получить список из заданного количества элементов + /// + /// + /// + List GetList(int count); + /// /// Получение элемента /// @@ -54,5 +61,17 @@ namespace RouteGuideContracts.StoragesContracts /// /// TransportViewModel? Delete(TransportBindingModel model); + + /// + /// Удаление элемента + /// + /// + TransportViewModel? Delete(); + + /// + /// Удаление всех элементов + /// + /// + int Clear(); } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs index 56da60c..1e7873f 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/DriverStorage.cs @@ -5,6 +5,7 @@ using RouteGuideContracts.ViewModels; using RouteGuideDatabaseImplement.Models; using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -47,6 +48,25 @@ namespace RouteGuideDatabaseImplement.Implements .ToList(); } + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + return context.Drivers + .Take(count) + .Select(x => x.GetViewModel) + .ToList(); + } + /// /// Получение элемента /// @@ -121,5 +141,41 @@ namespace RouteGuideDatabaseImplement.Implements context.SaveChanges(); return driver.GetViewModel; } + + /// + /// Удаление записи + /// + /// + public DriverViewModel? Delete() + { + using var context = new RouteGuideDatabase(); + if (!context.Drivers.Any()) + { + return null; + } + + var element = context.Drivers.First(); + context.Drivers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = context.Drivers.Count(); + if (count <= 0) + { + return 0; + } + + context.Drivers.RemoveRange(context.Drivers); + context.SaveChanges(); + return count; + } } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs index 4e7463d..ad26756 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/RouteStorage.cs @@ -56,6 +56,29 @@ namespace RouteGuideDatabaseImplement.Implements .ToList(); } + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + return context.Routes + .Include(x => x.Transport) + .Include(x => x.Stops) + .ThenInclude(x => x.Stop) + .ToList() + .Take(count) + .Select(x => x.GetViewModel) + .ToList(); + } + /// /// Получение элемента /// @@ -146,5 +169,41 @@ namespace RouteGuideDatabaseImplement.Implements context.SaveChanges(); return route.GetViewModel; } + + /// + /// Удаление записи + /// + /// + public RouteViewModel? Delete() + { + using var context = new RouteGuideDatabase(); + if (!context.Routes.Any()) + { + return null; + } + + var element = context.Routes.First(); + context.Routes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = context.Routes.Count(); + if (count <= 0) + { + return 0; + } + + context.Routes.RemoveRange(context.Routes); + context.SaveChanges(); + return count; + } } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs index 5abbb54..483d2cc 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/ScheduleStorage.cs @@ -50,6 +50,26 @@ namespace RouteGuideDatabaseImplement.Implements .ToList(); } + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + return context.Schedules + .Include(x => x.Route) + .Take(count) + .Select(x => x.GetViewModel) + .ToList(); + } + /// /// Получение элемента /// @@ -125,5 +145,41 @@ namespace RouteGuideDatabaseImplement.Implements context.SaveChanges(); return schedule.GetViewModel; } + + /// + /// Удаление записи + /// + /// + public ScheduleViewModel? Delete() + { + using var context = new RouteGuideDatabase(); + if (!context.Schedules.Any()) + { + return null; + } + + var element = context.Schedules.First(); + context.Schedules.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = context.Schedules.Count(); + if (count <= 0) + { + return 0; + } + + context.Schedules.RemoveRange(context.Schedules); + context.SaveChanges(); + return count; + } } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs index 246caaa..5b66c72 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/StopStorage.cs @@ -47,6 +47,25 @@ namespace RouteGuideDatabaseImplement.Implements .ToList(); } + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + return context.Stops + .Take(count) + .Select(x => x.GetViewModel) + .ToList(); + } + /// /// Получение элемента /// @@ -121,5 +140,41 @@ namespace RouteGuideDatabaseImplement.Implements context.SaveChanges(); return stop.GetViewModel; } + + /// + /// Удаление записи + /// + /// + public StopViewModel? Delete() + { + using var context = new RouteGuideDatabase(); + if (!context.Stops.Any()) + { + return null; + } + + var element = context.Stops.First(); + context.Stops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = context.Stops.Count(); + if (count <= 0) + { + return 0; + } + + context.Stops.RemoveRange(context.Stops); + context.SaveChanges(); + return count; + } } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs b/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs index fbc8ace..f2d4f24 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Implements/TransportStorage.cs @@ -50,6 +50,26 @@ namespace RouteGuideDatabaseImplement.Implements .ToList(); } + /// + /// Получить список из заданного количества элементов + /// + /// + /// + public List GetList(int count) + { + if (count <= 0) + { + return new(); + } + + using var context = new RouteGuideDatabase(); + return context.Transport + .Include(x => x.Driver) + .Take(count) + .Select(x => x.GetViewModel) + .ToList(); + } + /// /// Получение элемента /// @@ -125,5 +145,41 @@ namespace RouteGuideDatabaseImplement.Implements context.SaveChanges(); return transport.GetViewModel; } + + /// + /// Удаление записи + /// + /// + public TransportViewModel? Delete() + { + using var context = new RouteGuideDatabase(); + if (!context.Transport.Any()) + { + return null; + } + + var element = context.Transport.First(); + context.Transport.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + + /// + /// Удаление всех элементов + /// + /// + public int Clear() + { + using var context = new RouteGuideDatabase(); + int count = context.Transport.Count(); + if (count <= 0) + { + return 0; + } + + context.Transport.RemoveRange(context.Transport); + context.SaveChanges(); + return count; + } } } diff --git a/RouteGuide/RouteGuideView/FormDriversTests.Designer.cs b/RouteGuide/RouteGuideView/FormDriversTests.Designer.cs new file mode 100644 index 0000000..5c85173 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDriversTests.Designer.cs @@ -0,0 +1,230 @@ +namespace RouteGuideView +{ + partial class FormDriversTests + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + numericUpDownInsert = new NumericUpDown(); + numericUpDownRead = new NumericUpDown(); + numericUpDownDelete = new NumericUpDown(); + labelInsert = new Label(); + labelRead = new Label(); + labelDelete = new Label(); + labelEntities1 = new Label(); + labelEntities2 = new Label(); + labelEntities3 = new Label(); + buttonInsert = new Button(); + buttonRead = new Button(); + buttonDelete = new Button(); + labelInsertTime = new Label(); + labelReadTime = new Label(); + labelDeleteTime = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).BeginInit(); + SuspendLayout(); + // + // numericUpDownInsert + // + numericUpDownInsert.Location = new Point(79, 12); + numericUpDownInsert.Name = "numericUpDownInsert"; + numericUpDownInsert.Size = new Size(70, 23); + numericUpDownInsert.TabIndex = 0; + // + // numericUpDownRead + // + numericUpDownRead.Location = new Point(79, 41); + numericUpDownRead.Name = "numericUpDownRead"; + numericUpDownRead.Size = new Size(70, 23); + numericUpDownRead.TabIndex = 1; + // + // numericUpDownDelete + // + numericUpDownDelete.Location = new Point(79, 70); + numericUpDownDelete.Name = "numericUpDownDelete"; + numericUpDownDelete.Size = new Size(70, 23); + numericUpDownDelete.TabIndex = 2; + // + // labelInsert + // + labelInsert.AutoSize = true; + labelInsert.Location = new Point(12, 14); + labelInsert.Name = "labelInsert"; + labelInsert.Size = new Size(50, 15); + labelInsert.TabIndex = 3; + labelInsert.Text = "Создать"; + // + // labelRead + // + labelRead.AutoSize = true; + labelRead.Location = new Point(12, 43); + labelRead.Name = "labelRead"; + labelRead.Size = new Size(61, 15); + labelRead.TabIndex = 4; + labelRead.Text = "Получить"; + // + // labelDelete + // + labelDelete.AutoSize = true; + labelDelete.Location = new Point(12, 72); + labelDelete.Name = "labelDelete"; + labelDelete.Size = new Size(51, 15); + labelDelete.TabIndex = 5; + labelDelete.Text = "Удалить"; + // + // labelEntities1 + // + labelEntities1.AutoSize = true; + labelEntities1.Location = new Point(155, 14); + labelEntities1.Name = "labelEntities1"; + labelEntities1.Size = new Size(68, 15); + labelEntities1.TabIndex = 6; + labelEntities1.Text = "сущностей"; + // + // labelEntities2 + // + labelEntities2.AutoSize = true; + labelEntities2.Location = new Point(155, 43); + labelEntities2.Name = "labelEntities2"; + labelEntities2.Size = new Size(68, 15); + labelEntities2.TabIndex = 7; + labelEntities2.Text = "сущностей"; + // + // labelEntities3 + // + labelEntities3.AutoSize = true; + labelEntities3.Location = new Point(155, 72); + labelEntities3.Name = "labelEntities3"; + labelEntities3.Size = new Size(68, 15); + labelEntities3.TabIndex = 8; + labelEntities3.Text = "сущностей"; + // + // buttonInsert + // + buttonInsert.Location = new Point(260, 12); + buttonInsert.Name = "buttonInsert"; + buttonInsert.Size = new Size(75, 23); + buttonInsert.TabIndex = 9; + buttonInsert.Text = "Создать"; + buttonInsert.UseVisualStyleBackColor = true; + buttonInsert.Click += buttonInsert_Click; + // + // buttonRead + // + buttonRead.Location = new Point(260, 41); + buttonRead.Name = "buttonRead"; + buttonRead.Size = new Size(75, 23); + buttonRead.TabIndex = 10; + buttonRead.Text = "Получить"; + buttonRead.UseVisualStyleBackColor = true; + buttonRead.Click += buttonRead_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(260, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 11; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // labelInsertTime + // + labelInsertTime.AutoSize = true; + labelInsertTime.Location = new Point(372, 16); + labelInsertTime.Name = "labelInsertTime"; + labelInsertTime.Size = new Size(32, 15); + labelInsertTime.TabIndex = 12; + labelInsertTime.Text = "0 ms"; + // + // labelReadTime + // + labelReadTime.AutoSize = true; + labelReadTime.Location = new Point(372, 45); + labelReadTime.Name = "labelReadTime"; + labelReadTime.Size = new Size(32, 15); + labelReadTime.TabIndex = 13; + labelReadTime.Text = "0 ms"; + // + // labelDeleteTime + // + labelDeleteTime.AutoSize = true; + labelDeleteTime.Location = new Point(372, 74); + labelDeleteTime.Name = "labelDeleteTime"; + labelDeleteTime.Size = new Size(32, 15); + labelDeleteTime.TabIndex = 14; + labelDeleteTime.Text = "0 ms"; + // + // FormDriversTests + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 101); + Controls.Add(labelDeleteTime); + Controls.Add(labelReadTime); + Controls.Add(labelInsertTime); + Controls.Add(buttonDelete); + Controls.Add(buttonRead); + Controls.Add(buttonInsert); + Controls.Add(labelEntities3); + Controls.Add(labelEntities2); + Controls.Add(labelEntities1); + Controls.Add(labelDelete); + Controls.Add(labelRead); + Controls.Add(labelInsert); + Controls.Add(numericUpDownDelete); + Controls.Add(numericUpDownRead); + Controls.Add(numericUpDownInsert); + Name = "FormDriversTests"; + Text = "Тесты для сущности \"Водитель\""; + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private NumericUpDown numericUpDownInsert; + private NumericUpDown numericUpDownRead; + private NumericUpDown numericUpDownDelete; + private Label labelInsert; + private Label labelRead; + private Label labelDelete; + private Label labelEntities1; + private Label labelEntities2; + private Label labelEntities3; + private Button buttonInsert; + private Button buttonRead; + private Button buttonDelete; + private Label labelInsertTime; + private Label labelReadTime; + private Label labelDeleteTime; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormDriversTests.cs b/RouteGuide/RouteGuideView/FormDriversTests.cs new file mode 100644 index 0000000..79cb36a --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDriversTests.cs @@ -0,0 +1,143 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма с тестами для сущности "Водитель" + /// + public partial class FormDriversTests : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IDriverLogic _driverLogic; + + /// + /// Конструктор + /// + /// + /// + public FormDriversTests(ILogger logger, IDriverLogic driverLogic) + { + InitializeComponent(); + _logger = logger; + _driverLogic = driverLogic; + + numericUpDownInsert.Maximum = 1000; + numericUpDownRead.Maximum = 1000; + numericUpDownDelete.Maximum = 1000; + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonInsert_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownInsert.Value); + _logger.LogInformation("DriverInsertTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + var model = new DriverBindingModel + { + Id = 0, + FullName = $"Водитель {i}", + Phone = $"Номер {i}", + Experience = 1 + }; + + stopwatch.Start(); + var operationResult = _driverLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Водитель'. Дополнительная информация в логах."); + } + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelInsertTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "DriverInsertTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Получить" + /// + /// + /// + private void buttonRead_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownRead.Value); + _logger.LogInformation("DriverReadTest. Count: {Count}", entitiesCount); + try + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + _driverLogic.ReadList(entitiesCount); + stopwatch.Stop(); + labelReadTime.Text = $"{stopwatch.ElapsedMilliseconds} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "DriverReadTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownDelete.Value); + _logger.LogInformation("DriverDeleteTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + stopwatch.Start(); + _driverLogic.Delete(); + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelDeleteTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "DriverDeleteTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormDriversTests.resx b/RouteGuide/RouteGuideView/FormDriversTests.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDriversTests.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormMain.Designer.cs b/RouteGuide/RouteGuideView/FormMain.Designer.cs index 058cf89..1896005 100644 --- a/RouteGuide/RouteGuideView/FormMain.Designer.cs +++ b/RouteGuide/RouteGuideView/FormMain.Designer.cs @@ -34,6 +34,12 @@ TransportToolStripMenuItem = new ToolStripMenuItem(); RoutesToolStripMenuItem = new ToolStripMenuItem(); StopsToolStripMenuItem = new ToolStripMenuItem(); + тестыToolStripMenuItem = new ToolStripMenuItem(); + DriversTestsToolStripMenuItem = new ToolStripMenuItem(); + TransportTestsToolStripMenuItem = new ToolStripMenuItem(); + RoutesTestsToolStripMenuItem = new ToolStripMenuItem(); + StopsTestsToolStripMenuItem = new ToolStripMenuItem(); + SchedulesTestsToolStripMenuItem = new ToolStripMenuItem(); buttonCreate = new Button(); buttonUpdate = new Button(); buttonDelete = new Button(); @@ -45,7 +51,7 @@ // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, тестыToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(984, 24); @@ -62,31 +68,73 @@ // DrviversToolStripMenuItem // DrviversToolStripMenuItem.Name = "DrviversToolStripMenuItem"; - DrviversToolStripMenuItem.Size = new Size(180, 22); + DrviversToolStripMenuItem.Size = new Size(136, 22); DrviversToolStripMenuItem.Text = "Водители"; DrviversToolStripMenuItem.Click += DrviversToolStripMenuItem_Click; // // TransportToolStripMenuItem // TransportToolStripMenuItem.Name = "TransportToolStripMenuItem"; - TransportToolStripMenuItem.Size = new Size(180, 22); + TransportToolStripMenuItem.Size = new Size(136, 22); TransportToolStripMenuItem.Text = "Транспорт"; TransportToolStripMenuItem.Click += TransportToolStripMenuItem_Click; // // RoutesToolStripMenuItem // RoutesToolStripMenuItem.Name = "RoutesToolStripMenuItem"; - RoutesToolStripMenuItem.Size = new Size(180, 22); + RoutesToolStripMenuItem.Size = new Size(136, 22); RoutesToolStripMenuItem.Text = "Маршруты"; RoutesToolStripMenuItem.Click += RoutesToolStripMenuItem_Click; // // StopsToolStripMenuItem // StopsToolStripMenuItem.Name = "StopsToolStripMenuItem"; - StopsToolStripMenuItem.Size = new Size(180, 22); + StopsToolStripMenuItem.Size = new Size(136, 22); StopsToolStripMenuItem.Text = "Остановки"; StopsToolStripMenuItem.Click += StopsToolStripMenuItem_Click; // + // тестыToolStripMenuItem + // + тестыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DriversTestsToolStripMenuItem, TransportTestsToolStripMenuItem, RoutesTestsToolStripMenuItem, StopsTestsToolStripMenuItem, SchedulesTestsToolStripMenuItem }); + тестыToolStripMenuItem.Name = "тестыToolStripMenuItem"; + тестыToolStripMenuItem.Size = new Size(51, 20); + тестыToolStripMenuItem.Text = "Тесты"; + // + // DriversTestsToolStripMenuItem + // + DriversTestsToolStripMenuItem.Name = "DriversTestsToolStripMenuItem"; + DriversTestsToolStripMenuItem.Size = new Size(180, 22); + DriversTestsToolStripMenuItem.Text = "Водители"; + DriversTestsToolStripMenuItem.Click += DriversTestsToolStripMenuItem_Click; + // + // TransportTestsToolStripMenuItem + // + TransportTestsToolStripMenuItem.Name = "TransportTestsToolStripMenuItem"; + TransportTestsToolStripMenuItem.Size = new Size(180, 22); + TransportTestsToolStripMenuItem.Text = "Транспорт"; + TransportTestsToolStripMenuItem.Click += TransportTestsToolStripMenuItem_Click; + // + // RoutesTestsToolStripMenuItem + // + RoutesTestsToolStripMenuItem.Name = "RoutesTestsToolStripMenuItem"; + RoutesTestsToolStripMenuItem.Size = new Size(180, 22); + RoutesTestsToolStripMenuItem.Text = "Маршруты"; + RoutesTestsToolStripMenuItem.Click += RoutesTestsToolStripMenuItem_Click; + // + // StopsTestsToolStripMenuItem + // + StopsTestsToolStripMenuItem.Name = "StopsTestsToolStripMenuItem"; + StopsTestsToolStripMenuItem.Size = new Size(180, 22); + StopsTestsToolStripMenuItem.Text = "Остановки"; + StopsTestsToolStripMenuItem.Click += StopsTestsToolStripMenuItem_Click; + // + // SchedulesTestsToolStripMenuItem + // + SchedulesTestsToolStripMenuItem.Name = "SchedulesTestsToolStripMenuItem"; + SchedulesTestsToolStripMenuItem.Size = new Size(180, 22); + SchedulesTestsToolStripMenuItem.Text = "Расписания"; + SchedulesTestsToolStripMenuItem.Click += SchedulesTestsToolStripMenuItem_Click; + // // buttonCreate // buttonCreate.Location = new Point(885, 37); @@ -179,5 +227,11 @@ private Button buttonDelete; private Button buttonRefresh; private DataGridView dataGridView; + private ToolStripMenuItem тестыToolStripMenuItem; + private ToolStripMenuItem DriversTestsToolStripMenuItem; + private ToolStripMenuItem TransportTestsToolStripMenuItem; + private ToolStripMenuItem RoutesTestsToolStripMenuItem; + private ToolStripMenuItem StopsTestsToolStripMenuItem; + private ToolStripMenuItem SchedulesTestsToolStripMenuItem; } } diff --git a/RouteGuide/RouteGuideView/FormMain.cs b/RouteGuide/RouteGuideView/FormMain.cs index 57253a3..b5d622b 100644 --- a/RouteGuide/RouteGuideView/FormMain.cs +++ b/RouteGuide/RouteGuideView/FormMain.cs @@ -98,6 +98,76 @@ namespace RouteGuideView } } + /// + /// "" + /// + /// + /// + private void DriversTestsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDriversTests)); + if (service is FormDriversTests form) + { + form.ShowDialog(); + } + } + + /// + /// "" + /// + /// + /// + private void TransportTestsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransportTests)); + if (service is FormTransportTests form) + { + form.ShowDialog(); + } + } + + /// + /// "" + /// + /// + /// + private void RoutesTestsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoutesTests)); + if (service is FormRoutesTests form) + { + form.ShowDialog(); + } + } + + /// + /// "" + /// + /// + /// + private void StopsTestsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStopsTests)); + if (service is FormStopsTests form) + { + form.ShowDialog(); + } + } + + /// + /// "" + /// + /// + /// + private void SchedulesTestsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSchedulesTests)); + if (service is FormSchedulesTests form) + { + form.ShowDialog(); + } + } + /// /// "" /// diff --git a/RouteGuide/RouteGuideView/FormRoutes.cs b/RouteGuide/RouteGuideView/FormRoutes.cs index f37b0b1..c8476c4 100644 --- a/RouteGuide/RouteGuideView/FormRoutes.cs +++ b/RouteGuide/RouteGuideView/FormRoutes.cs @@ -141,6 +141,7 @@ namespace RouteGuideView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["RouteStops"].Visible = false; + dataGridView.Columns["TransportId"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка списка маршрутов"); diff --git a/RouteGuide/RouteGuideView/FormRoutesTests.Designer.cs b/RouteGuide/RouteGuideView/FormRoutesTests.Designer.cs new file mode 100644 index 0000000..a46f3b2 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoutesTests.Designer.cs @@ -0,0 +1,230 @@ +namespace RouteGuideView +{ + partial class FormRoutesTests + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelDeleteTime = new Label(); + labelReadTime = new Label(); + labelInsertTime = new Label(); + buttonDelete = new Button(); + buttonRead = new Button(); + buttonInsert = new Button(); + labelEntities3 = new Label(); + labelEntities2 = new Label(); + labelEntities1 = new Label(); + labelDelete = new Label(); + labelRead = new Label(); + labelInsert = new Label(); + numericUpDownDelete = new NumericUpDown(); + numericUpDownRead = new NumericUpDown(); + numericUpDownInsert = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).BeginInit(); + SuspendLayout(); + // + // labelDeleteTime + // + labelDeleteTime.AutoSize = true; + labelDeleteTime.Location = new Point(376, 72); + labelDeleteTime.Name = "labelDeleteTime"; + labelDeleteTime.Size = new Size(32, 15); + labelDeleteTime.TabIndex = 44; + labelDeleteTime.Text = "0 ms"; + // + // labelReadTime + // + labelReadTime.AutoSize = true; + labelReadTime.Location = new Point(376, 43); + labelReadTime.Name = "labelReadTime"; + labelReadTime.Size = new Size(32, 15); + labelReadTime.TabIndex = 43; + labelReadTime.Text = "0 ms"; + // + // labelInsertTime + // + labelInsertTime.AutoSize = true; + labelInsertTime.Location = new Point(376, 14); + labelInsertTime.Name = "labelInsertTime"; + labelInsertTime.Size = new Size(32, 15); + labelInsertTime.TabIndex = 42; + labelInsertTime.Text = "0 ms"; + // + // buttonDelete + // + buttonDelete.Location = new Point(264, 68); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 41; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRead + // + buttonRead.Location = new Point(264, 39); + buttonRead.Name = "buttonRead"; + buttonRead.Size = new Size(75, 23); + buttonRead.TabIndex = 40; + buttonRead.Text = "Получить"; + buttonRead.UseVisualStyleBackColor = true; + buttonRead.Click += buttonRead_Click; + // + // buttonInsert + // + buttonInsert.Location = new Point(264, 10); + buttonInsert.Name = "buttonInsert"; + buttonInsert.Size = new Size(75, 23); + buttonInsert.TabIndex = 39; + buttonInsert.Text = "Создать"; + buttonInsert.UseVisualStyleBackColor = true; + buttonInsert.Click += buttonInsert_Click; + // + // labelEntities3 + // + labelEntities3.AutoSize = true; + labelEntities3.Location = new Point(159, 70); + labelEntities3.Name = "labelEntities3"; + labelEntities3.Size = new Size(68, 15); + labelEntities3.TabIndex = 38; + labelEntities3.Text = "сущностей"; + // + // labelEntities2 + // + labelEntities2.AutoSize = true; + labelEntities2.Location = new Point(159, 41); + labelEntities2.Name = "labelEntities2"; + labelEntities2.Size = new Size(68, 15); + labelEntities2.TabIndex = 37; + labelEntities2.Text = "сущностей"; + // + // labelEntities1 + // + labelEntities1.AutoSize = true; + labelEntities1.Location = new Point(159, 12); + labelEntities1.Name = "labelEntities1"; + labelEntities1.Size = new Size(68, 15); + labelEntities1.TabIndex = 36; + labelEntities1.Text = "сущностей"; + // + // labelDelete + // + labelDelete.AutoSize = true; + labelDelete.Location = new Point(16, 70); + labelDelete.Name = "labelDelete"; + labelDelete.Size = new Size(51, 15); + labelDelete.TabIndex = 35; + labelDelete.Text = "Удалить"; + // + // labelRead + // + labelRead.AutoSize = true; + labelRead.Location = new Point(16, 41); + labelRead.Name = "labelRead"; + labelRead.Size = new Size(61, 15); + labelRead.TabIndex = 34; + labelRead.Text = "Получить"; + // + // labelInsert + // + labelInsert.AutoSize = true; + labelInsert.Location = new Point(16, 12); + labelInsert.Name = "labelInsert"; + labelInsert.Size = new Size(50, 15); + labelInsert.TabIndex = 33; + labelInsert.Text = "Создать"; + // + // numericUpDownDelete + // + numericUpDownDelete.Location = new Point(83, 68); + numericUpDownDelete.Name = "numericUpDownDelete"; + numericUpDownDelete.Size = new Size(70, 23); + numericUpDownDelete.TabIndex = 32; + // + // numericUpDownRead + // + numericUpDownRead.Location = new Point(83, 39); + numericUpDownRead.Name = "numericUpDownRead"; + numericUpDownRead.Size = new Size(70, 23); + numericUpDownRead.TabIndex = 31; + // + // numericUpDownInsert + // + numericUpDownInsert.Location = new Point(83, 10); + numericUpDownInsert.Name = "numericUpDownInsert"; + numericUpDownInsert.Size = new Size(70, 23); + numericUpDownInsert.TabIndex = 30; + // + // FormRoutesTests + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 101); + Controls.Add(labelDeleteTime); + Controls.Add(labelReadTime); + Controls.Add(labelInsertTime); + Controls.Add(buttonDelete); + Controls.Add(buttonRead); + Controls.Add(buttonInsert); + Controls.Add(labelEntities3); + Controls.Add(labelEntities2); + Controls.Add(labelEntities1); + Controls.Add(labelDelete); + Controls.Add(labelRead); + Controls.Add(labelInsert); + Controls.Add(numericUpDownDelete); + Controls.Add(numericUpDownRead); + Controls.Add(numericUpDownInsert); + Name = "FormRoutesTests"; + Text = "Тесты для сущности \"Маршрут\""; + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelDeleteTime; + private Label labelReadTime; + private Label labelInsertTime; + private Button buttonDelete; + private Button buttonRead; + private Button buttonInsert; + private Label labelEntities3; + private Label labelEntities2; + private Label labelEntities1; + private Label labelDelete; + private Label labelRead; + private Label labelInsert; + private NumericUpDown numericUpDownDelete; + private NumericUpDown numericUpDownRead; + private NumericUpDown numericUpDownInsert; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRoutesTests.cs b/RouteGuide/RouteGuideView/FormRoutesTests.cs new file mode 100644 index 0000000..bdb6826 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoutesTests.cs @@ -0,0 +1,150 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма с тестами для сущности "Маршрут" + /// + public partial class FormRoutesTests : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для маршрутов + /// + private readonly IRouteLogic _routeLogic; + + /// + /// Бизнес-логика для транспорта + /// + private readonly ITransportLogic _transportLogic; + + /// + /// Конструктор + /// + /// + /// + /// + public FormRoutesTests(ILogger logger, IRouteLogic routeLogic, ITransportLogic transportLogic) + { + InitializeComponent(); + _logger = logger; + _routeLogic = routeLogic; + _transportLogic = transportLogic; + + numericUpDownInsert.Maximum = 1000; + numericUpDownRead.Maximum = 1000; + numericUpDownDelete.Maximum = 1000; + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonInsert_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownInsert.Value); + _logger.LogInformation("RouteInsertTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + int transportId = _transportLogic.ReadList(1)![0].Id; + for (int i = 1; i <= entitiesCount; i++) + { + var model = new RouteBindingModel + { + Id = 0, + Name = $"Маршрут {i}", + TransportId = transportId + }; + + stopwatch.Start(); + var operationResult = _routeLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Маршрут'. Дополнительная информация в логах."); + } + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelInsertTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "RouteInsertTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Получить" + /// + /// + /// + private void buttonRead_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownRead.Value); + _logger.LogInformation("RouteReadTest. Count: {Count}", entitiesCount); + try + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + _routeLogic.ReadList(entitiesCount); + stopwatch.Stop(); + labelReadTime.Text = $"{stopwatch.ElapsedMilliseconds} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "RouteReadTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownDelete.Value); + _logger.LogInformation("RouteDeleteTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + stopwatch.Start(); + _routeLogic.Delete(); + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelDeleteTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "RouteDeleteTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormRoutesTests.resx b/RouteGuide/RouteGuideView/FormRoutesTests.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoutesTests.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormSchedule.Designer.cs b/RouteGuide/RouteGuideView/FormSchedule.Designer.cs index 419ea18..7285df4 100644 --- a/RouteGuide/RouteGuideView/FormSchedule.Designer.cs +++ b/RouteGuide/RouteGuideView/FormSchedule.Designer.cs @@ -44,42 +44,42 @@ // // dateTimePickerDate // - dateTimePickerDate.Location = new Point(101, 41); + dateTimePickerDate.Location = new Point(113, 41); dateTimePickerDate.Name = "dateTimePickerDate"; - dateTimePickerDate.Size = new Size(271, 23); + dateTimePickerDate.Size = new Size(259, 23); dateTimePickerDate.TabIndex = 0; // // dateTimePickerDepartureTime // dateTimePickerDepartureTime.Format = DateTimePickerFormat.Time; - dateTimePickerDepartureTime.Location = new Point(101, 70); + dateTimePickerDepartureTime.Location = new Point(113, 70); dateTimePickerDepartureTime.Name = "dateTimePickerDepartureTime"; - dateTimePickerDepartureTime.Size = new Size(271, 23); + dateTimePickerDepartureTime.Size = new Size(259, 23); dateTimePickerDepartureTime.TabIndex = 1; // // dateTimePickerArrivalTime // dateTimePickerArrivalTime.Format = DateTimePickerFormat.Time; - dateTimePickerArrivalTime.Location = new Point(101, 99); + dateTimePickerArrivalTime.Location = new Point(113, 99); dateTimePickerArrivalTime.Name = "dateTimePickerArrivalTime"; - dateTimePickerArrivalTime.Size = new Size(271, 23); + dateTimePickerArrivalTime.Size = new Size(259, 23); dateTimePickerArrivalTime.TabIndex = 2; // // dateTimePickerFrequency // dateTimePickerFrequency.Format = DateTimePickerFormat.Time; - dateTimePickerFrequency.Location = new Point(101, 128); + dateTimePickerFrequency.Location = new Point(113, 128); dateTimePickerFrequency.Name = "dateTimePickerFrequency"; - dateTimePickerFrequency.Size = new Size(271, 23); + dateTimePickerFrequency.Size = new Size(259, 23); dateTimePickerFrequency.TabIndex = 3; // // comboBoxRoute // comboBoxRoute.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxRoute.FormattingEnabled = true; - comboBoxRoute.Location = new Point(101, 12); + comboBoxRoute.Location = new Point(113, 12); comboBoxRoute.Name = "comboBoxRoute"; - comboBoxRoute.Size = new Size(271, 23); + comboBoxRoute.Size = new Size(259, 23); comboBoxRoute.TabIndex = 4; // // buttonSave diff --git a/RouteGuide/RouteGuideView/FormSchedulesTests.Designer.cs b/RouteGuide/RouteGuideView/FormSchedulesTests.Designer.cs new file mode 100644 index 0000000..630e89d --- /dev/null +++ b/RouteGuide/RouteGuideView/FormSchedulesTests.Designer.cs @@ -0,0 +1,230 @@ +namespace RouteGuideView +{ + partial class FormSchedulesTests + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelDeleteTime = new Label(); + labelReadTime = new Label(); + labelInsertTime = new Label(); + buttonDelete = new Button(); + buttonRead = new Button(); + buttonInsert = new Button(); + labelEntities3 = new Label(); + labelEntities2 = new Label(); + labelEntities1 = new Label(); + labelDelete = new Label(); + labelRead = new Label(); + labelInsert = new Label(); + numericUpDownDelete = new NumericUpDown(); + numericUpDownRead = new NumericUpDown(); + numericUpDownInsert = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).BeginInit(); + SuspendLayout(); + // + // labelDeleteTime + // + labelDeleteTime.AutoSize = true; + labelDeleteTime.Location = new Point(376, 72); + labelDeleteTime.Name = "labelDeleteTime"; + labelDeleteTime.Size = new Size(32, 15); + labelDeleteTime.TabIndex = 59; + labelDeleteTime.Text = "0 ms"; + // + // labelReadTime + // + labelReadTime.AutoSize = true; + labelReadTime.Location = new Point(376, 43); + labelReadTime.Name = "labelReadTime"; + labelReadTime.Size = new Size(32, 15); + labelReadTime.TabIndex = 58; + labelReadTime.Text = "0 ms"; + // + // labelInsertTime + // + labelInsertTime.AutoSize = true; + labelInsertTime.Location = new Point(376, 14); + labelInsertTime.Name = "labelInsertTime"; + labelInsertTime.Size = new Size(32, 15); + labelInsertTime.TabIndex = 57; + labelInsertTime.Text = "0 ms"; + // + // buttonDelete + // + buttonDelete.Location = new Point(264, 68); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 56; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRead + // + buttonRead.Location = new Point(264, 39); + buttonRead.Name = "buttonRead"; + buttonRead.Size = new Size(75, 23); + buttonRead.TabIndex = 55; + buttonRead.Text = "Получить"; + buttonRead.UseVisualStyleBackColor = true; + buttonRead.Click += buttonRead_Click; + // + // buttonInsert + // + buttonInsert.Location = new Point(264, 10); + buttonInsert.Name = "buttonInsert"; + buttonInsert.Size = new Size(75, 23); + buttonInsert.TabIndex = 54; + buttonInsert.Text = "Создать"; + buttonInsert.UseVisualStyleBackColor = true; + buttonInsert.Click += buttonInsert_Click; + // + // labelEntities3 + // + labelEntities3.AutoSize = true; + labelEntities3.Location = new Point(159, 70); + labelEntities3.Name = "labelEntities3"; + labelEntities3.Size = new Size(68, 15); + labelEntities3.TabIndex = 53; + labelEntities3.Text = "сущностей"; + // + // labelEntities2 + // + labelEntities2.AutoSize = true; + labelEntities2.Location = new Point(159, 41); + labelEntities2.Name = "labelEntities2"; + labelEntities2.Size = new Size(68, 15); + labelEntities2.TabIndex = 52; + labelEntities2.Text = "сущностей"; + // + // labelEntities1 + // + labelEntities1.AutoSize = true; + labelEntities1.Location = new Point(159, 12); + labelEntities1.Name = "labelEntities1"; + labelEntities1.Size = new Size(68, 15); + labelEntities1.TabIndex = 51; + labelEntities1.Text = "сущностей"; + // + // labelDelete + // + labelDelete.AutoSize = true; + labelDelete.Location = new Point(16, 70); + labelDelete.Name = "labelDelete"; + labelDelete.Size = new Size(51, 15); + labelDelete.TabIndex = 50; + labelDelete.Text = "Удалить"; + // + // labelRead + // + labelRead.AutoSize = true; + labelRead.Location = new Point(16, 41); + labelRead.Name = "labelRead"; + labelRead.Size = new Size(61, 15); + labelRead.TabIndex = 49; + labelRead.Text = "Получить"; + // + // labelInsert + // + labelInsert.AutoSize = true; + labelInsert.Location = new Point(16, 12); + labelInsert.Name = "labelInsert"; + labelInsert.Size = new Size(50, 15); + labelInsert.TabIndex = 48; + labelInsert.Text = "Создать"; + // + // numericUpDownDelete + // + numericUpDownDelete.Location = new Point(83, 68); + numericUpDownDelete.Name = "numericUpDownDelete"; + numericUpDownDelete.Size = new Size(70, 23); + numericUpDownDelete.TabIndex = 47; + // + // numericUpDownRead + // + numericUpDownRead.Location = new Point(83, 39); + numericUpDownRead.Name = "numericUpDownRead"; + numericUpDownRead.Size = new Size(70, 23); + numericUpDownRead.TabIndex = 46; + // + // numericUpDownInsert + // + numericUpDownInsert.Location = new Point(83, 10); + numericUpDownInsert.Name = "numericUpDownInsert"; + numericUpDownInsert.Size = new Size(70, 23); + numericUpDownInsert.TabIndex = 45; + // + // FormSchedulesTests + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 101); + Controls.Add(labelDeleteTime); + Controls.Add(labelReadTime); + Controls.Add(labelInsertTime); + Controls.Add(buttonDelete); + Controls.Add(buttonRead); + Controls.Add(buttonInsert); + Controls.Add(labelEntities3); + Controls.Add(labelEntities2); + Controls.Add(labelEntities1); + Controls.Add(labelDelete); + Controls.Add(labelRead); + Controls.Add(labelInsert); + Controls.Add(numericUpDownDelete); + Controls.Add(numericUpDownRead); + Controls.Add(numericUpDownInsert); + Name = "FormSchedulesTests"; + Text = "Тесты для сущности \"Расписание\""; + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelDeleteTime; + private Label labelReadTime; + private Label labelInsertTime; + private Button buttonDelete; + private Button buttonRead; + private Button buttonInsert; + private Label labelEntities3; + private Label labelEntities2; + private Label labelEntities1; + private Label labelDelete; + private Label labelRead; + private Label labelInsert; + private NumericUpDown numericUpDownDelete; + private NumericUpDown numericUpDownRead; + private NumericUpDown numericUpDownInsert; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormSchedulesTests.cs b/RouteGuide/RouteGuideView/FormSchedulesTests.cs new file mode 100644 index 0000000..29fbfb8 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormSchedulesTests.cs @@ -0,0 +1,153 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма с тестами для сущности "Расписание" + /// + public partial class FormSchedulesTests : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для расписания + /// + private readonly IScheduleLogic _scheduleLogic; + + /// + /// Бизнес-логика для маршрутов + /// + private readonly IRouteLogic _routeLogic; + + /// + /// Конструктор + /// + /// + /// + /// + public FormSchedulesTests(ILogger logger, IScheduleLogic scheduleLogic, IRouteLogic routeLogic) + { + InitializeComponent(); + _logger = logger; + _scheduleLogic = scheduleLogic; + _routeLogic = routeLogic; + + numericUpDownInsert.Maximum = 1000; + numericUpDownRead.Maximum = 1000; + numericUpDownDelete.Maximum = 1000; + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonInsert_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownInsert.Value); + _logger.LogInformation("ScheduleInsertTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + int routeId = _routeLogic.ReadList(1)![0].Id; + for (int i = 1; i <= entitiesCount; i++) + { + var model = new ScheduleBindingModel + { + Id = 0, + Date = DateTime.Now, + DepartureTime = DateTime.MinValue, + ArrivalTime = DateTime.MaxValue, + Frequency = DateTime.MinValue, + RouteId = routeId + }; + + stopwatch.Start(); + var operationResult = _scheduleLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Расписание'. Дополнительная информация в логах."); + } + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelInsertTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "ScheduleInsertTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Получить" + /// + /// + /// + private void buttonRead_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownRead.Value); + _logger.LogInformation("ScheduleReadTest. Count: {Count}", entitiesCount); + try + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + _scheduleLogic.ReadList(entitiesCount); + stopwatch.Stop(); + labelReadTime.Text = $"{stopwatch.ElapsedMilliseconds} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "ScheduleReadTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownDelete.Value); + _logger.LogInformation("ScheduleDeleteTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + stopwatch.Start(); + _scheduleLogic.Delete(); + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelDeleteTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "ScheduleDeleteTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormSchedulesTests.resx b/RouteGuide/RouteGuideView/FormSchedulesTests.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormSchedulesTests.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormStopsTests.Designer.cs b/RouteGuide/RouteGuideView/FormStopsTests.Designer.cs new file mode 100644 index 0000000..e29fcc6 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStopsTests.Designer.cs @@ -0,0 +1,230 @@ +namespace RouteGuideView +{ + partial class FormStopsTests + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelDeleteTime = new Label(); + labelReadTime = new Label(); + labelInsertTime = new Label(); + buttonDelete = new Button(); + buttonRead = new Button(); + buttonInsert = new Button(); + labelEntities3 = new Label(); + labelEntities2 = new Label(); + labelEntities1 = new Label(); + labelDelete = new Label(); + labelRead = new Label(); + labelInsert = new Label(); + numericUpDownDelete = new NumericUpDown(); + numericUpDownRead = new NumericUpDown(); + numericUpDownInsert = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).BeginInit(); + SuspendLayout(); + // + // labelDeleteTime + // + labelDeleteTime.AutoSize = true; + labelDeleteTime.Location = new Point(376, 72); + labelDeleteTime.Name = "labelDeleteTime"; + labelDeleteTime.Size = new Size(32, 15); + labelDeleteTime.TabIndex = 29; + labelDeleteTime.Text = "0 ms"; + // + // labelReadTime + // + labelReadTime.AutoSize = true; + labelReadTime.Location = new Point(376, 43); + labelReadTime.Name = "labelReadTime"; + labelReadTime.Size = new Size(32, 15); + labelReadTime.TabIndex = 28; + labelReadTime.Text = "0 ms"; + // + // labelInsertTime + // + labelInsertTime.AutoSize = true; + labelInsertTime.Location = new Point(376, 14); + labelInsertTime.Name = "labelInsertTime"; + labelInsertTime.Size = new Size(32, 15); + labelInsertTime.TabIndex = 27; + labelInsertTime.Text = "0 ms"; + // + // buttonDelete + // + buttonDelete.Location = new Point(264, 68); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 26; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRead + // + buttonRead.Location = new Point(264, 39); + buttonRead.Name = "buttonRead"; + buttonRead.Size = new Size(75, 23); + buttonRead.TabIndex = 25; + buttonRead.Text = "Получить"; + buttonRead.UseVisualStyleBackColor = true; + buttonRead.Click += buttonRead_Click; + // + // buttonInsert + // + buttonInsert.Location = new Point(264, 10); + buttonInsert.Name = "buttonInsert"; + buttonInsert.Size = new Size(75, 23); + buttonInsert.TabIndex = 24; + buttonInsert.Text = "Создать"; + buttonInsert.UseVisualStyleBackColor = true; + buttonInsert.Click += buttonInsert_Click; + // + // labelEntities3 + // + labelEntities3.AutoSize = true; + labelEntities3.Location = new Point(159, 70); + labelEntities3.Name = "labelEntities3"; + labelEntities3.Size = new Size(68, 15); + labelEntities3.TabIndex = 23; + labelEntities3.Text = "сущностей"; + // + // labelEntities2 + // + labelEntities2.AutoSize = true; + labelEntities2.Location = new Point(159, 41); + labelEntities2.Name = "labelEntities2"; + labelEntities2.Size = new Size(68, 15); + labelEntities2.TabIndex = 22; + labelEntities2.Text = "сущностей"; + // + // labelEntities1 + // + labelEntities1.AutoSize = true; + labelEntities1.Location = new Point(159, 12); + labelEntities1.Name = "labelEntities1"; + labelEntities1.Size = new Size(68, 15); + labelEntities1.TabIndex = 21; + labelEntities1.Text = "сущностей"; + // + // labelDelete + // + labelDelete.AutoSize = true; + labelDelete.Location = new Point(16, 70); + labelDelete.Name = "labelDelete"; + labelDelete.Size = new Size(51, 15); + labelDelete.TabIndex = 20; + labelDelete.Text = "Удалить"; + // + // labelRead + // + labelRead.AutoSize = true; + labelRead.Location = new Point(16, 41); + labelRead.Name = "labelRead"; + labelRead.Size = new Size(61, 15); + labelRead.TabIndex = 19; + labelRead.Text = "Получить"; + // + // labelInsert + // + labelInsert.AutoSize = true; + labelInsert.Location = new Point(16, 12); + labelInsert.Name = "labelInsert"; + labelInsert.Size = new Size(50, 15); + labelInsert.TabIndex = 18; + labelInsert.Text = "Создать"; + // + // numericUpDownDelete + // + numericUpDownDelete.Location = new Point(83, 68); + numericUpDownDelete.Name = "numericUpDownDelete"; + numericUpDownDelete.Size = new Size(70, 23); + numericUpDownDelete.TabIndex = 17; + // + // numericUpDownRead + // + numericUpDownRead.Location = new Point(83, 39); + numericUpDownRead.Name = "numericUpDownRead"; + numericUpDownRead.Size = new Size(70, 23); + numericUpDownRead.TabIndex = 16; + // + // numericUpDownInsert + // + numericUpDownInsert.Location = new Point(83, 10); + numericUpDownInsert.Name = "numericUpDownInsert"; + numericUpDownInsert.Size = new Size(70, 23); + numericUpDownInsert.TabIndex = 15; + // + // FormStopsTests + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 101); + Controls.Add(labelDeleteTime); + Controls.Add(labelReadTime); + Controls.Add(labelInsertTime); + Controls.Add(buttonDelete); + Controls.Add(buttonRead); + Controls.Add(buttonInsert); + Controls.Add(labelEntities3); + Controls.Add(labelEntities2); + Controls.Add(labelEntities1); + Controls.Add(labelDelete); + Controls.Add(labelRead); + Controls.Add(labelInsert); + Controls.Add(numericUpDownDelete); + Controls.Add(numericUpDownRead); + Controls.Add(numericUpDownInsert); + Name = "FormStopsTests"; + Text = "Тесты для сущности \"Остановка\""; + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelDeleteTime; + private Label labelReadTime; + private Label labelInsertTime; + private Button buttonDelete; + private Button buttonRead; + private Button buttonInsert; + private Label labelEntities3; + private Label labelEntities2; + private Label labelEntities1; + private Label labelDelete; + private Label labelRead; + private Label labelInsert; + private NumericUpDown numericUpDownDelete; + private NumericUpDown numericUpDownRead; + private NumericUpDown numericUpDownInsert; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormStopsTests.cs b/RouteGuide/RouteGuideView/FormStopsTests.cs new file mode 100644 index 0000000..ccd8f40 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStopsTests.cs @@ -0,0 +1,143 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма с тестами для сущности "Остановка" + /// + public partial class FormStopsTests : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IStopLogic _stopLogic; + + /// + /// Конструктор + /// + /// + /// + public FormStopsTests(ILogger logger, IStopLogic stopLogic) + { + InitializeComponent(); + _logger = logger; + _stopLogic = stopLogic; + + numericUpDownInsert.Maximum = 1000; + numericUpDownRead.Maximum = 1000; + numericUpDownDelete.Maximum = 1000; + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonInsert_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownInsert.Value); + _logger.LogInformation("StopInsertTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + var model = new StopBindingModel + { + Id = 0, + Name = $"Остановка {i}", + Street = $"Улица {i}", + Number = i + }; + + stopwatch.Start(); + var operationResult = _stopLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Остановка'. Дополнительная информация в логах."); + } + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelInsertTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "StopInsertTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Получить" + /// + /// + /// + private void buttonRead_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownRead.Value); + _logger.LogInformation("StopReadTest. Count: {Count}", entitiesCount); + try + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + _stopLogic.ReadList(entitiesCount); + stopwatch.Stop(); + labelReadTime.Text = $"{stopwatch.ElapsedMilliseconds} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "StopReadTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownDelete.Value); + _logger.LogInformation("StopDeleteTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + stopwatch.Start(); + _stopLogic.Delete(); + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelDeleteTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "StopDeleteTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormStopsTests.resx b/RouteGuide/RouteGuideView/FormStopsTests.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStopsTests.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormTransportTests.Designer.cs b/RouteGuide/RouteGuideView/FormTransportTests.Designer.cs new file mode 100644 index 0000000..0f3d8ab --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransportTests.Designer.cs @@ -0,0 +1,230 @@ +namespace RouteGuideView +{ + partial class FormTransportTests + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelDeleteTime = new Label(); + labelReadTime = new Label(); + labelInsertTime = new Label(); + buttonDelete = new Button(); + buttonRead = new Button(); + buttonInsert = new Button(); + labelEntities3 = new Label(); + labelEntities2 = new Label(); + labelEntities1 = new Label(); + labelDelete = new Label(); + labelRead = new Label(); + labelInsert = new Label(); + numericUpDownDelete = new NumericUpDown(); + numericUpDownRead = new NumericUpDown(); + numericUpDownInsert = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).BeginInit(); + SuspendLayout(); + // + // labelDeleteTime + // + labelDeleteTime.AutoSize = true; + labelDeleteTime.Location = new Point(376, 72); + labelDeleteTime.Name = "labelDeleteTime"; + labelDeleteTime.Size = new Size(32, 15); + labelDeleteTime.TabIndex = 29; + labelDeleteTime.Text = "0 ms"; + // + // labelReadTime + // + labelReadTime.AutoSize = true; + labelReadTime.Location = new Point(376, 43); + labelReadTime.Name = "labelReadTime"; + labelReadTime.Size = new Size(32, 15); + labelReadTime.TabIndex = 28; + labelReadTime.Text = "0 ms"; + // + // labelInsertTime + // + labelInsertTime.AutoSize = true; + labelInsertTime.Location = new Point(376, 14); + labelInsertTime.Name = "labelInsertTime"; + labelInsertTime.Size = new Size(32, 15); + labelInsertTime.TabIndex = 27; + labelInsertTime.Text = "0 ms"; + // + // buttonDelete + // + buttonDelete.Location = new Point(264, 68); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 26; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRead + // + buttonRead.Location = new Point(264, 39); + buttonRead.Name = "buttonRead"; + buttonRead.Size = new Size(75, 23); + buttonRead.TabIndex = 25; + buttonRead.Text = "Получить"; + buttonRead.UseVisualStyleBackColor = true; + buttonRead.Click += buttonRead_Click; + // + // buttonInsert + // + buttonInsert.Location = new Point(264, 10); + buttonInsert.Name = "buttonInsert"; + buttonInsert.Size = new Size(75, 23); + buttonInsert.TabIndex = 24; + buttonInsert.Text = "Создать"; + buttonInsert.UseVisualStyleBackColor = true; + buttonInsert.Click += buttonInsert_Click; + // + // labelEntities3 + // + labelEntities3.AutoSize = true; + labelEntities3.Location = new Point(159, 70); + labelEntities3.Name = "labelEntities3"; + labelEntities3.Size = new Size(68, 15); + labelEntities3.TabIndex = 23; + labelEntities3.Text = "сущностей"; + // + // labelEntities2 + // + labelEntities2.AutoSize = true; + labelEntities2.Location = new Point(159, 41); + labelEntities2.Name = "labelEntities2"; + labelEntities2.Size = new Size(68, 15); + labelEntities2.TabIndex = 22; + labelEntities2.Text = "сущностей"; + // + // labelEntities1 + // + labelEntities1.AutoSize = true; + labelEntities1.Location = new Point(159, 12); + labelEntities1.Name = "labelEntities1"; + labelEntities1.Size = new Size(68, 15); + labelEntities1.TabIndex = 21; + labelEntities1.Text = "сущностей"; + // + // labelDelete + // + labelDelete.AutoSize = true; + labelDelete.Location = new Point(16, 70); + labelDelete.Name = "labelDelete"; + labelDelete.Size = new Size(51, 15); + labelDelete.TabIndex = 20; + labelDelete.Text = "Удалить"; + // + // labelRead + // + labelRead.AutoSize = true; + labelRead.Location = new Point(16, 41); + labelRead.Name = "labelRead"; + labelRead.Size = new Size(61, 15); + labelRead.TabIndex = 19; + labelRead.Text = "Получить"; + // + // labelInsert + // + labelInsert.AutoSize = true; + labelInsert.Location = new Point(16, 12); + labelInsert.Name = "labelInsert"; + labelInsert.Size = new Size(50, 15); + labelInsert.TabIndex = 18; + labelInsert.Text = "Создать"; + // + // numericUpDownDelete + // + numericUpDownDelete.Location = new Point(83, 68); + numericUpDownDelete.Name = "numericUpDownDelete"; + numericUpDownDelete.Size = new Size(70, 23); + numericUpDownDelete.TabIndex = 17; + // + // numericUpDownRead + // + numericUpDownRead.Location = new Point(83, 39); + numericUpDownRead.Name = "numericUpDownRead"; + numericUpDownRead.Size = new Size(70, 23); + numericUpDownRead.TabIndex = 16; + // + // numericUpDownInsert + // + numericUpDownInsert.Location = new Point(83, 10); + numericUpDownInsert.Name = "numericUpDownInsert"; + numericUpDownInsert.Size = new Size(70, 23); + numericUpDownInsert.TabIndex = 15; + // + // FormTransportTests + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 101); + Controls.Add(labelDeleteTime); + Controls.Add(labelReadTime); + Controls.Add(labelInsertTime); + Controls.Add(buttonDelete); + Controls.Add(buttonRead); + Controls.Add(buttonInsert); + Controls.Add(labelEntities3); + Controls.Add(labelEntities2); + Controls.Add(labelEntities1); + Controls.Add(labelDelete); + Controls.Add(labelRead); + Controls.Add(labelInsert); + Controls.Add(numericUpDownDelete); + Controls.Add(numericUpDownRead); + Controls.Add(numericUpDownInsert); + Name = "FormTransportTests"; + Text = "Тесты для сущности \"Транспорт\""; + ((System.ComponentModel.ISupportInitialize)numericUpDownDelete).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRead).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownInsert).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelDeleteTime; + private Label labelReadTime; + private Label labelInsertTime; + private Button buttonDelete; + private Button buttonRead; + private Button buttonInsert; + private Label labelEntities3; + private Label labelEntities2; + private Label labelEntities1; + private Label labelDelete; + private Label labelRead; + private Label labelInsert; + private NumericUpDown numericUpDownDelete; + private NumericUpDown numericUpDownRead; + private NumericUpDown numericUpDownInsert; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormTransportTests.cs b/RouteGuide/RouteGuideView/FormTransportTests.cs new file mode 100644 index 0000000..1df8fa9 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransportTests.cs @@ -0,0 +1,152 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideDataModels.Enums; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма с тестами для сущности "Транспорт" + /// + public partial class FormTransportTests : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для транспорта + /// + private readonly ITransportLogic _transportLogic; + + /// + /// Бизнес-логика для водителей + /// + private readonly IDriverLogic _driverLogic; + + /// + /// Конструктор + /// + /// + /// + /// + public FormTransportTests(ILogger logger, ITransportLogic transportLogic, IDriverLogic driverLogic) + { + InitializeComponent(); + _logger = logger; + _transportLogic = transportLogic; + _driverLogic = driverLogic; + + numericUpDownInsert.Maximum = 1000; + numericUpDownRead.Maximum = 1000; + numericUpDownDelete.Maximum = 1000; + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonInsert_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownInsert.Value); + _logger.LogInformation("TransportInsertTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + int driverId = _driverLogic.ReadList(1)![0].Id; + for (int i = 1; i <= entitiesCount; i++) + { + var model = new TransportBindingModel + { + Id = 0, + License = i.ToString(), + Type = TransportType.Маршрутка, + Capacity = i, + DriverId = driverId + }; + + stopwatch.Start(); + var operationResult = _transportLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Транспорт'. Дополнительная информация в логах."); + } + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelInsertTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "TransportInsertTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Получить" + /// + /// + /// + private void buttonRead_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownRead.Value); + _logger.LogInformation("TransportReadTest. Count: {Count}", entitiesCount); + try + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + _transportLogic.ReadList(entitiesCount); + stopwatch.Stop(); + labelReadTime.Text = $"{stopwatch.ElapsedMilliseconds} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "TransportReadTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + int entitiesCount = Convert.ToInt32(numericUpDownDelete.Value); + _logger.LogInformation("TransportDeleteTest. Count: {Count}", entitiesCount); + try + { + double time = 0; + var stopwatch = new Stopwatch(); + for (int i = 1; i <= entitiesCount; i++) + { + stopwatch.Start(); + _transportLogic.Delete(); + stopwatch.Stop(); + time += stopwatch.ElapsedMilliseconds; + } + labelDeleteTime.Text = $"{Convert.ToInt32(time / entitiesCount)} ms"; + } + catch (Exception ex) + { + _logger.LogError(ex, "TransportDeleteTest. Test failed"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormTransportTests.resx b/RouteGuide/RouteGuideView/FormTransportTests.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransportTests.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/Program.cs b/RouteGuide/RouteGuideView/Program.cs index 9b96d03..d387d6c 100644 --- a/RouteGuide/RouteGuideView/Program.cs +++ b/RouteGuide/RouteGuideView/Program.cs @@ -60,7 +60,7 @@ namespace RouteGuideView services.AddTransient(); services.AddTransient(); - // IoC-, + // IoC-, services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -72,6 +72,16 @@ namespace RouteGuideView services.AddTransient(); services.AddTransient(); services.AddTransient(); + + // IoC-, + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + // DateTime Kind=Local + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); } } } \ No newline at end of file