151 lines
5.4 KiB
C#
151 lines
5.4 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Форма с тестами для сущности "Маршрут"
|
|||
|
/// </summary>
|
|||
|
public partial class FormRoutesTests : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Логгер
|
|||
|
/// </summary>
|
|||
|
private readonly ILogger _logger;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Бизнес-логика для маршрутов
|
|||
|
/// </summary>
|
|||
|
private readonly IRouteLogic _routeLogic;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Бизнес-логика для транспорта
|
|||
|
/// </summary>
|
|||
|
private readonly ITransportLogic _transportLogic;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
/// <param name="logger"></param>
|
|||
|
/// <param name="routeLogic"></param>
|
|||
|
/// <param name="transportLogic"></param>
|
|||
|
public FormRoutesTests(ILogger<FormRoutesTests> logger, IRouteLogic routeLogic, ITransportLogic transportLogic)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_routeLogic = routeLogic;
|
|||
|
_transportLogic = transportLogic;
|
|||
|
|
|||
|
numericUpDownInsert.Maximum = 1000;
|
|||
|
numericUpDownRead.Maximum = 1000;
|
|||
|
numericUpDownDelete.Maximum = 1000;
|
|||
|
}
|
|||
|
|
|||
|
/// <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("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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <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("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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <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("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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|