using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.SAUB;
using Moq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace AsbCloudWebApi.Tests.ServicesTests;

public class EventServiceTest
{
    private readonly AsbCloudDbContext context;
    private readonly CacheDb cacheDb;
    private readonly EventService service;

    public EventServiceTest()
    {
        context = TestHelpter.MakeTestContext();
        cacheDb = new CacheDb();
        var telemetryTracker = new Mock<ITelemetryTracker>();
        var imezoneServiceMock = new Mock<ITimezoneService>();
        var telemetryService = new TelemetryService(context, telemetryTracker.Object, imezoneServiceMock.Object, cacheDb);
        service = new EventService(context, telemetryService);
    }

    [Fact]
    public async Task Upsert_telemetry_events()
    {
        var dtos = new List<EventDto>
        {
            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());
    }
}