diff --git a/AsbCloudApp/Repositories/IEventRepository.cs b/AsbCloudApp/Repositories/IEventRepository.cs
index ebe5e500..90aa9687 100644
--- a/AsbCloudApp/Repositories/IEventRepository.cs
+++ b/AsbCloudApp/Repositories/IEventRepository.cs
@@ -17,7 +17,7 @@ public interface IEventRepository
/// параметры запроса
///
///
- Task> Get(TelemetryEventRequest request, CancellationToken token);
+ Task> GetAsync(TelemetryEventRequest request, CancellationToken token);
///
/// Сохранить. Добавить или заменить.
@@ -26,6 +26,5 @@ public interface IEventRepository
///
///
///
- Task UpsertAsync(string uid, IEnumerable dtos,
- CancellationToken token = default);
+ Task UpsertAsync(string uid, IEnumerable dtos, CancellationToken token);
}
diff --git a/AsbCloudApp/Repositories/IMessageRepository.cs b/AsbCloudApp/Repositories/IMessageRepository.cs
index d08eeefc..ac794a46 100644
--- a/AsbCloudApp/Repositories/IMessageRepository.cs
+++ b/AsbCloudApp/Repositories/IMessageRepository.cs
@@ -14,7 +14,7 @@ namespace AsbCloudApp.Repositories;
public interface IMessageRepository : ITelemetryDataEditorService
{
///
- /// Получить PaginationContainer с сообщениями по параметрам
+ /// Получить сообщения по параметрам
///
///
///
diff --git a/AsbCloudApp/Requests/MessageRequest.cs b/AsbCloudApp/Requests/MessageRequest.cs
index 861d091a..413b9091 100644
--- a/AsbCloudApp/Requests/MessageRequest.cs
+++ b/AsbCloudApp/Requests/MessageRequest.cs
@@ -2,6 +2,7 @@ using AsbCloudApp.Data;
using AsbCloudApp.Data.SAUB;
using System;
using System.Collections.Generic;
+using System.Linq;
namespace AsbCloudApp.Requests;
@@ -86,19 +87,25 @@ public class MessageTelemetryRequest : MessageRequestBase
///
/// события
///
- public IEnumerable Events { get; set; } = null!;
+ public IEnumerable Events { get; set; }= Enumerable.Empty();
///
/// телеметрии
///
- public IEnumerable Telemetries { get; set; } = null!;
+ public IEnumerable Telemetries { get; set; } = Enumerable.Empty();
- ///
- ///
- ///
- ///
- public MessageTelemetryRequest(MessageRequestBase request) : base(request)
+ ///
+ public MessageTelemetryRequest(
+ MessageRequestBase request,
+ IEnumerable events,
+ IEnumerable telemetries) : base(request)
{
+ Events = events;
+ Telemetries = telemetries;
}
+
+ ///
+ public MessageTelemetryRequest(MessageRequestBase request)
+ : base(request) { }
}
diff --git a/AsbCloudApp/Services/IMessageService.cs b/AsbCloudApp/Services/IMessageService.cs
index 92fd7864..319d2faa 100644
--- a/AsbCloudApp/Services/IMessageService.cs
+++ b/AsbCloudApp/Services/IMessageService.cs
@@ -17,7 +17,7 @@ public interface IMessageService
///
///
///
- Task> GetStat(MessageRequest request, CancellationToken token);
+ Task> GetStatAsync(MessageRequest request, CancellationToken token);
///
/// Получить PaginationContainer с сообщениями по параметрам
diff --git a/AsbCloudInfrastructure.Tests/Services/MessageServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/MessageServiceTest.cs
index c6a0627d..8cb94ca5 100644
--- a/AsbCloudInfrastructure.Tests/Services/MessageServiceTest.cs
+++ b/AsbCloudInfrastructure.Tests/Services/MessageServiceTest.cs
@@ -224,7 +224,7 @@ public class MessageServiceTest
.Returns(telemetries);
eventRepositoryMock
- .Get(Arg.Any(), Arg.Any())
+ .GetAsync(Arg.Any(), Arg.Any())
.Returns(events);
messageRepositoryMock
@@ -239,75 +239,51 @@ public class MessageServiceTest
//act
var baseRequest = new MessageRequestBase() { };
var messageRequest = new MessageRequest(baseRequest, [1]);
- var result = await messageServiceMock.GetStat(messageRequest, CancellationToken.None);
+ var result = await messageServiceMock.GetStatAsync(messageRequest, CancellationToken.None);
Assert.Equal(6, result.Count());
- var mCount_Telemetry_1_Category_1_Template_1_Expected = messages
- .Where(x => x.IdTelemetry == 1)
- .Where(x => x.IdEvent == 1)
- .Count();
- var mCount_Telemetry_1_Category_1_Template_1_Actual = result
+ var сообщение_1_1 = result
.Where(x => x.IdTelemetry == 1)
.Where(x => x.IdCategory == 1)
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 1")
- .Sum(x => x.MessagesCount);
- Assert.Equal(mCount_Telemetry_1_Category_1_Template_1_Expected, mCount_Telemetry_1_Category_1_Template_1_Actual);
+ .Single();
+ Assert.Equal(3, сообщение_1_1.MessagesCount);
- var mCount_Telemetry_1_Category_1_Template_2_Expected = messages
- .Where(x => x.IdTelemetry == 1)
- .Where(x => x.IdEvent == 2)
- .Count();
- var mCount_Telemetry_1_Category_1_Template_2_Actual = result
+ var сообщение_1_2 = result
.Where(x => x.IdTelemetry == 1)
.Where(x => x.IdCategory == 1)
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 1")
- .Sum(x => x.MessagesCount);
- Assert.Equal(mCount_Telemetry_1_Category_1_Template_2_Expected, mCount_Telemetry_1_Category_1_Template_2_Actual);
+ .Single();
+ Assert.Equal(3, сообщение_1_2.MessagesCount);
- var mCount_Telemetry_1_Category_1_Template_3_Expected = messages
- .Where(x => x.IdTelemetry == 1)
- .Where(x => x.IdEvent == 3)
- .Count();
- var mCount_Telemetry_1_Category_1_Template_3_Actual = result
+ var сообщение_1_3 = result
.Where(x => x.IdTelemetry == 1)
.Where(x => x.IdCategory == 1)
.Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 1")
- .Sum(x => x.MessagesCount);
- Assert.Equal(mCount_Telemetry_1_Category_1_Template_3_Expected, mCount_Telemetry_1_Category_1_Template_3_Actual);
+ .Single();
+ Assert.Equal(3, сообщение_1_3.MessagesCount);
- var mCount_Telemetry_1_Category_2_Template_2_Expected = messages
- .Where(x => x.IdTelemetry == 1)
- .Where(x => x.IdEvent == 5)
- .Count();
- var mCount_Telemetry_1_Category_2_Template_2_Actual = result
+ var сообщение_2_2 = result
.Where(x => x.IdTelemetry == 1)
.Where(x => x.IdCategory == 2)
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 2")
- .Sum(x => x.MessagesCount);
- Assert.Equal(mCount_Telemetry_1_Category_2_Template_2_Expected, mCount_Telemetry_1_Category_2_Template_2_Actual);
+ .Single();
+ Assert.Equal(2, сообщение_2_2.MessagesCount);
- var mCount_Telemetry_1_Category_2_Template_3_Expected = messages
- .Where(x => x.IdTelemetry == 1)
- .Where(x => x.IdEvent == 6)
- .Count();
- var mCount_Telemetry_1_Category_2_Template_3_Actual = result
+ var сообщение_2_1 = result
.Where(x => x.IdTelemetry == 1)
.Where(x => x.IdCategory == 2)
- .Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 2")
- .Sum(x => x.MessagesCount);
- Assert.Equal(mCount_Telemetry_1_Category_2_Template_3_Expected, mCount_Telemetry_1_Category_2_Template_3_Actual);
+ .Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 2")
+ .Single();
+ Assert.Equal(2, сообщение_2_1.MessagesCount);
- var mCount_Telemetry_2_Category_3_Template_1_Expected = messages
- .Where(x => x.IdTelemetry == 2)
- .Where(x => x.IdEvent == 6)
- .Count();
- var mCount_Telemetry_2_Category_3_Template_1_Actual = result
+ var сообщение_3_1 = result
.Where(x => x.IdTelemetry == 2)
.Where(x => x.IdCategory == 3)
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 3")
- .Sum(x => x.MessagesCount);
- Assert.Equal(mCount_Telemetry_2_Category_3_Template_1_Expected, mCount_Telemetry_2_Category_3_Template_1_Actual);
+ .Single();
+ Assert.Equal(3, сообщение_3_1.MessagesCount);
}
diff --git a/AsbCloudInfrastructure/Repository/EventRepository.cs b/AsbCloudInfrastructure/Repository/EventRepository.cs
index 8d3665a4..680746f9 100644
--- a/AsbCloudInfrastructure/Repository/EventRepository.cs
+++ b/AsbCloudInfrastructure/Repository/EventRepository.cs
@@ -27,7 +27,7 @@ public class EventRepository : IEventRepository
this.telemetryService = telemetryService;
}
- public async Task> Get(TelemetryEventRequest request, CancellationToken token)
+ public async Task> GetAsync(TelemetryEventRequest request, CancellationToken token)
{
var allEvents = await memoryCache.GetOrCreateBasicAsync(db.Set(), token);
var events = allEvents.Where(e => request.IdsTelemetries.Contains(e.IdTelemetry));
@@ -65,7 +65,7 @@ public class EventRepository : IEventRepository
IdCategory = dto.IdCategory,
MessageTemplate = dto.Message
});
- var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
+ await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
memoryCache.DropBasic();
}
}
diff --git a/AsbCloudInfrastructure/Services/MessageService.cs b/AsbCloudInfrastructure/Services/MessageService.cs
index f71b5c4a..24d703c1 100644
--- a/AsbCloudInfrastructure/Services/MessageService.cs
+++ b/AsbCloudInfrastructure/Services/MessageService.cs
@@ -36,7 +36,7 @@ public class MessageService : IMessageService
return result;
}
- public async Task> GetStat(MessageRequest request, CancellationToken token)
+ public async Task> GetStatAsync(MessageRequest request, CancellationToken token)
{
var messageTelemetryRequest = await CreateMessageTelemetryRequest(request, token);
@@ -70,17 +70,16 @@ public class MessageService : IMessageService
public async Task CreateMessageTelemetryRequest(MessageRequest request, CancellationToken token)
{
var telemetries = telemetryService.GetOrDefaultTelemetriesByIdsWells(request.IdsWell);
-
+
var telemetryEventRequest = new TelemetryEventRequest()
{
IdsTelemetries = telemetries.Select(t => t.Id),
IdsCategories = request.IdsCategories,
SearchString = request.SearchString,
};
-
- var messageTelemetryRequest = new MessageTelemetryRequest(request);
- messageTelemetryRequest.Telemetries = telemetries;
- messageTelemetryRequest.Events = await eventRepository.Get(telemetryEventRequest, token);
+ var events = await eventRepository.GetAsync(telemetryEventRequest, token);
+
+ var messageTelemetryRequest = new MessageTelemetryRequest(request, events, telemetries);
return messageTelemetryRequest;
}
diff --git a/AsbCloudWebApi/Controllers/SAUB/MessageController.cs b/AsbCloudWebApi/Controllers/SAUB/MessageController.cs
index 1867be94..31bd4345 100644
--- a/AsbCloudWebApi/Controllers/SAUB/MessageController.cs
+++ b/AsbCloudWebApi/Controllers/SAUB/MessageController.cs
@@ -68,7 +68,7 @@ public class MessageController : ControllerBase
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task Get([FromQuery] MessageRequest request, CancellationToken token)
{
- var result = await messageService.GetStat(request, token);
+ var result = await messageService.GetStatAsync(request, token);
return Ok(result);
}