diff --git a/Persistence.Client/Clients/IChangeLogClient.cs b/Persistence.Client/Clients/IChangeLogClient.cs
index 1658d5e..e904057 100644
--- a/Persistence.Client/Clients/IChangeLogClient.cs
+++ b/Persistence.Client/Clients/IChangeLogClient.cs
@@ -1,5 +1,4 @@
-using Microsoft.AspNetCore.Mvc;
-using Persistence.Models;
+using Persistence.Models;
using Persistence.Models.Requests;
using Refit;
@@ -10,7 +9,7 @@ namespace Persistence.Client.Clients;
///
public interface IChangeLogClient
{
- private const string BaseRoute = "/api/ChangeLog";
+ private const string BaseRoute = "/api/ChangeLog";
//[Get($"{BaseRoute}/current")]
///
@@ -22,25 +21,15 @@ public interface IChangeLogClient
[Post($"{BaseRoute}/replace")]
Task> ClearAndInsertRange(Guid idDiscriminator, IEnumerable dtos);
- /////
- ///// Получение данных на текущую дату (с пагинацией)
- /////
- /////
- ///// параметры запроса
- /////
- /////
- //Task GetCurrent(Guid idDiscriminator, SectionPartRequest request, CancellationToken token);
-
///
- /// Получение данных на определенную дату (с пагинацией)
+ /// Получение актуальных данных на определенную дату (с пагинацией)
///
///
///
/// параметры запроса
- ///
///
[Get($"{BaseRoute}/moment")]
- Task>> GetByDate(Guid idDiscriminator, DateTimeOffset moment, [Query]SectionPartRequest request);
+ Task>> GetByDate(Guid idDiscriminator, DateTimeOffset moment, [Query] SectionPartRequest request);
///
/// Получение исторических данных за определенный период времени
@@ -48,7 +37,6 @@ public interface IChangeLogClient
///
///
///
- ///
///
[Get($"{BaseRoute}/history")]
Task>> GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd);
@@ -67,7 +55,6 @@ public interface IChangeLogClient
///
///
///
- ///
///
[Post($"{BaseRoute}/range")]
Task> AddRange(Guid idDiscriminator, IEnumerable dtos);
@@ -86,7 +73,6 @@ public interface IChangeLogClient
///
///
///
- ///
///
[Put($"{BaseRoute}/range")]
Task> UpdateRange(Guid idDiscriminator, IEnumerable dtos);
@@ -95,7 +81,6 @@ public interface IChangeLogClient
/// Удалить одну запись
///
///
- ///
///
[Delete($"{BaseRoute}")]
Task> Delete(Guid id);
@@ -104,7 +89,6 @@ public interface IChangeLogClient
/// Удалить несколько записей
///
///
- ///
///
[Delete($"{BaseRoute}/range")]
Task> DeleteRange([Body] IEnumerable ids);
@@ -113,7 +97,6 @@ public interface IChangeLogClient
/// Получение списка дат, в которые происходили изменения (день, месяц, год, без времени)
///
///
- ///
///
[Get($"{BaseRoute}/datesRange")]
Task> GetDatesRange(Guid idDiscriminator);
diff --git a/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs b/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs
index a57433b..72f63da 100644
--- a/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs
+++ b/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs
@@ -1,19 +1,13 @@
-using Microsoft.Extensions.DependencyInjection;
-using Persistence.Client.Clients;
-using Persistence.Client;
-using Persistence.Models;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Xunit;
-using Microsoft.AspNetCore.Mvc;
+using Mapster;
using Microsoft.EntityFrameworkCore;
-using System.Net;
-using Mapster;
+using Microsoft.Extensions.DependencyInjection;
+using Persistence.Client;
+using Persistence.Client.Clients;
using Persistence.Database.Model;
+using Persistence.Models;
using Persistence.Models.Requests;
+using System.Net;
+using Xunit;
namespace Persistence.IntegrationTests.Controllers;
public class ChangeLogControllerTest : BaseIntegrationTest
@@ -58,7 +52,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
// assert
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
- Assert.Equal(count, result.Content);
+ Assert.Equal(count, result.Content);
}
[Fact]
@@ -127,7 +121,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
var count = 2;
var idDiscriminator = Guid.NewGuid();
var dtos = Generate(count, DateTimeOffset.UtcNow);
- var entities = dtos.Select(d => d.Adapt());
+ var entities = dtos.Select(d => d.Adapt()).ToArray();
dbContext.ChangeLog.AddRange(entities);
dbContext.SaveChanges();
@@ -138,7 +132,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
Id = c.Id,
IdSection = c.IdSection,
Value = c.Value
- });
+ }).ToArray();
// act
var result = await client.UpdateRange(idDiscriminator, dtos);
@@ -189,7 +183,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
public async Task GetDatesRange_returns_success()
{
// arrange
- var changeLogItems = CreateChangeLogItems(3);
+ var changeLogItems = CreateChangeLogItems(3, (-15, 15));
var idDiscriminator = changeLogItems.Item1;
var entities = changeLogItems.Item2;
@@ -213,57 +207,82 @@ public class ChangeLogControllerTest : BaseIntegrationTest
Assert.Equal(expectedMaxDate, actualMaxDate);
}
- private (Guid, ChangeLog[]) CreateChangeLogItems(int count)
- {
- Guid idDiscriminator = Guid.NewGuid();
- var dtos = Generate(count, DateTimeOffset.UtcNow);
- var entities = dtos.Select(d =>
- {
- var entity = d.Adapt();
- entity.IdDiscriminator = idDiscriminator;
- entity.Creation = DateTimeOffset.UtcNow.AddDays(generatorRandomDigits.Next(-15, 15));
-
- return entity;
- }).ToArray();
- dbContext.ChangeLog.AddRange(entities);
- dbContext.SaveChanges();
-
- return (idDiscriminator, entities);
- }
-
[Fact]
public async Task GetByDate_returns_success()
{
// arrange
- var changeLogItems = CreateChangeLogItems(3);
+ //создаем записи
+ var count = 5;
+ var changeLogItems = CreateChangeLogItems(count, (-15, 15));
var idDiscriminator = changeLogItems.Item1;
var entities = changeLogItems.Item2;
- var createdDates = entities.Select(e => e.Creation);
- var dtos = entities.Select(e =>
+ //удаляем все созданные записи за исключением первой и второй
+ //даты 2-х оставшихся записей должны вернуться в методе GetByDate
+ var ids = entities.Select(e => e.Id);
+ var idsToDelete = ids.Skip(2);
+
+ var deletedCount = await client.DeleteRange(idsToDelete);
+
+ var request = new SectionPartRequest()
{
- var dto = e.Adapt();
- dto.DepthEnd = dto.DepthEnd + 10;
-
- return dto;
- }).ToArray();
-
- var updatedItems = await client.UpdateRange(idDiscriminator, dtos);
-
- var request = new SectionPartRequest() {
Skip = 0,
Take = 10,
SortSettings = String.Empty,
};
- var moment = DateTimeOffset.UtcNow.AddDays(20);
+ var moment = DateTimeOffset.UtcNow.AddDays(16);
var result = await client.GetByDate(idDiscriminator, moment, request);
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Assert.NotNull(result.Content);
+ var restEntities = entities.Where(e => !idsToDelete.Contains(e.Id));
+ Assert.Equal(restEntities.Count(), result.Content.Count);
+
+ var actualIds = restEntities.Select(e => e.Id);
+ var expectedIds = result.Content.Items.Select(e => e.Id);
+ Assert.Equivalent(expectedIds, actualIds);
}
+ [Theory]
+ [InlineData(5, -15, 15, -20, 20, 10)]
+ [InlineData(5, -15, -10, -16, -9, 5)]
+ public async Task GetChangeLogForDate_returns_success(
+ int insertedCount,
+ int leftCreationFromCurrentDate,
+ int rightCreationFromCurrentDate,
+ int leftPointFromCurrentDate,
+ int rightPointFromCurrentDate,
+ int changeLogCount)
+ {
+ // arrange
+ //создаем записи
+ var count = insertedCount;
+ var daysRange = (leftCreationFromCurrentDate, rightCreationFromCurrentDate);
+ var changeLogItems = CreateChangeLogItems(count, daysRange);
+ var idDiscriminator = changeLogItems.Item1;
+ var entities = changeLogItems.Item2;
+
+ foreach (var entity in entities)
+ {
+ entity.DepthEnd = entity.DepthEnd + 10;
+ }
+ var dtos = entities.Select(e => e.Adapt()).ToArray();
+ await client.UpdateRange(idDiscriminator, dtos);
+
+ //act
+ var dateBegin = DateTimeOffset.UtcNow.AddDays(leftPointFromCurrentDate);
+ var dateEnd = DateTimeOffset.UtcNow.AddDays(rightPointFromCurrentDate);
+ var result = await client.GetChangeLogForDate(idDiscriminator, dateBegin, dateEnd);
+
+ //assert
+ Assert.Equal(HttpStatusCode.OK, result.StatusCode);
+ Assert.NotNull(result.Content);
+ Assert.Equal(changeLogCount, result.Content.Count());
+ }
+
+
private static IEnumerable Generate(int count, DateTimeOffset from)
{
for (int i = 0; i < count; i++)
@@ -280,4 +299,25 @@ public class ChangeLogControllerTest : BaseIntegrationTest
};
}
+
+ private (Guid, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange)
+ {
+ var minDayCount = daysRange.Item1;
+ var maxDayCount = daysRange.Item2;
+
+ Guid idDiscriminator = Guid.NewGuid();
+ var dtos = Generate(count, DateTimeOffset.UtcNow);
+ var entities = dtos.Select(d =>
+ {
+ var entity = d.Adapt();
+ entity.IdDiscriminator = idDiscriminator;
+ entity.Creation = DateTimeOffset.UtcNow.AddDays(generatorRandomDigits.Next(minDayCount, maxDayCount));
+
+ return entity;
+ }).ToArray();
+ dbContext.ChangeLog.AddRange(entities);
+ dbContext.SaveChanges();
+
+ return (idDiscriminator, entities);
+ }
}