Доработка юнит-тестов

This commit is contained in:
Olga Nemt 2024-08-05 10:20:48 +05:00
parent ada5dc28aa
commit 1aeb9599d1
2 changed files with 19 additions and 5 deletions

View File

@ -32,7 +32,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
var dataSaubStatService = services.GetService<IDataSaubStatService>(); var dataSaubStatService = services.GetService<IDataSaubStatService>();
if (dataSaubStatService != null ) if (dataSaubStatService != null )
var createdDataSaubStatCount = await dataSaubStatService.CreateStatAsync(Gap, onProgressCallback, token); await dataSaubStatService.CreateStatAsync(Gap, onProgressCallback, token);
} }
} }

View File

@ -244,16 +244,24 @@ public class DataSaubStatServiceTest
.InsertRangeAsync(Arg.Any<IEnumerable<DataSaubStatDto>>(), Arg.Any<CancellationToken>()) .InsertRangeAsync(Arg.Any<IEnumerable<DataSaubStatDto>>(), Arg.Any<CancellationToken>())
.Returns(insertedDataSaubStatCount); .Returns(insertedDataSaubStatCount);
Action<string, double?> action = (message, count) => Action<string, double?> action = (message, percent) =>
{ {
//assert //assert
Assert.Equal(insertedDataSaubStatCount, count); Assert.NotNull(percent);
Assert.InRange((double)percent, 0.0, 100.0);
}; };
//act //act
await dataSaubStatService.CreateStatAsync(Gap, action, CancellationToken.None); await dataSaubStatService.CreateStatAsync(Gap, action, CancellationToken.None);
//assert
await dataSaubStatRepositoryMock.Received().InsertRangeAsync(
Arg.Is<IEnumerable<DataSaubStatDto>>(l => l.Count() == insertedDataSaubStatCount),
Arg.Any<CancellationToken>());
} }
[Fact] [Fact]
public async Task Create_2DataSaubStatItems_ShouldReturn__Success() public async Task Create_2DataSaubStatItems_ShouldReturn__Success()
{ {
@ -297,13 +305,19 @@ public class DataSaubStatServiceTest
.InsertRangeAsync(Arg.Any<IEnumerable<DataSaubStatDto>>(), Arg.Any<CancellationToken>()) .InsertRangeAsync(Arg.Any<IEnumerable<DataSaubStatDto>>(), Arg.Any<CancellationToken>())
.Returns(insertedDataSaubStatCount); .Returns(insertedDataSaubStatCount);
Action<string, double?> action = (message, count) => Action<string, double?> action = (message, percent) =>
{ {
//assert //assert
Assert.Equal(insertedDataSaubStatCount, count); Assert.NotNull(percent);
Assert.InRange((double)percent, 0.0, 100.0);
}; };
//act //act
await dataSaubStatService.CreateStatAsync(Gap, action, CancellationToken.None); await dataSaubStatService.CreateStatAsync(Gap, action, CancellationToken.None);
//assert
await dataSaubStatRepositoryMock.Received().InsertRangeAsync(
Arg.Is<IEnumerable<DataSaubStatDto>>(l => l.Count() == insertedDataSaubStatCount),
Arg.Any<CancellationToken>());
} }
} }