remove CacheDB from tests

This commit is contained in:
ngfrolov 2022-11-18 16:13:32 +05:00
parent 342f5845f4
commit 431d291782
7 changed files with 11 additions and 26 deletions

View File

@ -22,7 +22,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
protected override ICrudService<DepositDto> MakeService()
{
var dbContext = TestHelpter.MakeRealTestContext();
return new CrudCacheServiceBase<DepositDto, Deposit>(dbContext);
return new CrudCacheServiceBase<DepositDto, Deposit>(dbContext, TestHelpter.MemoryCache);
}
}
}

View File

@ -3,8 +3,6 @@ using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.DetectOperations;
using Moq;
using System;
@ -19,7 +17,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
public class DetectedOperationServiceTest
{
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
private readonly DetectedOperationService service;
private readonly DetectedOperationRequest request;
private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" };

View File

@ -1,10 +1,5 @@
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using Moq;
using System.Collections.Generic;
using System.Linq;

View File

@ -1,7 +1,6 @@
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.SAUB;
using Moq;
using System.Collections.Generic;
@ -14,13 +13,11 @@ namespace AsbCloudWebApi.Tests.ServicesTests;
public class EventServiceTest
{
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
private readonly EventService service;
public EventServiceTest()
{
context = TestHelpter.MakeRealTestContext();
cacheDb = new CacheDb();
var telemetryTracker = new Mock<ITelemetryTracker>();
var imezoneServiceMock = new Mock<ITimezoneService>();
var telemetryService = new TelemetryService(context, telemetryTracker.Object, imezoneServiceMock.Object);

View File

@ -1,7 +1,5 @@
using AsbCloudApp.Data;
using AsbCloudDb.Model;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -19,7 +17,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
context = TestHelpter.MakeRealTestContext();
context.SaveChanges();
service = new FileCategoryService(context);
service = new FileCategoryService(context, TestHelpter.MemoryCache);
}
~FileCategoryServiceTest()

View File

@ -2,7 +2,6 @@
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.SAUB;
using Moq;
using System;
@ -20,9 +19,9 @@ namespace AsbCloudWebApi.Tests.ServicesTests
private readonly Mock<ITimezoneService> timezoneService;
private readonly SimpleTimezoneDto timezone;
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
private readonly TelemetryService telemetryService;
private readonly TelemetryUserService telemetryUserService;
private readonly TelemetryDataCache<TelemetryDataSaubDto> telemetryDataSaubCache;
private readonly DateTime drillingStartDate;
private readonly string uuid;
public TelemetryDataSaubServiceTest()
@ -41,9 +40,9 @@ namespace AsbCloudWebApi.Tests.ServicesTests
.Returns(timezone);
context = TestHelpter.MakeRealTestContext();
cacheDb = new CacheDb();
telemetryService = new TelemetryService(context, telemetryTracker.Object, timezoneService.Object);
telemetryUserService = new TelemetryUserService(context, telemetryService, TestHelpter.MemoryCache);
telemetryDataSaubCache = TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(context, out Task _);
var info = new TelemetryInfoDto
{
TimeZoneOffsetTotalHours = timezone.Hours,
@ -64,7 +63,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
public async Task UpdateDataAsync()
{
// Arrange
var telemetryDataSaubService = new TelemetryDataSaubService(context, telemetryService, null, cacheDb);
var telemetryDataSaubService = new TelemetryDataSaubService(context, telemetryService, telemetryUserService, telemetryDataSaubCache);
var now = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)).DateTime;
var tuser = "Завулон";

View File

@ -1,5 +1,6 @@
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Moq;
using System.Collections.Generic;
using System.Linq;
@ -10,16 +11,14 @@ namespace AsbCloudWebApi.Tests
{
// Попробовать когда-нибудь https://github.com/MichalJankowskii/Moq.EntityFrameworkCore
public static IMemoryCache MemoryCache = new MemoryCache(new MemoryCacheOptions());
public static AsbCloudDbContext MakeRealTestContext()
{
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
//.UseInMemoryDatabase(System.Guid.NewGuid().ToString())
//.ConfigureWarnings(configBuilder =>
// configBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning))
.UseNpgsql("Host=localhost;Database=tests;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True")
.Options;
var context = new AsbCloudDbContext(options);
//context.Database.EnsureDeleted();
context.Database.EnsureCreated();
return context;
}