Добавлено автозаполнение и тесты замеров времени

This commit is contained in:
ArtemEmelyanov 2023-05-02 12:30:31 +04:00
parent 47aa318592
commit e949397d5a
22 changed files with 623 additions and 31 deletions

View File

@ -36,6 +36,7 @@
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -57,7 +58,8 @@
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ролиToolStripMenuItem,
this.пользователиToolStripMenuItem,
this.категорииToolStripMenuItem});
this.категорииToolStripMenuItem,
this.тестыToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
@ -116,6 +118,13 @@
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// тестыToolStripMenuItem
//
this.тестыToolStripMenuItem.Name = естыToolStripMenuItem";
this.тестыToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
this.тестыToolStripMenuItem.Text = "Тесты";
this.тестыToolStripMenuItem.Click += new System.EventHandler(this.тестыToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -149,5 +158,6 @@
private Button buttonCreate;
private Button buttonDelete;
private Button buttonUpdate;
private ToolStripMenuItem тестыToolStripMenuItem;
}
}

View File

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

View File

@ -31,20 +31,23 @@
this.textBoxRoleName = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAddRoles = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxRoleName
//
this.textBoxRoleName.Location = new System.Drawing.Point(12, 12);
this.textBoxRoleName.Location = new System.Drawing.Point(10, 9);
this.textBoxRoleName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxRoleName.Name = "textBoxRoleName";
this.textBoxRoleName.Size = new System.Drawing.Size(268, 27);
this.textBoxRoleName.Size = new System.Drawing.Size(218, 23);
this.textBoxRoleName.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 45);
this.buttonSave.Location = new System.Drawing.Point(10, 34);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 1;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
@ -52,22 +55,35 @@
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(186, 45);
this.buttonCancel.Location = new System.Drawing.Point(10, 63);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonAddRoles
//
this.buttonAddRoles.Location = new System.Drawing.Point(153, 34);
this.buttonAddRoles.Name = "buttonAddRoles";
this.buttonAddRoles.Size = new System.Drawing.Size(75, 54);
this.buttonAddRoles.TabIndex = 3;
this.buttonAddRoles.Text = "Добавить 1000 ролей";
this.buttonAddRoles.UseVisualStyleBackColor = true;
this.buttonAddRoles.Click += new System.EventHandler(this.buttonAddRoles_Click);
//
// FormRole
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 81);
this.ClientSize = new System.Drawing.Size(234, 96);
this.Controls.Add(this.buttonAddRoles);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxRoleName);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormRole";
this.Text = "Роль";
this.Load += new System.EventHandler(this.FormRole_Load);
@ -81,5 +97,6 @@
private TextBox textBoxRoleName;
private Button buttonSave;
private Button buttonCancel;
private Button buttonAddRoles;
}
}

View File

