Adding MaidBotApi

This commit is contained in:
Zeeshaun
2026-03-11 13:21:47 -05:00
parent f3cb730f3b
commit f004c8205a
122 changed files with 4227 additions and 0 deletions
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
using LCU.Api.Internal.MaidBotApi.Services;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.API.Internal.MaidBotApi.Controllers;
namespace LCU.Api.Internal.MaidBotTests.ControllerTests;
public class LoggingMatrixControllerTest
{
private readonly LoggingMatrixController _loggingMatrixController;
private readonly Mock<ILoggingMatrixService> _mockLoggingMatrixService;
public LoggingMatrixControllerTest()
{
_mockLoggingMatrixService = new Mock<ILoggingMatrixService>();
_loggingMatrixController = new LoggingMatrixController(_mockLoggingMatrixService.Object);
}
[Fact]
public async void GetAllLoggingMatrix_Success_200()
{
// Arrange
_mockLoggingMatrixService.Setup(service => service.GetAsync()).ReturnsAsync(new List<LoggingMatrix>
{
new LoggingMatrix(),
new LoggingMatrix()
});
// Act
var result = await _loggingMatrixController.Get();
// Assert
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.NotNull(okResult.Value);
var extractedValue = okResult.Value as IEnumerable<LoggingMatrix>;
Assert.NotNull(extractedValue);
Assert.Equal(2, extractedValue.Count());
}
[Fact]
public async void GetAllLoggingMatrix_BsaCorrectionServiceThrowsError_500()
{
// Arrange
_mockLoggingMatrixService.Setup(service => service.GetAsync()).ThrowsAsync(new Exception());
// Act
var result = await _loggingMatrixController.Get();
// Assert
Assert.NotNull(result);
var okResult = result as StatusCodeResult;
Assert.NotNull(okResult);
Assert.Equal(StatusCodes.Status500InternalServerError, okResult.StatusCode);
}
[Fact]
public async void PostLoggingMatrix_LoggingMatrixReturnsNull_BadRequest400()
{
var loggingMatrix = new LoggingMatrix() { };
_mockLoggingMatrixService.Setup(service => service.SaveAsync(loggingMatrix)).ReturnsAsync(() => null);
// Act
var result = await _loggingMatrixController.Post(loggingMatrix);
// Assert
Assert.NotNull(result);
var okResult = result as ObjectResult;
Assert.NotNull(okResult);
Assert.Equal(StatusCodes.Status400BadRequest, okResult.StatusCode);
}
[Fact]
public async void PostLoggingMatrix_throwsException_500()
{
var loggingMatrix = new LoggingMatrix() { };
_mockLoggingMatrixService.Setup(service => service.SaveAsync(loggingMatrix)).Throws(new Exception("Exception from unit test"));
// Act
var result = await _loggingMatrixController.Post(loggingMatrix);
// Assert
Assert.NotNull(result);
var okResult = result as StatusCodeResult;
Assert.NotNull(okResult);
Assert.Equal(StatusCodes.Status500InternalServerError, okResult.StatusCode);
}
[Fact]
public async void PutLoggingMatrix_BadRequestIdEqualZero_400()
{
var loggingMatrix = new LoggingMatrix
{
LoggingMatrixId = 0
};
// Act
var result = await _loggingMatrixController.Put(loggingMatrix);
// Assert
Assert.NotNull(result);
var returnedResult = result as BadRequestObjectResult;
Assert.NotNull(returnedResult);
Assert.Equal(StatusCodes.Status400BadRequest, returnedResult.StatusCode);
}
[Fact]
public async void PutLoggingMatrix_ThrowsException_500()
{
var loggingMatrix = new LoggingMatrix
{
LoggingMatrixId = 1
};
_mockLoggingMatrixService.Setup(service => service.UpdateAsync(loggingMatrix)).Throws(new Exception("Exception from update unit test"));
// Act
var result = await _loggingMatrixController.Put(loggingMatrix);
// Assert
Assert.NotNull(result);
var okResult = result as StatusCodeResult;
Assert.NotNull(okResult);
Assert.Equal(StatusCodes.Status500InternalServerError, okResult.StatusCode);
}
}
@@ -0,0 +1,39 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
using LCU.Api.Internal.MaidBotApi.Services;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.API.Internal.MaidBotApi.Controllers;
namespace LCU.Api.Internal.MaidBotTests.ControllerTests;
public class QueueEventLogControllerTest
{
private readonly QueueEventLogController _queueEventLogController;
private readonly Mock<IQueueEventLogService> _mockQueueEventLogService;
public QueueEventLogControllerTest()
{
_mockQueueEventLogService = new Mock<IQueueEventLogService>();
_queueEventLogController = new QueueEventLogController(_mockQueueEventLogService.Object);
}
[Fact]
public async Task PostLoggingMatrix_throwsException_500()
{
var eventLog = new EventLog() { };
_mockQueueEventLogService.Setup(service => service.QueueEventLog(eventLog)).Throws(new Exception("Exception from unit test"));
// Act
var result = await _queueEventLogController.Post(eventLog);
// Assert
Assert.NotNull(result);
var okResult = result as StatusCodeResult;
Assert.NotNull(okResult);
Assert.Equal(StatusCodes.Status500InternalServerError, okResult.StatusCode);
}
}