осталось малость пофиксить

This commit is contained in:
VictoriaPresnyakova 2023-05-05 23:52:14 +04:00
parent 2d2cd016c7
commit 75a6b87680
3 changed files with 61 additions and 18 deletions

View File

@ -78,7 +78,7 @@ namespace BusinessLogic.BusinessLogic
public string TestInsertList(int num)
{
throw new NotImplementedException();
return _routeStorage.TestInsertList(num);
}
public string TestReadList(int num)

View File

@ -19,31 +19,27 @@ namespace TransportGuide
public FormTests(IRouteLogic routeLogic)//IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic)
{
InitializeComponent();
//_userLogic = userLogic;
//_topicLogic = topicLogic;
_routeLogic= routeLogic;
numericUpDownInsert.Minimum = 0;
numericUpDownInsert.Minimum = 1;
numericUpDownInsert.Maximum = 1000000;
numericUpDownRead.Minimum = 0;
numericUpDownRead.Minimum = 1;
numericUpDownRead.Maximum = 1000000;
numericUpDownJoin.Minimum = 0;
numericUpDownJoin.Minimum = 1;
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());
try
{
var result = _routeLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value));
// textBoxInsertTime.Text = result;
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
textBoxInsertTime.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonReadTest_Click(object sender, EventArgs e)

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using TransportGuideContracts.BindingModels;
@ -82,7 +83,53 @@ namespace TransportGuideDatabaseImplements.Implements
public string TestInsertList(int num)
{
throw new NotImplementedException();
var context = new TransportGuideDB();
Stopwatch stopwatch = new();
Random rnd = new Random();
long[] res = new long[num * 2];
List<TransportTypeViewModel> _types = context.TransportTypes.ToList().Select(x => x.GetViewModel).ToList();
for (int i = 0; i < num; ++i)
{
int rndId = rnd.Next();
var model = new StopBindingModel
{
Id = rndId,
Name = "Stop" + 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 = "Route" + rndId.ToString(),
IP = "IP" + rndId.ToString(),
TransportTypeId = _types[rnd.Next(_types.Count)].Id
};
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)