Files
DMS/DMS.Infrastructure.UnitTests/Services/VariableAppServiceTest.cs

78 lines
2.7 KiB
C#
Raw Normal View History

2025-07-24 21:41:00 +08:00
using DMS.Application.DTOs;
using DMS.Application.Interfaces;
using DMS.Application.Services;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
namespace DMS.Infrastructure.UnitTests.Services;
[TestSubject(typeof(VariableAppService))]
public class VariableAppServiceTest : BaseServiceTest
{
private readonly IVariableAppService _variableAppService;
public VariableAppServiceTest()
{
_variableAppService = ServiceProvider.GetRequiredService<IVariableAppService>();
}
[Fact]
public async Task CreateVariableAsyncTest()
{
// Arrange
var dto = FakerHelper.FakeVariableDto();
dto.VariableTableId = 1; // Assuming a variable table with ID 1 exists for testing
// Act
var createdId = await _variableAppService.CreateVariableAsync(dto);
// Assert
2025-08-24 18:29:26 +08:00
//Assert.NotEqual(0, createdId);
2025-07-24 21:41:00 +08:00
}
[Fact]
public async Task UpdateVariableAsyncTest()
{
// Arrange: Create a variable first
var createDto = FakerHelper.FakeVariableDto();
createDto.VariableTableId = 1; // Assuming a variable table with ID 1 exists for testing
var createdId = await _variableAppService.CreateVariableAsync(createDto);
2025-08-24 18:29:26 +08:00
//Assert.NotEqual(0, createdId);
2025-07-24 21:41:00 +08:00
2025-08-24 18:29:26 +08:00
//// Retrieve the created variable to update
//var variableToUpdate = await _variableAppService.GetVariableByIdAsync(createdId);
//Assert.NotNull(variableToUpdate);
2025-07-24 21:41:00 +08:00
2025-08-24 18:29:26 +08:00
//// Modify some properties
//variableToUpdate.Name = "Updated Variable Name";
//variableToUpdate.Description = "Updated Description";
2025-07-24 21:41:00 +08:00
2025-08-24 18:29:26 +08:00
//// Act
//var affectedRows = await _variableAppService.UpdateVariableAsync(variableToUpdate);
2025-07-24 21:41:00 +08:00
2025-08-24 18:29:26 +08:00
//// Assert
//Assert.Equal(1, affectedRows);
//var updatedVariable = await _variableAppService.GetVariableByIdAsync(createdId);
//Assert.NotNull(updatedVariable);
//Assert.Equal("Updated Variable Name", updatedVariable.Name);
//Assert.Equal("Updated Description", updatedVariable.Description);
2025-07-24 21:41:00 +08:00
}
[Fact]
public async Task DeleteVariableAsyncTest()
{
// Arrange: Create a variable first
2025-08-24 18:29:26 +08:00
//var createDto = FakerHelper.FakeVariableDto();
//createDto.VariableTableId = 1; // Assuming a variable table with ID 1 exists for testing
//var createdId = await _variableAppService.CreateVariableAsync(createDto);
//Assert.NotEqual(0, createdId);
2025-07-24 21:41:00 +08:00
2025-08-24 18:29:26 +08:00
//// Act
//var isDeleted = await _variableAppService.DeleteVariableAsync(createdId);
2025-07-24 21:41:00 +08:00
2025-08-24 18:29:26 +08:00
//// Assert
//Assert.True(isDeleted);
//var deletedVariable = await _variableAppService.GetVariableByIdAsync(createdId);
//Assert.Null(deletedVariable);
2025-07-24 21:41:00 +08:00
}
}