fix EventServiceTest.Upsert_telemetry_events()

This commit is contained in:
ngfrolov 2022-06-10 10:36:51 +05:00
parent a8c4fa58e9
commit 2f5178a68e
2 changed files with 7 additions and 15 deletions

View File

@ -15,25 +15,22 @@ namespace AsbCloudWebApi.Tests.ServicesTests;
public class EventServiceTest public class EventServiceTest
{ {
private readonly AsbCloudDbContext context; private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb; private readonly CacheDb cacheDb;
private readonly Mock<ITelemetryService> telemetryService; private readonly EventService service;
public EventServiceTest() public EventServiceTest()
{ {
context = TestHelpter.MakeTestContext(); context = TestHelpter.MakeTestContext();
cacheDb = new CacheDb(); cacheDb = new CacheDb();
telemetryService = new Mock<ITelemetryService>(); var telemetryTracker = new Mock<ITelemetryTracker>();
telemetryService.Setup(s => s.GetOrCreateTelemetryIdByUid(It.IsAny<string>())) var imezoneServiceMock = new Mock<ITimezoneService>();
.Returns(1); var telemetryService = new TelemetryService(context, telemetryTracker.Object, imezoneServiceMock.Object, cacheDb);
context.TelemetryEvents.RemoveRange(context.TelemetryEvents); service = new EventService(context, cacheDb, telemetryService);
context.SaveChanges();
} }
[Fact] [Fact]
public async Task It_should_save_two_telemetry_events() public async Task Upsert_telemetry_events()
{ {
var service = new EventService(context, cacheDb, telemetryService.Object);
var dtos = new List<EventDto> var dtos = new List<EventDto>
{ {
new EventDto {Id = 1, IdCategory = 1, Message = "Test message 1"}, new EventDto {Id = 1, IdCategory = 1, Message = "Test message 1"},

View File

@ -1,10 +1,5 @@
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Tests namespace AsbCloudWebApi.Tests
{ {