Добавлены тесты.

This commit is contained in:
Anastasia 2023-05-18 23:07:48 +04:00
parent 269eeaea99
commit 9fed8d43c4
10 changed files with 394 additions and 2 deletions

View File

@ -33,6 +33,7 @@
this.транспортToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.остановкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.маршрутыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
@ -43,7 +44,8 @@
this.типыТранспортаToolStripMenuItem,
this.транспортToolStripMenuItem,
this.остановкиToolStripMenuItem,
this.маршрутыToolStripMenuItem});
this.маршрутыToolStripMenuItem,
this.тестыToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(800, 33);
@ -78,6 +80,13 @@
this.маршрутыToolStripMenuItem.Text = "Маршруты";
this.маршрутыToolStripMenuItem.Click += new System.EventHandler(this.МаршрутыToolStripMenuItem_Click);
//
// тестыToolStripMenuItem
//
this.тестыToolStripMenuItem.Name = естыToolStripMenuItem";
this.тестыToolStripMenuItem.Size = new System.Drawing.Size(74, 29);
this.тестыToolStripMenuItem.Text = "Тесты";
this.тестыToolStripMenuItem.Click += new System.EventHandler(this.ТестыToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
@ -101,5 +110,6 @@
private ToolStripMenuItem транспортToolStripMenuItem;
private ToolStripMenuItem остановкиToolStripMenuItem;
private ToolStripMenuItem маршрутыToolStripMenuItem;
private ToolStripMenuItem тестыToolStripMenuItem;
}
}

View File

@ -51,5 +51,15 @@ namespace RouteGuide
form.ShowDialog();
}
}
private void ÒåñòûToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormTests));
if (service is FormTests form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,166 @@
namespace RouteGuide
{
partial class FormTests
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown();
this.numericUpDownRead = new System.Windows.Forms.NumericUpDown();
this.textBoxInsertTime = new System.Windows.Forms.TextBox();
this.buttonInsertTest = new System.Windows.Forms.Button();
this.buttonReadTest = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.textBoxReadTime = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(165, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Кол-во элементов:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 67);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(139, 25);
this.label2.TabIndex = 1;
this.label2.Text = "Время запроса:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(321, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(165, 25);
this.label3.TabIndex = 2;
this.label3.Text = "Кол-во элементов:";
//
// numericUpDownInsert
//
this.numericUpDownInsert.Location = new System.Drawing.Point(183, 7);
this.numericUpDownInsert.Name = "numericUpDownInsert";
this.numericUpDownInsert.Size = new System.Drawing.Size(119, 31);
this.numericUpDownInsert.TabIndex = 6;
//
// numericUpDownRead
//
this.numericUpDownRead.Location = new System.Drawing.Point(492, 7);
this.numericUpDownRead.Name = "numericUpDownRead";
this.numericUpDownRead.Size = new System.Drawing.Size(119, 31);
this.numericUpDownRead.TabIndex = 7;
//
// textBoxInsertTime
//
this.textBoxInsertTime.Location = new System.Drawing.Point(183, 64);
this.textBoxInsertTime.Name = "textBoxInsertTime";
this.textBoxInsertTime.Size = new System.Drawing.Size(119, 31);
this.textBoxInsertTime.TabIndex = 10;
//
// buttonInsertTest
//
this.buttonInsertTest.Location = new System.Drawing.Point(96, 127);
this.buttonInsertTest.Name = "buttonInsertTest";
this.buttonInsertTest.Size = new System.Drawing.Size(112, 34);
this.buttonInsertTest.TabIndex = 12;
this.buttonInsertTest.Text = "INSERT";
this.buttonInsertTest.UseVisualStyleBackColor = true;
this.buttonInsertTest.Click += new System.EventHandler(this.ButtonInsertTest_Click);
//
// buttonReadTest
//
this.buttonReadTest.Location = new System.Drawing.Point(422, 127);
this.buttonReadTest.Name = "buttonReadTest";
this.buttonReadTest.Size = new System.Drawing.Size(112, 34);
this.buttonReadTest.TabIndex = 13;
this.buttonReadTest.Text = "READ";
this.buttonReadTest.UseVisualStyleBackColor = true;
this.buttonReadTest.Click += new System.EventHandler(this.ButtonReadTest_Click);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(321, 67);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(139, 25);
this.label7.TabIndex = 15;
this.label7.Text = "Время запроса:";
//
// textBoxReadTime
//
this.textBoxReadTime.Location = new System.Drawing.Point(492, 64);
this.textBoxReadTime.Name = "textBoxReadTime";
this.textBoxReadTime.Size = new System.Drawing.Size(119, 31);
this.textBoxReadTime.TabIndex = 16;
//
// FormTests
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(626, 187);
this.Controls.Add(this.textBoxReadTime);
this.Controls.Add(this.label7);
this.Controls.Add(this.buttonReadTest);
this.Controls.Add(this.buttonInsertTest);
this.Controls.Add(this.textBoxInsertTime);
this.Controls.Add(this.numericUpDownRead);
this.Controls.Add(this.numericUpDownInsert);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FormTests";
this.Text = "Тесты";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private NumericUpDown numericUpDownInsert;
private NumericUpDown numericUpDownRead;
private TextBox textBoxInsertTime;
private Button buttonInsertTest;
private Button buttonReadTest;
private Label label7;
private TextBox textBoxReadTime;
}
}

