diff --git a/BusinessLogic/BusinessLogic/RouteLogic.cs b/BusinessLogic/BusinessLogic/RouteLogic.cs index e4b150c..ed08761 100644 --- a/BusinessLogic/BusinessLogic/RouteLogic.cs +++ b/BusinessLogic/BusinessLogic/RouteLogic.cs @@ -76,6 +76,16 @@ namespace BusinessLogic.BusinessLogic return list; } + public string TestInsertList(int num) + { + throw new NotImplementedException(); + } + + public string TestReadList(int num) + { + return _routeStorage.TestReadList(num); + } + public bool Update(RouteBindingModel model) { CheckModel(model); diff --git a/TransportGuide/FormMain.Designer.cs b/TransportGuide/FormMain.Designer.cs index c85a1ff..2839e8a 100644 --- a/TransportGuide/FormMain.Designer.cs +++ b/TransportGuide/FormMain.Designer.cs @@ -32,6 +32,7 @@ this.transportTypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.stopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.routeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.testsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); // @@ -41,7 +42,8 @@ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.transportTypeToolStripMenuItem, this.stopToolStripMenuItem, - this.routeToolStripMenuItem}); + this.routeToolStripMenuItem, + this.testsToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(800, 33); @@ -69,6 +71,13 @@ this.routeToolStripMenuItem.Text = "Route"; this.routeToolStripMenuItem.Click += new System.EventHandler(this.routeToolStripMenuItem_Click); // + // testsToolStripMenuItem + // + this.testsToolStripMenuItem.Name = "testsToolStripMenuItem"; + this.testsToolStripMenuItem.Size = new System.Drawing.Size(66, 29); + this.testsToolStripMenuItem.Text = "Tests"; + this.testsToolStripMenuItem.Click += new System.EventHandler(this.testsToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -92,5 +101,6 @@ private ToolStripMenuItem transportTypeToolStripMenuItem; private ToolStripMenuItem stopToolStripMenuItem; private ToolStripMenuItem routeToolStripMenuItem; + private ToolStripMenuItem testsToolStripMenuItem; } } \ No newline at end of file diff --git a/TransportGuide/FormMain.cs b/TransportGuide/FormMain.cs index c052f32..13c11c5 100644 --- a/TransportGuide/FormMain.cs +++ b/TransportGuide/FormMain.cs @@ -53,5 +53,15 @@ namespace TransportGuide form.ShowDialog(); } } + + private void testsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTests)); + + if (service is FormTests form) + { + form.ShowDialog(); + } + } } } diff --git a/TransportGuide/FormTests.Designer.cs b/TransportGuide/FormTests.Designer.cs new file mode 100644 index 0000000..083800b --- /dev/null +++ b/TransportGuide/FormTests.Designer.cs @@ -0,0 +1,228 @@ +namespace TransportGuide +{ + partial class FormTests + { + /// + /// 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() + { + 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; + } +} diff --git a/TransportGuide/FormTests.cs b/TransportGuide/FormTests.cs new file mode 100644 index 0000000..d64b79c --- /dev/null +++ b/TransportGuide/FormTests.cs @@ -0,0 +1,75 @@ +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; +using TransportGuideContracts.BusinessLogicsContracts; + +namespace TransportGuide +{ + public partial class FormTests : Form + { + private readonly IRouteLogic _routeLogic; + //private readonly IUserLogic _userLogic; + //private readonly ITopicLogic _topicLogic; + public FormTests(IRouteLogic routeLogic)//IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic) + { + InitializeComponent(); + //_userLogic = userLogic; + //_topicLogic = topicLogic; + _routeLogic= routeLogic; + 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 = _routeLogic.TestReadList(Convert.ToInt32(numericUpDownRead.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); + //} + } + } +} diff --git a/TransportGuide/FormTests.resx b/TransportGuide/FormTests.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportGuide/FormTests.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/TransportGuide/Program.cs b/TransportGuide/Program.cs index 68f422f..dcc378b 100644 --- a/TransportGuide/Program.cs +++ b/TransportGuide/Program.cs @@ -49,6 +49,8 @@ namespace TransportGuide services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file diff --git a/TransportGuideContracts/BusinessLogicsContracts/IRouteLogic.cs b/TransportGuideContracts/BusinessLogicsContracts/IRouteLogic.cs index 7ed5c51..816ea51 100644 --- a/TransportGuideContracts/BusinessLogicsContracts/IRouteLogic.cs +++ b/TransportGuideContracts/BusinessLogicsContracts/IRouteLogic.cs @@ -16,5 +16,7 @@ namespace TransportGuideContracts.BusinessLogicsContracts bool Create(RouteBindingModel model); bool Update(RouteBindingModel model); bool Delete(RouteBindingModel model); + string TestInsertList(int num); + string TestReadList(int num); } } diff --git a/TransportGuideContracts/StoragesContracts/IRouteStorage.cs b/TransportGuideContracts/StoragesContracts/IRouteStorage.cs index 70c0afb..a9ca35d 100644 --- a/TransportGuideContracts/StoragesContracts/IRouteStorage.cs +++ b/TransportGuideContracts/StoragesContracts/IRouteStorage.cs @@ -17,5 +17,7 @@ namespace TransportGuideContracts.StoragesContracts RouteViewModel? Insert(RouteBindingModel model); RouteViewModel? Update(RouteBindingModel model); RouteViewModel? Delete(RouteBindingModel model); + string TestInsertList(int num); + string TestReadList(int num); } } diff --git a/TransportGuideDatabaseImplements/Implements/RouteStorage.cs b/TransportGuideDatabaseImplements/Implements/RouteStorage.cs index 5f10946..923bba2 100644 --- a/TransportGuideDatabaseImplements/Implements/RouteStorage.cs +++ b/TransportGuideDatabaseImplements/Implements/RouteStorage.cs @@ -1,6 +1,8 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -78,6 +80,36 @@ namespace TransportGuideDatabaseImplements.Implements return newRoute.GetViewModel; } + public string TestInsertList(int num) + { + throw new NotImplementedException(); + } + + public string TestReadList(int num) + { + var context = new TransportGuideDB(); + Stopwatch stopwatch = new(); + + long[] res = new long[num]; + + for (int i = 0; i < num; i++) + { + + stopwatch.Start(); + List list = context.Routes.Include(x => x.TransportType).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(); + } + public RouteViewModel? Update(RouteBindingModel model) { using var context = new TransportGuideDB();