@ -1,6 +1,7 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.SearchModels;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -84,5 +85,18 @@ namespace Forum
}
}
}
private void buttonAddRoles_Click(object sender, EventArgs e)
{
try
{
_roleLogic.RoleInsertList(1000);
FormRole_Load(sender, e);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

229
Forum/Forum/FormTests.Designer.cs generated Normal file
View File

@ -0,0 +1,229 @@
namespace Forum
{
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.buttonInsertTest = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBoxInsertTime = new System.Windows.Forms.TextBox();
this.buttonReadTest = new System.Windows.Forms.Button();
this.textBoxReadTime = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown();
this.numericUpDownRead = new System.Windows.Forms.NumericUpDown();
this.buttonJoinQuery = new System.Windows.Forms.Button();
this.numericUpDownJoin = new System.Windows.Forms.NumericUpDown();
this.textBoxJoin = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).BeginInit();
this.SuspendLayout();
//
// buttonInsertTest
//
this.buttonInsertTest.Location = new System.Drawing.Point(12, 12);
this.buttonInsertTest.Name = "buttonInsertTest";
this.buttonInsertTest.Size = new System.Drawing.Size(86, 61);
this.buttonInsertTest.TabIndex = 0;
this.buttonInsertTest.Text = "Тест вставки сообщений";
this.buttonInsertTest.UseVisualStyleBackColor = true;
this.buttonInsertTest.Click += new System.EventHandler(this.buttonInsertTest_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(104, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(156, 15);
this.label1.TabIndex = 1;
this.label1.Text = "Введите кол-во элементов:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(104, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(146, 15);
this.label2.TabIndex = 3;
this.label2.Text = "Итоговое время запроса:";
//
// textBoxInsertTime
//
this.textBoxInsertTime.Location = new System.Drawing.Point(266, 50);
this.textBoxInsertTime.Name = "textBoxInsertTime";
this.textBoxInsertTime.ReadOnly = true;
this.textBoxInsertTime.Size = new System.Drawing.Size(100, 23);
this.textBoxInsertTime.TabIndex = 4;
//
// buttonReadTest
//
this.buttonReadTest.Location = new System.Drawing.Point(12, 106);
this.buttonReadTest.Name = "buttonReadTest";
this.buttonReadTest.Size = new System.Drawing.Size(86, 56);
this.buttonReadTest.TabIndex = 5;
this.buttonReadTest.Text = "Тест чтения сообщений";
this.buttonReadTest.UseVisualStyleBackColor = true;
this.buttonReadTest.Click += new System.EventHandler(this.buttonReadTest_Click);
//
// textBoxReadTime
//
this.textBoxReadTime.Location = new System.Drawing.Point(266, 144);
this.textBoxReadTime.Name = "textBoxReadTime";
this.textBoxReadTime.ReadOnly = true;
this.textBoxReadTime.Size = new System.Drawing.Size(100, 23);
this.textBoxReadTime.TabIndex = 9;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(104, 147);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(146, 15);
this.label3.TabIndex = 8;
this.label3.Text = "Итоговое время запроса:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(104, 106);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(156, 15);
this.label4.TabIndex = 6;
this.label4.Text = "Введите кол-во элементов:";
//
// numericUpDownInsert
//
this.numericUpDownInsert.Location = new System.Drawing.Point(266, 10);
this.numericUpDownInsert.Name = "numericUpDownInsert";
this.numericUpDownInsert.Size = new System.Drawing.Size(100, 23);
this.numericUpDownInsert.TabIndex = 10;
//
// numericUpDownRead
//
this.numericUpDownRead.Location = new System.Drawing.Point(266, 104);
this.numericUpDownRead.Name = "numericUpDownRead";
this.numericUpDownRead.Size = new System.Drawing.Size(100, 23);
this.numericUpDownRead.TabIndex = 11;
//
// buttonJoinQuery
//
this.buttonJoinQuery.Location = new System.Drawing.Point(12, 197);
this.buttonJoinQuery.Name = "buttonJoinQuery";
this.buttonJoinQuery.Size = new System.Drawing.Size(86, 74);
this.buttonJoinQuery.TabIndex = 12;
this.buttonJoinQuery.Text = "Тест сложного чтения (Join)";
this.buttonJoinQuery.UseVisualStyleBackColor = true;
this.buttonJoinQuery.Click += new System.EventHandler(this.buttonJoinQuery_Click);
//
// numericUpDownJoin
//
this.numericUpDownJoin.Location = new System.Drawing.Point(266, 195);
this.numericUpDownJoin.Name = "numericUpDownJoin";
this.numericUpDownJoin.Size = new System.Drawing.Size(100, 23);
this.numericUpDownJoin.TabIndex = 16;
//
// textBoxJoin
//
this.textBoxJoin.Location = new System.Drawing.Point(266, 235);
this.textBoxJoin.Name = "textBoxJoin";
this.textBoxJoin.ReadOnly = true;
this.textBoxJoin.Size = new System.Drawing.Size(100, 23);
this.textBoxJoin.TabIndex = 15;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(104, 238);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(146, 15);
this.label5.TabIndex = 14;
this.label5.Text = "Итоговое время запроса:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(104, 197);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(156, 15);
this.label6.TabIndex = 13;
this.label6.Text = "Введите кол-во элементов:";
//
// FormTests
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(383, 286);
this.Controls.Add(this.numericUpDownJoin);
this.Controls.Add(this.textBoxJoin);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.buttonJoinQuery);
this.Controls.Add(this.numericUpDownRead);
this.Controls.Add(this.numericUpDownInsert);
this.Controls.Add(this.textBoxReadTime);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.buttonReadTest);
this.Controls.Add(this.textBoxInsertTime);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonInsertTest);
this.Name = "FormTests";
this.Text = "Тесты запросов к бд";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonInsertTest;
private Label label1;
private Label label2;
private TextBox textBoxInsertTime;
private Button buttonReadTest;
private TextBox textBoxReadTime;
private Label label3;
private Label label4;
private NumericUpDown numericUpDownInsert;
private NumericUpDown numericUpDownRead;
private Button buttonJoinQuery;
private NumericUpDown numericUpDownJoin;
private TextBox textBoxJoin;
private Label label5;
private Label label6;
}
}