View File

@ -0,0 +1,57 @@
using RouteGuideContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RouteGuide
{
public partial class FormTests : Form
{
private readonly IRouteLogic _routeLogic;
public FormTests(IRouteLogic routeLogic)
{
InitializeComponent();
_routeLogic = routeLogic;
numericUpDownInsert.Minimum = 0;
numericUpDownInsert.Maximum = 1000;
numericUpDownRead.Minimum = 0;
numericUpDownRead.Maximum = 1000;
}
private void ButtonInsertTest_Click(object sender, EventArgs e)
{
try
{
var result = _routeLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value));
textBoxInsertTime.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonReadTest_Click(object sender, EventArgs e)
{
try
{
var result = _routeLogic.TestReadList(Convert.ToInt32(numericUpDownRead.Value));
textBoxReadTime.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -54,7 +54,7 @@ namespace RouteGuide
services.AddTransient<FormRoutes>();
services.AddTransient<FormRoute>();
services.AddTransient<FormRouteStop>();
//services.AddTransient<FormTests>();
services.AddTransient<FormTests>();
}
}

View File

@ -110,5 +110,15 @@ namespace RouteGuideBusinessLogic.BusinessLogic
throw new InvalidOperationException("Route с таким названием уже есть");
}
}
public string TestInsertList(int num)
{
return _routeStorage.TestInsertList(num);
}
public string TestReadList(int num)
{
return _routeStorage.TestReadList(num);
}
}
}

View File

@ -18,5 +18,8 @@ namespace RouteGuideContracts.BusinessLogicContracts
bool Create(RouteBindingModel model);
bool Update(RouteBindingModel model);
bool Delete(RouteBindingModel model);
string TestInsertList(int num);
string TestReadList(int num);
}
}

View File

@ -20,5 +20,8 @@ namespace RouteGuideContracts.StoragesModels
RouteViewModel? Insert(RouteBindingModel model);
RouteViewModel? Update(RouteBindingModel model);
RouteViewModel? Delete(RouteBindingModel model);
string TestInsertList(int num);
string TestReadList(int num);
}
}

View File

@ -108,5 +108,78 @@ namespace RouteGuideDatabaseImplements.Implements
throw;
}
}
public string TestInsertList(int num)
{
var context = new RouteGuideDatabase();
Stopwatch stopwatch = new();
Random rnd = new Random();
long[] res = new long[num * 2];
for (int i = 0; i < num; ++i)
{
int rndId = rnd.Next();
var model = new StopBindingModel
{
Id = rndId,
Name = "Остановка " + rndId.ToString(),
};
context.Stops.Add(Stop.Create(model));
stopwatch.Start();
context.SaveChanges();
stopwatch.Stop();
res[i] = stopwatch.ElapsedMilliseconds;
}
List<StopViewModel> _stops = context.Stops.Select(x => x.GetViewModel).ToList();
for (int i = 0; i < num; ++i)
{
int rndId = rnd.Next();
var model = new RouteBindingModel
{
Id = rndId,
Name = "Maршрут №" + rndId.ToString(),
};
context.Routes.Add(Route.Create(context, model));
stopwatch.Start();
context.SaveChanges();
stopwatch.Stop();
res[i] = stopwatch.ElapsedMilliseconds;
}
long sum = 0;
for (int i = 0; i < num; i++)
{
sum += res[i];
}
int result = Convert.ToInt32(sum / num);
return result.ToString();
}
public string TestReadList(int num)
{
var context = new RouteGuideDatabase();
Stopwatch stopwatch = new();
long[] res = new long[num];
for (int i = 0; i < num; i++)
{
stopwatch.Start();
List<RouteViewModel> list = context.Routes.Include(x => x.Stops).ThenInclude(x => x.Stop).ToList().Select(x => x.GetViewModel).ToList();
stopwatch.Stop();
res[i] = stopwatch.ElapsedMilliseconds;
}
long sum = 0;
for (int i = 0; i < num; i++)
{
sum += res[i];
}
int result = Convert.ToInt32(sum / num);
return result.ToString();
}
}
}