Adding tests

This commit is contained in:
2025-03-28 22:15:39 +01:00
parent d52c385e7c
commit 366962abfa
13 changed files with 271 additions and 16 deletions

View File

@@ -805,6 +805,52 @@ public class RoleController_Tests
}
}
[TestMethod]
public async Task UpdateRoleAsync_NotEditable()
{
if (_roleController == null)
{
Assert.Fail($"_roleController is null");
}
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
role.IsNotEditable = true;
CreateRoleRequest request = new CreateRoleRequest()
{
Data = new CreateRoleRequestData()
{
Name = "RoleTest",
IsNotEditable = true
}
};
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
_roleServiceMock?.Setup(s => s.CheckIfNameIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(false);
ObjectResult response = (ObjectResult)(await _roleController.UpdateRoleAsync(request, role.Guid));
if (response != null && response.Value != null)
{
Assert.IsTrue(response.StatusCode == StatusCodes.Status400BadRequest);
var result = (BaseResponse<object>)response.Value;
if (result != null)
{
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest);
Assert.IsTrue(result.Message == "This role is not editable");
}
else
{
Assert.Fail($"Result value is null");
}
}
else
{
Assert.Fail($"Response value is null");
}
}
[TestMethod]
public async Task UpdateRoleAsync_CreateRoleRequestDataNull()
{

View File

@@ -39,7 +39,6 @@ public class RootController_Test
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex}");
}
}

View File

@@ -232,7 +232,7 @@ public class UserController_Tests
}
[TestMethod]
public async Task CreateUserAsync_Should_Return_200_When_Successful()
public async Task CreateUserAsync_Success()
{
if (_userController == null)
{

View File

@@ -68,7 +68,6 @@ public class VersionController_Tests
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex}");
}
}
@@ -80,7 +79,6 @@ public class VersionController_Tests
try
{
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
var configuration = TestUtils.CreateEmptyConfiguration(System.AppDomain.CurrentDomain.BaseDirectory + "/JsonData", "emptyAppsettings.json");
VersionController versionController = new VersionController(configuration);
var result = versionController.GetVersion();
@@ -97,7 +95,6 @@ public class VersionController_Tests
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
Assert.Fail($"An exception was thrown: {ex}");
}
}