75
Forum/Forum/FormTests.cs Normal file
View File

@ -0,0 +1,75 @@
using ForumContracts.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 Forum
{
public partial class FormTests : Form
{
private readonly IMessageLogic _messageLogic;
private readonly IUserLogic _userLogic;
private readonly ITopicLogic _topicLogic;
public FormTests(IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic)
{
InitializeComponent();
_userLogic = userLogic;
_topicLogic = topicLogic;
_messageLogic = messageLogic;
numericUpDownInsert.Minimum = 0;
numericUpDownInsert.Maximum = 1000000;
numericUpDownRead.Minimum = 0;
numericUpDownRead.Maximum = 1000000;
numericUpDownJoin.Minimum = 0;
numericUpDownJoin.Maximum = 1000000;
}
private void buttonInsertTest_Click(object sender, EventArgs e)
{
try
{
var result = _messageLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value),
_userLogic.ReadList(null) ?? new(),
_topicLogic.ReadList(null) ?? new());
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 = _messageLogic.TestReadList(Convert.ToInt32(numericUpDownInsert.Value));
textBoxReadTime.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonJoinQuery_Click(object sender, EventArgs e)
{
try
{
var result = _messageLogic.TestJoinReadList(Convert.ToInt32(numericUpDownJoin.Value));
textBoxJoin.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

@ -38,61 +38,66 @@
this.buttonCancel = new System.Windows.Forms.Button();
this.comboBoxSelectRole = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.buttonAddUsers = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxUsername
//
this.textBoxUsername.Location = new System.Drawing.Point(92, 12);
this.textBoxUsername.Location = new System.Drawing.Point(80, 9);
this.textBoxUsername.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxUsername.Name = "textBoxUsername";
this.textBoxUsername.Size = new System.Drawing.Size(151, 27);
this.textBoxUsername.Size = new System.Drawing.Size(133, 23);
this.textBoxUsername.TabIndex = 0;
//
// textBoxLogin
//
this.textBoxLogin.Location = new System.Drawing.Point(92, 45);
this.textBoxLogin.Location = new System.Drawing.Point(80, 34);
this.textBoxLogin.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxLogin.Name = "textBoxLogin";
this.textBoxLogin.Size = new System.Drawing.Size(151, 27);
this.textBoxLogin.Size = new System.Drawing.Size(133, 23);
this.textBoxLogin.TabIndex = 1;
//
// textBoxPassword
//
this.textBoxPassword.Location = new System.Drawing.Point(92, 78);
this.textBoxPassword.Location = new System.Drawing.Point(80, 58);
this.textBoxPassword.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.Size = new System.Drawing.Size(151, 27);
this.textBoxPassword.Size = new System.Drawing.Size(133, 23);
this.textBoxPassword.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(11, 19);
this.label1.Location = new System.Drawing.Point(10, 14);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(75, 20);
this.label1.Size = new System.Drawing.Size(60, 15);
this.label1.TabIndex = 3;
this.label1.Text = "Username";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 52);
this.label2.Location = new System.Drawing.Point(10, 39);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(46, 20);
this.label2.Size = new System.Drawing.Size(37, 15);
this.label2.TabIndex = 4;
this.label2.Text = "Login";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(11, 85);
this.label3.Location = new System.Drawing.Point(10, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(70, 20);
this.label3.Size = new System.Drawing.Size(57, 15);
this.label3.TabIndex = 5;
this.label3.Text = "Password";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 160);
this.buttonSave.Location = new System.Drawing.Point(219, 11);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
@ -100,9 +105,10 @@
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(149, 160);
this.buttonCancel.Location = new System.Drawing.Point(219, 37);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
@ -111,25 +117,37 @@
// comboBoxSelectRole
//
this.comboBoxSelectRole.FormattingEnabled = true;
this.comboBoxSelectRole.Location = new System.Drawing.Point(92, 117);
this.comboBoxSelectRole.Location = new System.Drawing.Point(80, 88);
this.comboBoxSelectRole.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxSelectRole.Name = "comboBoxSelectRole";
this.comboBoxSelectRole.Size = new System.Drawing.Size(151, 28);
this.comboBoxSelectRole.Size = new System.Drawing.Size(133, 23);
this.comboBoxSelectRole.TabIndex = 8;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(11, 120);
this.label4.Location = new System.Drawing.Point(10, 90);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(39, 20);
this.label4.Size = new System.Drawing.Size(30, 15);
this.label4.TabIndex = 9;
this.label4.Text = "Role";
//
// buttonAddUsers
//
this.buttonAddUsers.Location = new System.Drawing.Point(219, 64);
this.buttonAddUsers.Name = "buttonAddUsers";
this.buttonAddUsers.Size = new System.Drawing.Size(82, 77);
this.buttonAddUsers.TabIndex = 10;
this.buttonAddUsers.Text = "Добавить 1000 пользователей";
this.buttonAddUsers.UseVisualStyleBackColor = true;
this.buttonAddUsers.Click += new System.EventHandler(this.buttonAddUsers_Click);
//
// FormUser
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(262, 201);
this.ClientSize = new System.Drawing.Size(310, 145);
this.Controls.Add(this.buttonAddUsers);
this.Controls.Add(this.label4);
this.Controls.Add(this.comboBoxSelectRole);
this.Controls.Add(this.buttonCancel);
@ -140,6 +158,7 @@
this.Controls.Add(this.textBoxPassword);
this.Controls.Add(this.textBoxLogin);
this.Controls.Add(this.textBoxUsername);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormUser";
this.Text = "Пользователь";
this.Load += new System.EventHandler(this.FormUser_Load);
@ -160,5 +179,6 @@
private Button buttonCancel;
private ComboBox comboBoxSelectRole;
private Label label4;
private Button buttonAddUsers;
}
}

View File

@ -122,5 +122,17 @@ namespace Forum
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAddUsers_Click(object sender, EventArgs e)
{
try
{
_userLogic.UserInsertList(1000, _roleLogic.ReadList(null));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -49,6 +49,7 @@ namespace Forum
services.AddTransient<FormAddTopics>();
services.AddTransient<FormAddTopic>();
services.AddTransient<FormCreateMessage>();
services.AddTransient<FormTests>();
}
}
}

