using System; using System.Threading.Tasks; using Moq; using Xunit; using LCU.Api.Internal.MaidBotApi.Exceptions; using LCU.Api.Internal.MaidBotApi.Services; using LCU.Api.Internal.MaidBotLib.Models; using LCU.Api.Internal.MaidBotLib.Repositories; using LCU.Library.Internal.Exceptions; namespace LCU.Api.Internal.MaidBotTests.ServiceTests; public class DebugEventLogServiceTest { private readonly DebugEventLogService _debugEventLogService; private readonly Mock _mockDebugEventLogRepository; public DebugEventLogServiceTest() { var mockUnitOfWork = new Mock(); _mockDebugEventLogRepository = new Mock(); _debugEventLogService = new DebugEventLogService(mockUnitOfWork.Object, _mockDebugEventLogRepository.Object); } [Fact] public async Task SaveAsync_Success() { // Arrange _mockDebugEventLogRepository.Setup(repo => repo.AddAsync(It.IsAny())).ReturnsAsync(new DebugEventLog()); // Act var result = await _debugEventLogService.SaveAsync(new DebugEventLog()); // Assert Assert.NotNull(result); } [Fact] public async Task SaveAsync_Exception_Throws_ServerError() { // Arrange _mockDebugEventLogRepository.Setup(repo => repo.AddAsync(It.IsAny())).ThrowsAsync(new Exception()); // Act / Assert await Assert.ThrowsAsync(async () => await _debugEventLogService.SaveAsync(new DebugEventLog())); } [Fact] public async Task DebugEventLog_Verify_AddAsyncCalled_Once() { // Arrange var testEventLog = new EventLog() { DebugData = "Test Debug Data" }; var testDebugEventLog = new DebugEventLog() { RawLog = "Test Debug Data" }; _mockDebugEventLogRepository.Setup(repo => repo.AddAsync(testDebugEventLog)).ReturnsAsync(testDebugEventLog); //Act await _debugEventLogService.DebugEventLog(testEventLog); //Assert _mockDebugEventLogRepository.Verify(x => x.AddAsync(It.IsAny()), Times.Once); } [Fact] public async Task DebugEventLog_Verify_AddAsyncCalled_Never() { // Arrange var testEventLog = new EventLog() { }; _mockDebugEventLogRepository.Setup(repo => repo.AddAsync(It.IsAny())).ReturnsAsync(new DebugEventLog()); var testDebugEventLog = new DebugEventLog(); //Act await _debugEventLogService.DebugEventLog(testEventLog); //Assert _mockDebugEventLogRepository.Verify(x => x.AddAsync(testDebugEventLog), Times.Never); } }