diff --git a/AsbCloudWebApi.Tests/ServicesTests/EventServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/EventServiceTest.cs new file mode 100644 index 00000000..e6aef6ed --- /dev/null +++ b/AsbCloudWebApi.Tests/ServicesTests/EventServiceTest.cs @@ -0,0 +1,47 @@ +using AsbCloudApp.Data; +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 AsbCloudInfrastructure.Services; +using Moq; +using Xunit; + +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()); + } +} \ No newline at end of file