using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; using AsbCloudInfrastructure.Services; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AsbCloudApp.Services; using Moq; using Xunit; using AsbCloudApp.Data.SAUB; using AsbCloudInfrastructure.Services.SAUB; namespace AsbCloudWebApi.Tests.ServicesTests; public class EventServiceTest { private readonly AsbCloudDbContext context; private readonly CacheDb cacheDb; private readonly Mock telemetryService; public EventServiceTest() { context = TestHelpter.MakeTestContext(); cacheDb = new CacheDb(); telemetryService = new Mock(); telemetryService.Setup(s => s.GetOrCreateTelemetryIdByUid(It.IsAny())) .Returns(1); context.TelemetryEvents.RemoveRange(context.TelemetryEvents); context.SaveChanges(); } [Fact] public async Task It_should_save_two_telemetry_events() { var service = new EventService(context, cacheDb, telemetryService.Object); var dtos = new List { new EventDto {Id = 1, IdCategory = 1, Message = "Test message 1"}, new EventDto {Id = 2, IdCategory = 1, Message = "Test message 2"} }; await service.UpsertAsync("uid", dtos); Assert.Equal(2, context.TelemetryEvents.Count()); } }