правки по результатам ревью

This commit is contained in:
Olga Nemt 2024-09-11 10:56:26 +05:00
parent 57d97057da
commit 31efdbf406
8 changed files with 47 additions and 66 deletions

View File

@ -17,7 +17,7 @@ public interface IEventRepository
/// <param name="request">параметры запроса</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TelemetryEventDto>> Get(TelemetryEventRequest request, CancellationToken token);
Task<IEnumerable<TelemetryEventDto>> GetAsync(TelemetryEventRequest request, CancellationToken token);
/// <summary>
/// Сохранить. Добавить или заменить.
@ -26,6 +26,5 @@ public interface IEventRepository
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
CancellationToken token = default);
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos, CancellationToken token);
}

View File

@ -14,7 +14,7 @@ namespace AsbCloudApp.Repositories;
public interface IMessageRepository : ITelemetryDataEditorService
{
/// <summary>
/// Получить PaginationContainer с сообщениями по параметрам
/// Получить сообщения по параметрам
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>

View File

@ -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
/// <summary>
/// события
/// </summary>
public IEnumerable<TelemetryEventDto> Events { get; set; } = null!;
public IEnumerable<TelemetryEventDto> Events { get; set; }= Enumerable.Empty<TelemetryEventDto>();
/// <summary>
/// телеметрии
/// </summary>
public IEnumerable<TelemetryBaseDto> Telemetries { get; set; } = null!;
public IEnumerable<TelemetryBaseDto> Telemetries { get; set; } = Enumerable.Empty<TelemetryBaseDto>();
/// <summary>
///
/// </summary>
/// <param name="request"></param>
public MessageTelemetryRequest(MessageRequestBase request) : base(request)
/// <inheritdoc/>
public MessageTelemetryRequest(
MessageRequestBase request,
IEnumerable<TelemetryEventDto> events,
IEnumerable<TelemetryBaseDto> telemetries) : base(request)
{
Events = events;
Telemetries = telemetries;
}
/// <inheritdoc/>
public MessageTelemetryRequest(MessageRequestBase request)
: base(request) { }
}

View File

@ -17,7 +17,7 @@ public interface IMessageService
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<StatCriticalMessageDto>> GetStat(MessageRequest request, CancellationToken token);
Task<IEnumerable<StatCriticalMessageDto>> GetStatAsync(MessageRequest request, CancellationToken token);
/// <summary>
/// Получить PaginationContainer с сообщениями по параметрам

View File

@ -224,7 +224,7 @@ public class MessageServiceTest
.Returns(telemetries);
eventRepositoryMock
.Get(Arg.Any<TelemetryEventRequest>(), Arg.Any<CancellationToken>())
.GetAsync(Arg.Any<TelemetryEventRequest>(), Arg.Any<CancellationToken>())
.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);
}

View File

@ -27,7 +27,7 @@ public class EventRepository : IEventRepository
this.telemetryService = telemetryService;
}
public async Task<IEnumerable<TelemetryEventDto>> Get(TelemetryEventRequest request, CancellationToken token)
public async Task<IEnumerable<TelemetryEventDto>> GetAsync(TelemetryEventRequest request, CancellationToken token)
{
var allEvents = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryEvent>(), 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<TelemetryEvent>();
}
}

View File

@ -36,7 +36,7 @@ public class MessageService : IMessageService
return result;
}
public async Task<IEnumerable<StatCriticalMessageDto>> GetStat(MessageRequest request, CancellationToken token)
public async Task<IEnumerable<StatCriticalMessageDto>> GetStatAsync(MessageRequest request, CancellationToken token)
{
var messageTelemetryRequest = await CreateMessageTelemetryRequest(request, token);
@ -70,17 +70,16 @@ public class MessageService : IMessageService
public async Task<MessageTelemetryRequest> 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;
}

View File

@ -68,7 +68,7 @@ public class MessageController : ControllerBase
[ProducesResponseType(typeof(IEnumerable<StatCriticalMessageDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> Get([FromQuery] MessageRequest request, CancellationToken token)
{
var result = await messageService.GetStat(request, token);
var result = await messageService.GetStatAsync(request, token);
return Ok(result);
}