2024-04-09 13:48:30 +04:00
|
|
|
|
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;
|
2024-04-09 20:03:50 +04:00
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
|
2024-04-09 13:48:30 +04:00
|
|
|
|
|
|
|
|
|
namespace RouteGuideView
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма с тестами для сущности "Расписание"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormSchedulesTests : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логгер
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для расписания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IScheduleLogic _scheduleLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для маршрутов
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IRouteLogic _routeLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
/// <param name="scheduleLogic"></param>
|
|
|
|
|
/// <param name="routeLogic"></param>
|
|
|
|
|
public FormSchedulesTests(ILogger<FormSchedulesTests> logger, IScheduleLogic scheduleLogic, IRouteLogic routeLogic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_scheduleLogic = scheduleLogic;
|
|
|
|
|
_routeLogic = routeLogic;
|
|
|
|
|
|
2024-04-09 20:03:50 +04:00
|
|
|
|
numericUpDownInsert.Maximum = 10000;
|
|
|
|
|
numericUpDownRead.Maximum = 10000;
|
|
|
|
|
numericUpDownDelete.Maximum = 10000;
|
2024-04-09 13:48:30 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Кнопка "Создать"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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();
|
2024-04-23 19:38:25 +04:00
|
|
|
|
object routeId = _routeLogic.ReadList(1)![0].Id;
|
2024-04-09 13:48:30 +04:00
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-09 20:03:50 +04:00
|
|
|
|
stopwatch.Restart();
|
2024-04-09 13:48:30 +04:00
|
|
|
|
var operationResult = _scheduleLogic.Create(model);
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при сохранении сущности 'Расписание'. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
time += stopwatch.ElapsedMilliseconds;
|
|
|
|
|
}
|
2024-04-09 20:03:50 +04:00
|
|
|
|
labelInsertTime.Text = $"Total time: {Convert.ToInt32(time)} ms / Average time: {Convert.ToInt32(time / entitiesCount)} ms";
|
2024-04-09 13:48:30 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "ScheduleInsertTest. Test failed");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Кнопка "Получить"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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();
|
2024-04-09 20:03:50 +04:00
|
|
|
|
labelReadTime.Text = $"Total time: {Convert.ToInt32(stopwatch.ElapsedMilliseconds)} ms / Average time: {Convert.ToInt32(stopwatch.ElapsedMilliseconds / entitiesCount)} ms";
|
2024-04-09 13:48:30 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "ScheduleReadTest. Test failed");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Кнопка "Удалить"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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++)
|
|
|
|
|
{
|
2024-04-09 20:03:50 +04:00
|
|
|
|
stopwatch.Restart();
|
2024-04-09 13:48:30 +04:00
|
|
|
|
_scheduleLogic.Delete();
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
time += stopwatch.ElapsedMilliseconds;
|
|
|
|
|
}
|
2024-04-09 20:03:50 +04:00
|
|
|
|
labelDeleteTime.Text = $"Total time: {Convert.ToInt32(time)} ms / Average time: {Convert.ToInt32(time / entitiesCount)} ms";
|
2024-04-09 13:48:30 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "ScheduleDeleteTest. Test failed");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|