View File

@ -64,6 +64,19 @@ namespace ForumBusinessLogic
return list;
}
public string TestInsertList(int num, List<UserViewModel> users, List<TopicViewModel> topics)
{
return _messageStorage.TestInsertList(num, users, topics);
}
public string TestReadList(int num)
{
return _messageStorage.TestReadList(num);
}
public string TestJoinReadList(int num)
{
return _messageStorage.TestJoinReadList(num);
}
public bool Update(MessageBindingModel model)
{
CheckModel(model);

View File

@ -64,6 +64,11 @@ namespace ForumBusinessLogic
return list;
}
public void RoleInsertList(int num)
{
_roleStorage.RoleInsertList(num);
}
public bool Update(RoleBindingModel model)
{
CheckModel(model);

View File

@ -73,6 +73,11 @@ namespace ForumBusinessLogic
return true;
}
public void UserInsertList(int num, List<RoleViewModel> roles)
{
_userStorage.UserInsertList(num, roles);
}
private void CheckModel(UserBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -16,5 +16,8 @@ namespace ForumContracts.BusinessLogicContracts
bool Create(MessageBindingModel model);
bool Update(MessageBindingModel model);
bool Delete(MessageBindingModel model);
public string TestInsertList(int num, List<UserViewModel> users, List<TopicViewModel> topics);
string TestReadList(int num);
string TestJoinReadList(int num);
}
}

View File

@ -16,5 +16,6 @@ namespace ForumContracts.BusinessLogicContracts
bool Create(RoleBindingModel model);
bool Update(RoleBindingModel model);
bool Delete(RoleBindingModel model);
void RoleInsertList(int num);
}
}

View File

@ -16,5 +16,6 @@ namespace ForumContracts.BusinessLogicContracts
bool Create(UserBindingModel model);
bool Update(UserBindingModel model);
bool Delete(UserBindingModel model);
void UserInsertList(int num, List<RoleViewModel> roles);
}
}

View File

@ -17,5 +17,8 @@ namespace ForumContracts.StoragesContracts
MessageViewModel? Insert(MessageBindingModel model);
MessageViewModel? Update(MessageBindingModel model);
MessageViewModel? Delete(MessageBindingModel model);
string TestInsertList(int num, List<UserViewModel> users, List<TopicViewModel> topics);
string TestReadList(int num);
string TestJoinReadList(int num);
}
}

View File

@ -17,5 +17,6 @@ namespace ForumContracts.StoragesContracts
RoleViewModel? Insert(RoleBindingModel model);
RoleViewModel? Update(RoleBindingModel model);
RoleViewModel? Delete(RoleBindingModel model);
void RoleInsertList(int num);
}
}

View File

@ -17,5 +17,6 @@ namespace ForumContracts.StoragesContracts
UserViewModel? Insert(UserBindingModel model);
UserViewModel? Update(UserBindingModel model);
UserViewModel? Delete(UserBindingModel model);
void UserInsertList(int num, List<RoleViewModel> roles);
}
}

View File

@ -6,6 +6,7 @@ using ForumDatabase.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -73,6 +74,81 @@ namespace ForumDatabase.Implements
return newMessage.GetViewModel;
}
public string TestInsertList(int num, List<UserViewModel> users, List<TopicViewModel> topics)
{
Random rnd = new Random();
using var context = new ForumDatabase();
for (int i = 0; i < num; ++i)
{
var model = new MessageBindingModel
{
Id = 0,
Text = "hello",
Date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
UserId = users[rnd.Next(users.Count)].Id,
TopicId = topics[rnd.Next(topics.Count)].Id,
};
context.Messages.Add(Message.Create(model));
}
Stopwatch stopwatch = new();
stopwatch.Start();
context.SaveChanges();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public string TestJoinReadList(int num)
{
using var context = new ForumDatabase();
Stopwatch stopwatch = new();
stopwatch.Start();
var list = context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.Join(context.Users,
r => r.UserId,
c => c.Id,
(r, c) => new { Message = r, User = c })
.Join(context.Topics,
rc => rc.Message.TopicId,
car => car.Id,
(rc, topic) => new { rc.Message, rc.User, Topic = topic })
.Select(rc => new
{
Message = rc.Message.GetViewModel,
User = rc.User.GetViewModel,
Topic = rc.Topic.GetViewModel,
})
.Take(num)
.ToList();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public string TestReadList(int num)
{
using var context = new ForumDatabase();
Stopwatch stopwatch = new();
stopwatch.Start();
List<MessageViewModel> list = context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.Take(num)
.Select(x => x.GetViewModel)
.ToList();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public MessageViewModel? Update(MessageBindingModel model)
{
using var context = new ForumDatabase();

View File

@ -13,6 +13,21 @@ namespace ForumDatabase.Implements
{
public class RoleStorage : IRoleStorage
{
public void RoleInsertList(int num)
{
Random rnd = new Random();
using var context = new ForumDatabase();
for (int i = 0; i < num; ++i)
{
var model = new RoleBindingModel
{
Id = 0,
Name = rnd.Next(1000).ToString(),
};
context.Roles.Add(Role.Create(model));
}
context.SaveChanges();
}
public RoleViewModel? Delete(RoleBindingModel model)
{
using var context = new ForumDatabase();

View File

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
@ -91,5 +92,24 @@ namespace ForumDatabase.Implements
context.SaveChanges();
return component.GetViewModel;
}
public void UserInsertList(int num, List<RoleViewModel> roles)
{
Random rnd = new Random();
using var context = new ForumDatabase();
for (int i = 0; i < num; ++i)
{
var model = new UserBindingModel
{
Id = 0,
Username = rnd.Next(1000).ToString(),
Email = rnd.Next(1000).ToString(),
Password = rnd.Next(1000).ToString(),
RoleId = roles[rnd.Next(roles.Count)].Id,
};
context.Users.Add(User.Create(model));
}
context.SaveChanges();
}
}
}