Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c4ef564d71 | |||
| 9e95ad1cc8 | |||
| 4c3aa30cbb | |||
|
|
54a5106314 | ||
| 87adaffa3e | |||
| fa4f1c0791 | |||
| a6193c3c94 | |||
| 12b4a4d0c8 | |||
| 63fab9d827 | |||
| e1d1381a5c | |||
| 2d7db3d919 | |||
| 73043970a8 | |||
| 5c1eacd85e | |||
| e03db76496 | |||
| 1fc8e6cc1c | |||
| 8bc50f8135 | |||
| e1a249c07a | |||
| 8986e3d77e | |||
| 56a7e76785 | |||
| 061ce4cb3d | |||
| 11a9696bdd | |||
| ad1909ef57 | |||
| 1877c29e68 | |||
| 14d9b45413 | |||
| a4b8458542 | |||
|
|
c950556104 | ||
| 118a9bb6e4 | |||
| a3938fa5f0 | |||
| ca8fd67428 | |||
| fbd09b56c8 | |||
|
|
79549bea05 | ||
|
|
ac20664446 |
15
.editorconfig
Normal file
15
.editorconfig
Normal file
@@ -0,0 +1,15 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Core EditorConfig properties
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
csharp_prefer_braced_block = true:suggestion
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
|
||||
15
.github/dependabot.yml
vendored
Normal file
15
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "nuget"
|
||||
directory: "/MainProject"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
open-pull-requests-limit: 5
|
||||
target-branch: "main"
|
||||
|
||||
- package-ecosystem: "nuget"
|
||||
directory: "/MainProject.Tests"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
open-pull-requests-limit: 5
|
||||
target-branch: "main"
|
||||
31
MainProject.Tests/Config/invalid-permissions.json
Normal file
31
MainProject.Tests/Config/invalid-permissions.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"PermissionInfos": [
|
||||
{
|
||||
"System": "base",
|
||||
"RolePermissionModuleOperations": [
|
||||
{
|
||||
"Module": "roles",
|
||||
"Operations": [
|
||||
{ "Operation": "create", "Roles": [] },
|
||||
{ "Operation": "read", "Roles": [] },
|
||||
{ "Operation": "update", "Roles": [] },
|
||||
{ "Operation": "delete", "Roles": [] },
|
||||
{ "Operation": "list", "Roles": [] },
|
||||
{ "Operation": "use", "Roles": [] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"Module": "users",
|
||||
"Operations": [
|
||||
{ "Operation": "create", "Roles": [] },
|
||||
{ "Operation": "read", "Roles": [] },
|
||||
{ "Operation": "update", "Roles": [] },
|
||||
{ "Operation": "delete", "Roles": [] },
|
||||
{ "Operation": "list", "Roles": [] },
|
||||
{ "Operation": "use", "Roles": [] }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
]
|
||||
}
|
||||
31
MainProject.Tests/Config/permissions.json
Normal file
31
MainProject.Tests/Config/permissions.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"PermissionInfos": [
|
||||
{
|
||||
"System": "base",
|
||||
"RolePermissionModuleOperations": [
|
||||
{
|
||||
"Module": "roles",
|
||||
"Operations": [
|
||||
{ "Operation": "create", "Roles": ["Admin"] },
|
||||
{ "Operation": "read", "Roles": [] },
|
||||
{ "Operation": "update", "Roles": ["Admin"] },
|
||||
{ "Operation": "delete", "Roles": ["Admin"] },
|
||||
{ "Operation": "list", "Roles": [] },
|
||||
{ "Operation": "use", "Roles": [] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"Module": "users",
|
||||
"Operations": [
|
||||
{ "Operation": "create", "Roles": [] },
|
||||
{ "Operation": "read", "Roles": [] },
|
||||
{ "Operation": "update", "Roles": [] },
|
||||
{ "Operation": "delete", "Roles": [] },
|
||||
{ "Operation": "list", "Roles": [] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
@@ -61,12 +61,12 @@ public class AuthController_Tests
|
||||
ObjectResult response = (ObjectResult)(await controller.AuthenticateAsync(request));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(AuthenticatedUser));
|
||||
}
|
||||
else
|
||||
@@ -81,42 +81,6 @@ public class AuthController_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AuthenticateAsync_AuthenticateRequestDataNull()
|
||||
{
|
||||
IConfiguration configuration = TestUtils.CreateConfiguration();
|
||||
var authServiceMock = new Mock<IAuthService>();
|
||||
var controller = new AuthController(configuration, authServiceMock.Object);
|
||||
|
||||
var request = new AuthenticateRequest
|
||||
{
|
||||
Data = null
|
||||
};
|
||||
AuthenticatedUser? authenticatedUser = null;
|
||||
authServiceMock.Setup(s => s.AuthenticateAsync(It.IsAny<AuthenticateRequestData>())).ReturnsAsync(authenticatedUser);
|
||||
ObjectResult response = (ObjectResult)(await controller.AuthenticateAsync(request));
|
||||
|
||||
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 == "Request is not well formed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AuthenticateAsync_NotFound()
|
||||
{
|
||||
@@ -140,46 +104,7 @@ public class AuthController_Tests
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status404NotFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AuthenticateAsync_ModelInvalid()
|
||||
{
|
||||
IConfiguration configuration = TestUtils.CreateConfiguration();
|
||||
var authServiceMock = new Mock<IAuthService>();
|
||||
var controller = new AuthController(configuration, authServiceMock.Object);
|
||||
|
||||
var request = new AuthenticateRequest
|
||||
{
|
||||
Data = null
|
||||
};
|
||||
AuthenticatedUser? authenticatedUser = null;
|
||||
authServiceMock.Setup(s => s.AuthenticateAsync(It.IsAny<AuthenticateRequestData>())).ReturnsAsync(authenticatedUser);
|
||||
controller.ModelState.AddModelError("Data", "Invalid data");
|
||||
ObjectResult response = (ObjectResult)(await controller.AuthenticateAsync(request));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
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 == "Request is not well formed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -207,13 +132,13 @@ public class AuthController_Tests
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status500InternalServerError);
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError);
|
||||
Assert.IsTrue(result.Message == "Something went wrong. Unexpected error");
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
670
MainProject.Tests/Controllers/RoleController_Tests.cs
Normal file
670
MainProject.Tests/Controllers/RoleController_Tests.cs
Normal file
@@ -0,0 +1,670 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Moq;
|
||||
using BasicDotnetTemplate.MainProject.Controllers;
|
||||
using BasicDotnetTemplate.MainProject.Services;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Role;
|
||||
using DatabaseSqlServer = BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Request.Role;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.Role;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class RoleController_Tests
|
||||
{
|
||||
private Mock<IRoleService>? _roleServiceMock;
|
||||
private RoleController? _roleController;
|
||||
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
IConfiguration configuration = TestUtils.CreateConfiguration();
|
||||
_roleServiceMock = new Mock<IRoleService>();
|
||||
_roleController = new RoleController(configuration, _roleServiceMock.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RoleController_NullConfiguration()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
var exception = true;
|
||||
try
|
||||
{
|
||||
var roleServiceMock = new Mock<IRoleService>();
|
||||
_ = new RoleController(null, roleServiceMock.Object);
|
||||
exception = false;
|
||||
Assert.Fail($"This test should not pass as configuration is null");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.IsTrue(exception);
|
||||
}
|
||||
}
|
||||
|
||||
#region "GET"
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetRoleByGuidAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
ObjectResult response = (ObjectResult)(await _roleController.GetRoleByGuidAsync(guid));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(RoleDto));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetRoleByGuidAsync_NotFound()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.Role? role = null;
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
NotFoundResult response = (NotFoundResult)(await _roleController.GetRoleByGuidAsync(guid));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(NotFoundResult));
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetRoleByGuidAsync_Exception()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Unexpected error"));
|
||||
ObjectResult response = (ObjectResult)(await _roleController.GetRoleByGuidAsync(guid));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "CREATE"
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateRoleAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
if (_roleServiceMock == null)
|
||||
{
|
||||
Assert.Fail($"_roleServiceMock is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
CreateRoleRequest request = new CreateRoleRequest()
|
||||
{
|
||||
Data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "RoleTest",
|
||||
IsNotEditable = true
|
||||
}
|
||||
};
|
||||
|
||||
_roleServiceMock?.Setup(s => s.CheckIfNameIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(true);
|
||||
_roleServiceMock?.Setup(s => s.CreateRoleAsync(request.Data)).ReturnsAsync(role);
|
||||
|
||||
ObjectResult response = (ObjectResult)(await _roleController.CreateRoleAsync(request));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(RoleDto));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateRoleAsync_InvalidName()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
CreateRoleRequest request = new CreateRoleRequest()
|
||||
{
|
||||
Data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "RoleTest",
|
||||
IsNotEditable = true
|
||||
}
|
||||
};
|
||||
|
||||
_roleServiceMock?.Setup(s => s.CheckIfNameIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(false);
|
||||
|
||||
ObjectResult response = (ObjectResult)(await _roleController.CreateRoleAsync(request));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Invalid name", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateRoleAsync_NotCreated()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
if (_roleServiceMock == null)
|
||||
{
|
||||
Assert.Fail($"_roleServiceMock is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
DatabaseSqlServer.Role? expectedRole = null;
|
||||
|
||||
CreateRoleRequest request = new CreateRoleRequest()
|
||||
{
|
||||
Data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "RoleTest",
|
||||
IsNotEditable = true
|
||||
}
|
||||
};
|
||||
|
||||
_roleServiceMock?.Setup(s => s.CheckIfNameIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(true);
|
||||
_roleServiceMock?.Setup(s => s.CreateRoleAsync(request.Data)).ReturnsAsync(expectedRole);
|
||||
|
||||
ObjectResult response = (ObjectResult)(await _roleController.CreateRoleAsync(request));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Not created", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateRoleAsync_Exception()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
if (_roleServiceMock == null)
|
||||
{
|
||||
Assert.Fail($"_roleServiceMock is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
CreateRoleRequest request = new CreateRoleRequest()
|
||||
{
|
||||
Data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "RoleTest",
|
||||
IsNotEditable = true
|
||||
}
|
||||
};
|
||||
|
||||
_roleServiceMock?.Setup(s => s.CheckIfNameIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(true);
|
||||
_roleServiceMock?.Setup(s => s.CreateRoleAsync(
|
||||
It.IsAny<CreateRoleRequestData>()
|
||||
)).ThrowsAsync(new Exception("Unexpected error"));
|
||||
|
||||
ObjectResult response = (ObjectResult)(await _roleController.CreateRoleAsync(request));
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "DELETE"
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleByGuidAsync_Success()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
ObjectResult response = (ObjectResult)(await _roleController.DeleteRoleByGuidAsync(guid));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleByGuidAsync_NotFound()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.Role? role = null;
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
NotFoundResult response = (NotFoundResult)(await _roleController.DeleteRoleByGuidAsync(guid));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(NotFoundResult));
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleByGuidAsync_Exception()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Unexpected error"));
|
||||
ObjectResult response = (ObjectResult)(await _roleController.DeleteRoleByGuidAsync(guid));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "UPDATE"
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
if (_roleServiceMock == null)
|
||||
{
|
||||
Assert.Fail($"_roleServiceMock is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
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(true);
|
||||
_roleServiceMock?.Setup(s => s.UpdateRoleAsync(It.IsAny<CreateRoleRequestData>(), It.IsAny<Role>())).ReturnsAsync(role);
|
||||
|
||||
ObjectResult response = (ObjectResult)(await _roleController.UpdateRoleAsync(request, role.Guid));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(RoleDto));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_RoleNotFound()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role? role = null;
|
||||
|
||||
CreateRoleRequest request = new CreateRoleRequest()
|
||||
{
|
||||
Data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "RoleTest",
|
||||
IsNotEditable = true
|
||||
}
|
||||
};
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
|
||||
NotFoundResult response = (NotFoundResult)(await _roleController.UpdateRoleAsync(request, Guid.NewGuid().ToString()));
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_InvalidName()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
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.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Invalid name", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[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.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("This role is not editable", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_Exception()
|
||||
{
|
||||
if (_roleController == null)
|
||||
{
|
||||
Assert.Fail($"_roleController is null");
|
||||
}
|
||||
|
||||
if (_roleServiceMock == null)
|
||||
{
|
||||
Assert.Fail($"_roleServiceMock is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
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(true);
|
||||
_roleServiceMock?.Setup(s => s.UpdateRoleAsync(
|
||||
It.IsAny<CreateRoleRequestData>(), It.IsAny<Role>()
|
||||
)).ThrowsAsync(new Exception("Unexpected error"));
|
||||
|
||||
ObjectResult response = (ObjectResult)await _roleController.UpdateRoleAsync(request, role.Guid);
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class RootController_Test
|
||||
if (result != null)
|
||||
{
|
||||
var data = (OkResult)result;
|
||||
Assert.IsTrue(data.StatusCode == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, data.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -39,7 +39,6 @@ public class RootController_Test
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UserControllerTests
|
||||
public class UserController_Tests
|
||||
{
|
||||
private Mock<IUserService>? _userServiceMock;
|
||||
private Mock<IRoleService>? _roleServiceMock;
|
||||
@@ -43,7 +43,7 @@ public class UserControllerTests
|
||||
IConfiguration configuration = TestUtils.CreateConfiguration();
|
||||
_userServiceMock = new Mock<IUserService>();
|
||||
_roleServiceMock = new Mock<IRoleService>();
|
||||
_userController = new UserController(configuration, _userServiceMock?.Object, _roleServiceMock.Object);
|
||||
_userController = new UserController(configuration, _userServiceMock.Object, _roleServiceMock.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -66,6 +66,7 @@ public class UserControllerTests
|
||||
}
|
||||
|
||||
|
||||
#region "GET"
|
||||
[TestMethod]
|
||||
public async Task GetUserByGuidAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
@@ -80,12 +81,12 @@ public class UserControllerTests
|
||||
ObjectResult response = (ObjectResult)(await _userController.GetUserByGuidAsync(guid));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(UserDto));
|
||||
}
|
||||
else
|
||||
@@ -99,41 +100,6 @@ public class UserControllerTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserByGuidAsync_AuthenticateRequestDataNull()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
var guid = String.Empty;
|
||||
DatabaseSqlServer.User? user = null;
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
ObjectResult response = (ObjectResult)(await _userController.GetUserByGuidAsync(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 == "Request is not well formed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserByGuidAsync_NotFound()
|
||||
{
|
||||
@@ -151,44 +117,7 @@ public class UserControllerTests
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status404NotFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserByGuidAsync_ModelInvalid()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.User? user = null;
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userController.ModelState.AddModelError("Data", "Invalid data");
|
||||
ObjectResult response = (ObjectResult)(await _userController.GetUserByGuidAsync(guid));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
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 == "Request is not well formed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -212,13 +141,13 @@ public class UserControllerTests
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status500InternalServerError);
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError);
|
||||
Assert.IsTrue(result.Message == "Something went wrong. Unexpected error");
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -231,8 +160,12 @@ public class UserControllerTests
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "CREATE"
|
||||
[TestMethod]
|
||||
public async Task CreateUserAsync_Should_Return_200_When_Successful()
|
||||
public async Task CreateUserAsync_Success()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
@@ -265,12 +198,12 @@ public class UserControllerTests
|
||||
ObjectResult response = (ObjectResult)(await _userController.CreateUserAsync(request));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status200OK);
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(UserDto));
|
||||
}
|
||||
else
|
||||
@@ -311,13 +244,13 @@ public class UserControllerTests
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status400BadRequest);
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest);
|
||||
Assert.IsTrue(result.Message == "Invalid email");
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Invalid email", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -362,58 +295,13 @@ public class UserControllerTests
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status400BadRequest);
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest);
|
||||
Assert.IsTrue(result.Message == "Role not found");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateUserAsync_CreateUserRequestDataNull()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
CreateUserRequest request = new CreateUserRequest()
|
||||
{
|
||||
Data = null
|
||||
};
|
||||
|
||||
_userServiceMock?.Setup(s => s.CheckIfEmailIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(true);
|
||||
|
||||
_userServiceMock?.Setup(s => s.CreateUserAsync(
|
||||
It.IsAny<CreateUserRequestData>(),
|
||||
It.IsAny<Role>()
|
||||
)).ReturnsAsync(user);
|
||||
|
||||
ObjectResult response = (ObjectResult)(await _userController.CreateUserAsync(request));
|
||||
|
||||
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 == "Request is not well formed");
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Role not found", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -462,13 +350,13 @@ public class UserControllerTests
|
||||
ObjectResult response = (ObjectResult)(await _userController.CreateUserAsync(request));
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status400BadRequest);
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status400BadRequest);
|
||||
Assert.IsTrue(result.Message == "Not created");
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Not created", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -481,59 +369,6 @@ public class UserControllerTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateUserAsync_ModelInvalid()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
CreateUserRequest request = new CreateUserRequest()
|
||||
{
|
||||
Data = new CreateUserRequestData()
|
||||
{
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Email = user.Email,
|
||||
Password = user.Password
|
||||
}
|
||||
};
|
||||
|
||||
_userServiceMock?.Setup(s => s.CheckIfEmailIsValid(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(true);
|
||||
|
||||
_userServiceMock?.Setup(s => s.CreateUserAsync(
|
||||
It.IsAny<CreateUserRequestData>(),
|
||||
It.IsAny<Role>()
|
||||
)).ReturnsAsync(user);
|
||||
_userController.ModelState.AddModelError("Data", "Invalid data");
|
||||
ObjectResult response = (ObjectResult)(await _userController.CreateUserAsync(request));
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
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 == "Request is not well formed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateUserAsync_Exception()
|
||||
{
|
||||
@@ -576,13 +411,13 @@ public class UserControllerTests
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == StatusCodes.Status500InternalServerError);
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == StatusCodes.Status500InternalServerError);
|
||||
Assert.IsTrue(result.Message == "Something went wrong. Unexpected error");
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -594,4 +429,479 @@ public class UserControllerTests
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "DELETE"
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleByGuidAsync_Success()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
ObjectResult response = (ObjectResult)await _userController.DeleteUserByGuidAsync(guid);
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleByGuidAsync_NotFound()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
DatabaseSqlServer.User? user = null;
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
NotFoundResult response = (NotFoundResult)await _userController.DeleteUserByGuidAsync(guid);
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(NotFoundResult));
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleByGuidAsync_Exception()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Unexpected error"));
|
||||
ObjectResult response = (ObjectResult)await _userController.DeleteUserByGuidAsync(guid);
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "UPDATE"
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
UpdateUserRequest request = new UpdateUserRequest()
|
||||
{
|
||||
Data = new UpdateUserRequestData()
|
||||
{
|
||||
FirstName = "NewFirstName",
|
||||
LastName = "NewLastName"
|
||||
}
|
||||
};
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserAsync(It.IsAny<UpdateUserRequestData>(), It.IsAny<User>())).ReturnsAsync(user);
|
||||
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserAsync(request, user.Guid);
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(UserDto));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserAsync_UserNotFound()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User? user = null;
|
||||
|
||||
UpdateUserRequest request = new UpdateUserRequest()
|
||||
{
|
||||
Data = new UpdateUserRequestData()
|
||||
{
|
||||
FirstName = "NewFirstName",
|
||||
LastName = "NewLastName"
|
||||
}
|
||||
};
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
NotFoundResult response = (NotFoundResult)await _userController.UpdateUserAsync(request, Guid.NewGuid().ToString());
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserAsync_Exception()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
UpdateUserRequest request = new UpdateUserRequest()
|
||||
{
|
||||
Data = new UpdateUserRequestData()
|
||||
{
|
||||
FirstName = "NewFirstName",
|
||||
LastName = "NewLastName"
|
||||
}
|
||||
};
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserAsync(
|
||||
It.IsAny<UpdateUserRequestData>(), It.IsAny<User>()
|
||||
)).ThrowsAsync(new Exception("Unexpected error"));
|
||||
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserAsync(request, user.Guid);
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserPasswordAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
string newPassword = "This!s4T3stP4ssw0rd#";
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserPasswordAsync(It.IsAny<User>(), newPassword)).ReturnsAsync(user);
|
||||
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserPasswordAsync(user.Guid, newPassword);
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(UserDto));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserPasswordAsync_UserNotFound()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User? user = null;
|
||||
|
||||
string newPassword = "This!s4T3stP4ssw0rd#";
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
|
||||
NotFoundResult response = (NotFoundResult)await _userController.UpdateUserPasswordAsync(Guid.NewGuid().ToString(), newPassword);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserPasswordAsync_Exception()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
|
||||
string newPassword = "This!s4T3stP4ssw0rd#";
|
||||
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserPasswordAsync(
|
||||
It.IsAny<User>(), It.IsAny<string>()
|
||||
)).ThrowsAsync(new Exception("Unexpected error"));
|
||||
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserPasswordAsync(user.Guid, newPassword);
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserRoleAsync_Should_Return_200_When_Successful()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
if(_roleServiceMock == null)
|
||||
{
|
||||
Assert.Fail($"_roleServiceMock is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserRoleAsync(It.IsAny<User>(), It.IsAny<Role>())).ReturnsAsync(user);
|
||||
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserRoleAsync(user.Guid, role.Guid);
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status200OK, result.Status);
|
||||
Assert.IsInstanceOfType(result.Data, typeof(UserDto));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response value is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserPasswordAsync_RoleNotFound()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
DatabaseSqlServer.Role? role = null;
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserRoleAsync(user.Guid, Guid.NewGuid().ToString());
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
|
||||
Assert.IsNotNull(response.Value);
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status400BadRequest, result.Status);
|
||||
Assert.AreEqual("Role not found", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserRoleAsync_UserNotFound()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User? user = null;
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserRoleAsync(It.IsAny<User>(), It.IsAny<Role>())).ReturnsAsync(user);
|
||||
|
||||
NotFoundResult response = (NotFoundResult)await _userController.UpdateUserRoleAsync(Guid.NewGuid().ToString(), role.Guid);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status404NotFound, response.StatusCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserRoleAsync_Exception()
|
||||
{
|
||||
if (_userController == null)
|
||||
{
|
||||
Assert.Fail($"_userController is null");
|
||||
}
|
||||
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
|
||||
_roleServiceMock?.Setup(s => s.GetRoleByGuidAsync(It.IsAny<string>())).ReturnsAsync(role);
|
||||
_userServiceMock?.Setup(s => s.GetUserByGuidAsync(It.IsAny<string>())).ReturnsAsync(user);
|
||||
_userServiceMock?.Setup(s => s.UpdateUserRoleAsync(
|
||||
It.IsAny<User>(), It.IsAny<Role>()
|
||||
)).ThrowsAsync(new Exception("Unexpected error"));
|
||||
|
||||
ObjectResult response = (ObjectResult)await _userController.UpdateUserRoleAsync(user.Guid, role.Guid);
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if (response != null && response.Value != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, response.StatusCode);
|
||||
|
||||
var result = (BaseResponse<object>)response.Value;
|
||||
if (result != null)
|
||||
{
|
||||
Assert.AreEqual(StatusCodes.Status500InternalServerError, result.Status);
|
||||
Assert.AreEqual("Something went wrong. Unexpected error", result.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,4 +143,4 @@ public class JwtAuthorizationAttribute_Tests
|
||||
Assert.IsNotInstanceOfType(context.Result, typeof(UnauthorizedResult));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
135
MainProject.Tests/Core/Filters/ValidationActionFilter_Tests.cs
Normal file
135
MainProject.Tests/Core/Filters/ValidationActionFilter_Tests.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.User;
|
||||
using DatabaseSqlServer = BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using BasicDotnetTemplate.MainProject.Core.Attributes;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using BasicDotnetTemplate.MainProject.Core.Filters;
|
||||
using Newtonsoft.Json;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Base;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class ValidationActionFilter_Tests
|
||||
{
|
||||
private readonly string _requestNotWellFormedMessage = "Request is not well formed";
|
||||
|
||||
private static ActionExecutingContext CreateContext(ModelStateDictionary modelState, object? requestBody = null)
|
||||
{
|
||||
var actionContext = new ActionContext(
|
||||
new DefaultHttpContext(),
|
||||
new Microsoft.AspNetCore.Routing.RouteData(),
|
||||
new Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor(),
|
||||
modelState
|
||||
);
|
||||
var actionArguments = new Dictionary<string, object?>();
|
||||
|
||||
if (requestBody != null)
|
||||
{
|
||||
actionArguments.Add("request", requestBody);
|
||||
}
|
||||
return new ActionExecutingContext(
|
||||
actionContext,
|
||||
[],
|
||||
actionArguments,
|
||||
new Mock<Controller>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OnActionExecutionAsync_ModelStateInvalid_ReturnsBadRequestAndDoesNotCallNext()
|
||||
{
|
||||
// Arrange
|
||||
var modelState = new ModelStateDictionary();
|
||||
modelState.AddModelError("MissingProperty", "MissingProperty is required");
|
||||
var context = CreateContext(modelState, new { SomeProp = "Value" });
|
||||
var nextCalled = false;
|
||||
ActionExecutionDelegate next = () => {
|
||||
nextCalled = true;
|
||||
return Task.FromResult(new ActionExecutedContext(context, [], new Mock<Controller>().Object));
|
||||
};
|
||||
var filter = new ValidationActionFilter();
|
||||
// Act
|
||||
filter.OnActionExecutionAsync(context, next).GetAwaiter().GetResult();
|
||||
// Assert
|
||||
Assert.IsNotNull(context.Result);
|
||||
var badRequestResult = context.Result as BadRequestObjectResult;
|
||||
Assert.IsNotNull(badRequestResult);
|
||||
Assert.IsNotNull(badRequestResult!.Value);
|
||||
|
||||
ValidationError validationError = (ValidationError)badRequestResult.Value;
|
||||
Assert.AreEqual(_requestNotWellFormedMessage, validationError?.Message);
|
||||
Assert.IsNotNull(validationError?.Errors);
|
||||
Assert.IsFalse(modelState.IsValid);
|
||||
Assert.IsFalse(nextCalled);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OnActionExecutionAsync_ModelStateValid_RequestBodyNull_ReturnsBadRequestAndDoesNotCallNext()
|
||||
{
|
||||
|
||||
var modelState = new ModelStateDictionary();
|
||||
|
||||
var context = CreateContext(modelState, null);
|
||||
var nextCalled = false;
|
||||
ActionExecutionDelegate next = () => {
|
||||
nextCalled = true;
|
||||
return Task.FromResult(new ActionExecutedContext(context, [], new Mock<Controller>().Object));
|
||||
};
|
||||
var filter = new ValidationActionFilter();
|
||||
// Act
|
||||
filter.OnActionExecutionAsync(context, next).GetAwaiter().GetResult();
|
||||
// Assert
|
||||
Assert.IsNotNull(context.Result);
|
||||
var badRequestResult = context.Result as BadRequestObjectResult;
|
||||
Assert.IsNotNull(badRequestResult);
|
||||
Assert.IsNotNull(badRequestResult!.Value);
|
||||
|
||||
ValidationError validationError = (ValidationError)badRequestResult.Value;
|
||||
Assert.AreEqual(_requestNotWellFormedMessage, validationError?.Message);
|
||||
Assert.IsNull(validationError?.Errors);
|
||||
Assert.IsTrue(modelState.IsValid);
|
||||
Assert.IsFalse(nextCalled);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void OnActionExecutionAsync_ModelStateValid_RequestBodyValid_CallsNextAndDoesNotSetResult()
|
||||
{
|
||||
// Arrange
|
||||
var modelState = new ModelStateDictionary();
|
||||
|
||||
var requestBody = new TestRequestBody { Value = "Test" };
|
||||
var context = CreateContext(modelState, requestBody);
|
||||
var nextCalled = false;
|
||||
ActionExecutionDelegate next = () => {
|
||||
nextCalled = true;
|
||||
return Task.FromResult(new ActionExecutedContext(context, [], new Mock<Controller>().Object));
|
||||
};
|
||||
var filter = new ValidationActionFilter();
|
||||
// Act
|
||||
filter.OnActionExecutionAsync(context, next).GetAwaiter().GetResult();
|
||||
// Assert
|
||||
Assert.IsNull(context.Result);
|
||||
Assert.IsTrue(nextCalled);
|
||||
}
|
||||
|
||||
|
||||
private class TestRequestBody
|
||||
{
|
||||
public string? Value { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,10 +40,10 @@ public class AutoMapperConfiguration_Tests
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
UserDto? data = _mapper?.Map<UserDto>(user);
|
||||
|
||||
Assert.IsTrue(data?.Guid == user.Guid);
|
||||
Assert.IsTrue(data?.FirstName == user.FirstName);
|
||||
Assert.IsTrue(data?.LastName == user.LastName);
|
||||
Assert.IsTrue(data?.Email == user.Email);
|
||||
Assert.AreEqual(user.Guid, data?.Guid);
|
||||
Assert.AreEqual(user.FirstName, data?.FirstName);
|
||||
Assert.AreEqual(user.LastName, data?.LastName);
|
||||
Assert.AreEqual(user.Email, data?.Email);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -35,8 +35,9 @@
|
||||
"ExpiredAfterMinsOfInactivity": 15
|
||||
},
|
||||
"EncryptionSettings": {
|
||||
"Salt": "S7VIidfXQf1tOQYX",
|
||||
"Pepper": ""
|
||||
"SaltKey": "S7VIidfXQf1tOQYX",
|
||||
"Salt": "u5CZAwq9vLGysC",
|
||||
"Iterations": 10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,9 @@
|
||||
"ExpiredAfterMinsOfInactivity": 15
|
||||
},
|
||||
"EncryptionSettings": {
|
||||
"Salt": "AAAAA",
|
||||
"Pepper": ""
|
||||
"SaltKey": "AAAAA",
|
||||
"Salt": "",
|
||||
"Iterations": 10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.9.3" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.9.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -29,6 +32,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="JsonData/**" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
|
||||
</ItemGroup>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Config/**" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -23,9 +23,9 @@ public class UserRole_Tests
|
||||
try
|
||||
{
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
UserRole userRole = new UserRole(role);
|
||||
UserRole userRole = new(role);
|
||||
|
||||
Assert.IsTrue(userRole.Name == role.Name);
|
||||
Assert.AreEqual(role.Name, userRole.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -33,4 +33,4 @@ public class UserRole_Tests
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ public class AuthenticatedUser_Tests
|
||||
DatabaseSqlServer.User user = ModelsInit.CreateUser();
|
||||
AuthenticatedUser authenticatedUser = new AuthenticatedUser(user);
|
||||
|
||||
Assert.IsTrue(authenticatedUser.FirstName == user.FirstName);
|
||||
Assert.IsTrue(authenticatedUser.LastName == user.LastName);
|
||||
Assert.IsTrue(authenticatedUser.Email == user.Email);
|
||||
Assert.AreEqual(user.FirstName, authenticatedUser.FirstName);
|
||||
Assert.AreEqual(user.LastName, authenticatedUser.LastName);
|
||||
Assert.AreEqual(user.Email, authenticatedUser.Email);
|
||||
Assert.IsInstanceOfType(authenticatedUser.Role, typeof(UserRole));
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -36,4 +36,4 @@ public class AuthenticatedUser_Tests
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ApiResponse_Tests
|
||||
try
|
||||
{
|
||||
var baseResponse = new BaseResponse<object>(201, null, null);
|
||||
Assert.IsFalse(baseResponse.Status == StatusCodes.Status200OK);
|
||||
Assert.AreNotEqual(StatusCodes.Status200OK, baseResponse.Status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ public class AuthenticateResponse_Tests
|
||||
try
|
||||
{
|
||||
var authenticateResponse = new AuthenticateResponse(201, null, null);
|
||||
Assert.IsFalse(authenticateResponse.Status == StatusCodes.Status200OK);
|
||||
Assert.AreNotEqual(StatusCodes.Status200OK, authenticateResponse.Status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using BasicDotnetTemplate.MainProject;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using Microsoft.Extensions.DependencyModel.Resolution;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Role;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response.Role;
|
||||
using DatabaseSqlServer = BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response.Auth;
|
||||
using BasicDotnetTemplate.MainProject.Core.Middlewares;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class GetRoleResponse_Tests
|
||||
{
|
||||
private IMapper? _mapper;
|
||||
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddProfile<AutoMapperConfiguration>();
|
||||
});
|
||||
|
||||
_mapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateGetRoleResponse_OnlyStatus_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
var getRoleResponse = new GetRoleResponse(200, null, null);
|
||||
Assert.IsTrue(getRoleResponse.Status == StatusCodes.Status200OK && String.IsNullOrEmpty(getRoleResponse.Message) && getRoleResponse.Data == null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateGetRoleResponse_OnlyStatus_IsInvalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
var getRoleResponse = new GetRoleResponse(201, null, null);
|
||||
Assert.AreNotEqual(StatusCodes.Status200OK, getRoleResponse.Status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateGetRoleResponse_StatusAndMessage_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
var getRoleResponse = new GetRoleResponse(200, "This is a test message", null);
|
||||
Assert.IsTrue(getRoleResponse.Status == StatusCodes.Status200OK && getRoleResponse.Message == "This is a test message" && getRoleResponse.Data == null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateGetRoleResponse_AllFields_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
DatabaseSqlServer.Role role = ModelsInit.CreateRole();
|
||||
RoleDto? data = _mapper?.Map<RoleDto>(role);
|
||||
var getRoleResponse = new GetRoleResponse(200, "This is a test message", data);
|
||||
Assert.IsTrue(getRoleResponse.Status == StatusCodes.Status200OK && getRoleResponse.Message == "This is a test message" && getRoleResponse.Data == data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class GetUserResponse_Tests
|
||||
try
|
||||
{
|
||||
var getUserResponse = new GetUserResponse(201, null, null);
|
||||
Assert.IsFalse(getUserResponse.Status == StatusCodes.Status200OK);
|
||||
Assert.AreNotEqual(StatusCodes.Status200OK, getUserResponse.Status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Settings_Tests
|
||||
try
|
||||
{
|
||||
var baseResponse = new BaseResponse<object>(201, null, null);
|
||||
Assert.IsFalse(baseResponse.Status == StatusCodes.Status200OK);
|
||||
Assert.AreNotEqual(StatusCodes.Status200OK, baseResponse.Status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -69,7 +69,6 @@ public class Program_Tests
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class AuthService_Tests
|
||||
if (authService != null)
|
||||
{
|
||||
var authenticatedUser = await authService.AuthenticateAsync(request.Data);
|
||||
Assert.IsTrue(authenticatedUser == null);
|
||||
Assert.IsNull(authenticatedUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -93,7 +93,7 @@ public class AuthService_Tests
|
||||
if (authService != null)
|
||||
{
|
||||
var authenticatedUser = await authService.AuthenticateAsync(request.Data);
|
||||
Assert.IsTrue(authenticatedUser == null);
|
||||
Assert.IsNull(authenticatedUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ public class JwtService_Tests
|
||||
if (jwtService != null)
|
||||
{
|
||||
var jwt = jwtService.GenerateToken(testString);
|
||||
Assert.IsTrue(jwt != null);
|
||||
Assert.IsNotNull(jwt);
|
||||
Assert.IsInstanceOfType(jwt, typeof(string));
|
||||
}
|
||||
else
|
||||
|
||||
1135
MainProject.Tests/Services/PermissionService_Tests.cs
Normal file
1135
MainProject.Tests/Services/PermissionService_Tests.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,8 @@
|
||||
using BasicDotnetTemplate.MainProject.Services;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.Role;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Newtonsoft.Json;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +64,7 @@ public class RoleService_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateRoleData()
|
||||
public async Task CreateRoleAsync_Success()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -77,8 +79,8 @@ public class RoleService_Tests
|
||||
var role = await _roleService.CreateRoleAsync(data);
|
||||
Assert.IsInstanceOfType(role, typeof(Role));
|
||||
Assert.IsNotNull(role);
|
||||
Assert.IsTrue(_expectedRole?.Name == role.Name);
|
||||
Assert.IsTrue(_expectedRole?.IsNotEditable == role.IsNotEditable);
|
||||
Assert.AreEqual(_expectedRole?.Name, role.Name);
|
||||
Assert.AreEqual(_expectedRole?.IsNotEditable, role.IsNotEditable);
|
||||
_role = role;
|
||||
}
|
||||
else
|
||||
@@ -93,6 +95,43 @@ public class RoleService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateRoleAsync_Exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRoleRequestData data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "Exception",
|
||||
IsNotEditable = false
|
||||
};
|
||||
|
||||
var exceptionRoleService = TestUtils.CreateRoleServiceException();
|
||||
|
||||
if (exceptionRoleService != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var role = await exceptionRoleService.CreateRoleAsync(data);
|
||||
Assert.Fail($"Expected exception instead of response: {role?.Guid}");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.IsInstanceOfType(exception, typeof(Exception));
|
||||
Assert.IsInstanceOfType(exception, typeof(CreateException));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"RoleService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CheckIfNameIsValid_NameCurrentRole()
|
||||
{
|
||||
@@ -149,7 +188,7 @@ public class RoleService_Tests
|
||||
{
|
||||
var role = await _roleService.GetRoleByIdAsync(_role?.Id ?? 0);
|
||||
Assert.IsNotNull(role);
|
||||
Assert.IsTrue(role.Id == _role?.Id);
|
||||
Assert.AreEqual(_role?.Id, _role?.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -172,7 +211,7 @@ public class RoleService_Tests
|
||||
{
|
||||
var role = await _roleService.GetRoleByGuidAsync(_role?.Guid ?? String.Empty);
|
||||
Assert.IsNotNull(role);
|
||||
Assert.IsTrue(role.Guid == _role?.Guid);
|
||||
Assert.AreEqual(_role?.Guid, role.Guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -195,7 +234,7 @@ public class RoleService_Tests
|
||||
{
|
||||
var role = await _roleService.GetRoleForUser(_role?.Guid);
|
||||
Assert.IsNotNull(role);
|
||||
Assert.IsTrue(role.Guid == _role?.Guid);
|
||||
Assert.AreEqual(_role?.Guid, role.Guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -224,8 +263,8 @@ public class RoleService_Tests
|
||||
var roleCreated = await _roleService.CreateRoleAsync(data);
|
||||
var role = await _roleService.GetRoleForUser(String.Empty);
|
||||
Assert.IsNotNull(role);
|
||||
Assert.IsTrue(roleCreated?.Guid == role?.Guid);
|
||||
Assert.IsTrue(role?.Name == "Default");
|
||||
Assert.AreEqual(role?.Guid, roleCreated?.Guid);
|
||||
Assert.AreEqual("Default", role?.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -261,6 +300,111 @@ public class RoleService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_Success()
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRoleRequestData data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "ChangedRoleName",
|
||||
IsNotEditable = false
|
||||
};
|
||||
|
||||
if (_roleService != null)
|
||||
{
|
||||
Assert.IsNotNull(_role);
|
||||
var role = await _roleService.UpdateRoleAsync(data, _role!);
|
||||
Assert.IsInstanceOfType(role, typeof(Role));
|
||||
Assert.IsNotNull(role);
|
||||
Assert.AreEqual(data.Name, role.Name);
|
||||
Assert.AreEqual(data.IsNotEditable, role.IsNotEditable);
|
||||
_role = role;
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"RoleService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_NotEditable()
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRoleRequestData createRoleData = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "NotEditableRole",
|
||||
IsNotEditable = true
|
||||
};
|
||||
|
||||
|
||||
if (_roleService != null)
|
||||
{
|
||||
var role = await _roleService.CreateRoleAsync(createRoleData);
|
||||
Assert.IsNotNull(role);
|
||||
|
||||
CreateRoleRequestData updateRoleData = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "TryingToEditRole",
|
||||
IsNotEditable = false
|
||||
};
|
||||
|
||||
var roleUpdatedRole = await _roleService.UpdateRoleAsync(updateRoleData, role!);
|
||||
Assert.IsInstanceOfType(roleUpdatedRole, typeof(Role));
|
||||
Assert.IsNotNull(roleUpdatedRole);
|
||||
Assert.AreEqual(createRoleData.Name, roleUpdatedRole.Name);
|
||||
Assert.AreEqual(createRoleData.IsNotEditable, roleUpdatedRole.IsNotEditable);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"RoleService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateRoleAsync_Exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRoleRequestData data = new CreateRoleRequestData()
|
||||
{
|
||||
Name = "Exception",
|
||||
IsNotEditable = false
|
||||
};
|
||||
|
||||
var exceptionRoleService = TestUtils.CreateRoleServiceException();
|
||||
|
||||
if (exceptionRoleService != null)
|
||||
{
|
||||
Assert.IsNotNull(_role);
|
||||
var role = await exceptionRoleService.UpdateRoleAsync(data, _role!);
|
||||
Assert.Fail($"Expected exception instead of response: {role?.Guid}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"RoleService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.IsInstanceOfType(ex, typeof(Exception));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteRoleAsync()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ using BasicDotnetTemplate.MainProject.Services;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.User;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Newtonsoft.Json;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -35,29 +36,6 @@ public class UserService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserByUsernameAndPassword_Null()
|
||||
{
|
||||
try
|
||||
{
|
||||
var testString = "test";
|
||||
if (_userService != null)
|
||||
{
|
||||
var user = await _userService.GetUserByUsernameAndPassword(testString, testString);
|
||||
Assert.IsTrue(user == null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CheckIfEmailIsValid_EmailNotExists()
|
||||
{
|
||||
@@ -92,7 +70,8 @@ public class UserService_Tests
|
||||
{
|
||||
FirstName = expectedUser.FirstName ?? String.Empty,
|
||||
LastName = expectedUser.LastName ?? String.Empty,
|
||||
Email = expectedUser.Email ?? String.Empty
|
||||
Email = expectedUser.Email ?? String.Empty,
|
||||
Password = "Password"
|
||||
};
|
||||
|
||||
Role role = new()
|
||||
@@ -105,10 +84,14 @@ public class UserService_Tests
|
||||
var user = await _userService.CreateUserAsync(data, role);
|
||||
Assert.IsInstanceOfType(user, typeof(User));
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsTrue(expectedUser.FirstName == user.FirstName);
|
||||
Assert.IsTrue(expectedUser.LastName == user.LastName);
|
||||
Assert.IsTrue(expectedUser.Email == user.Email);
|
||||
Assert.IsTrue(expectedUser.Role?.Name == user.Role?.Name);
|
||||
Assert.AreEqual(expectedUser.FirstName, user.FirstName);
|
||||
Assert.AreEqual(expectedUser.LastName, user.LastName);
|
||||
Assert.AreEqual(expectedUser.Email, user.Email);
|
||||
Assert.AreEqual(expectedUser.Role?.Name, user.Role?.Name);
|
||||
Assert.AreEqual(10, user.PasswordIterations);
|
||||
Assert.IsNotNull(expectedUser.PasswordSalt);
|
||||
Assert.IsNotNull(expectedUser.PasswordPepper);
|
||||
Assert.IsNotNull(expectedUser.Password);
|
||||
_user = user;
|
||||
|
||||
}
|
||||
@@ -119,6 +102,99 @@ public class UserService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserByUsernameAndPassword_Null()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_userService != null)
|
||||
{
|
||||
var user = await _userService.GetUserByUsernameAndPassword(_user.Email, "WrongPassword");
|
||||
Assert.IsNull(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserByUsernameAndPassword_Success()
|
||||
{
|
||||
try
|
||||
{
|
||||
var password = "Password";
|
||||
if (_userService != null)
|
||||
{
|
||||
var user = await _userService.GetUserByUsernameAndPassword(_user.Email, password);
|
||||
Assert.IsNotNull(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CreateUserAsync_Exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
var expectedUser = ModelsInit.CreateUser();
|
||||
|
||||
CreateUserRequestData data = new CreateUserRequestData()
|
||||
{
|
||||
FirstName = expectedUser.FirstName ?? String.Empty,
|
||||
LastName = expectedUser.LastName ?? String.Empty,
|
||||
Email = expectedUser.Email ?? String.Empty,
|
||||
Password = expectedUser.Password ?? String.Empty
|
||||
};
|
||||
|
||||
Role role = new()
|
||||
{
|
||||
Name = expectedUser.Role?.Name ?? String.Empty,
|
||||
IsNotEditable = expectedUser.Role?.IsNotEditable ?? false,
|
||||
Guid = expectedUser.Role?.Guid ?? String.Empty
|
||||
};
|
||||
|
||||
var exceptionUserService = TestUtils.CreateUserServiceException();
|
||||
|
||||
if (exceptionUserService != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await exceptionUserService.CreateUserAsync(data, role);
|
||||
Assert.Fail($"Expected exception instead of response: {user?.Guid}");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.IsInstanceOfType(exception, typeof(Exception));
|
||||
Assert.IsInstanceOfType(exception, typeof(CreateException));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CheckIfEmailIsValid_EmailCurrentUser()
|
||||
{
|
||||
@@ -175,7 +251,7 @@ public class UserService_Tests
|
||||
{
|
||||
var user = await _userService.GetUserByIdAsync(_user.Id);
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsTrue(user.Id == _user?.Id);
|
||||
Assert.AreEqual(user.Id, _user?.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -199,7 +275,7 @@ public class UserService_Tests
|
||||
{
|
||||
var user = await _userService.GetUserByGuidAsync(_user.Guid ?? String.Empty);
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsTrue(user.Guid == _user?.Guid);
|
||||
Assert.AreEqual(user.Guid, _user?.Guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -213,6 +289,186 @@ public class UserService_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserAsync_Success()
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateUserRequestData data = new UpdateUserRequestData()
|
||||
{
|
||||
FirstName = "ChangedUserFirstName",
|
||||
LastName = "ChangedUserLastName"
|
||||
};
|
||||
|
||||
if (_userService != null)
|
||||
{
|
||||
Assert.IsNotNull(_user);
|
||||
var user = await _userService.UpdateUserAsync(data, _user!);
|
||||
Assert.IsInstanceOfType(user, typeof(User));
|
||||
Assert.IsNotNull(user);
|
||||
Assert.AreEqual(data.FirstName, user.FirstName);
|
||||
Assert.AreEqual(data.LastName, user.LastName);
|
||||
_user = user;
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserAsync_Exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateUserRequestData data = new UpdateUserRequestData()
|
||||
{
|
||||
FirstName = "ChangedUserFirstName",
|
||||
LastName = "ChangedUserLastName"
|
||||
};
|
||||
|
||||
var exceptionUserService = TestUtils.CreateUserServiceException();
|
||||
|
||||
if (exceptionUserService != null)
|
||||
{
|
||||
Assert.IsNotNull(_user);
|
||||
var user = await exceptionUserService.UpdateUserAsync(data, _user!);
|
||||
Assert.Fail($"Expected exception instead of response: {user?.Guid}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.IsInstanceOfType(ex, typeof(Exception));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserPasswordAsync_Success()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_userService != null)
|
||||
{
|
||||
Assert.IsNotNull(_user);
|
||||
var oldPassword = _user.Password;
|
||||
var user = await _userService.UpdateUserPasswordAsync(_user!, "this-is-a-new-password");
|
||||
Assert.IsInstanceOfType(user, typeof(User));
|
||||
Assert.IsNotNull(user);
|
||||
Assert.AreNotEqual(user.Password, oldPassword);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserPasswordAsync_Exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
var exceptionUserService = TestUtils.CreateUserServiceException();
|
||||
|
||||
if (exceptionUserService != null)
|
||||
{
|
||||
Assert.IsNotNull(_user);
|
||||
var user = await exceptionUserService.UpdateUserPasswordAsync(_user!, "this-is-a-new-password");
|
||||
Assert.Fail($"Expected exception instead of response: {user?.Guid}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.IsInstanceOfType(ex, typeof(Exception));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserRoleAsync_Success()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_userService != null)
|
||||
{
|
||||
Assert.IsNotNull(_user);
|
||||
Role role = new()
|
||||
{
|
||||
Name = "NewRole",
|
||||
IsNotEditable = false,
|
||||
Guid = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
var oldRole = _user.Role;
|
||||
var user = await _userService.UpdateUserRoleAsync(_user!, role);
|
||||
Assert.IsInstanceOfType(user, typeof(User));
|
||||
Assert.IsNotNull(user);
|
||||
Assert.AreNotEqual(user.Role?.Id, oldRole?.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task UpdateUserRoleAsync_Exception()
|
||||
{
|
||||
try
|
||||
{
|
||||
var exceptionUserService = TestUtils.CreateUserServiceException();
|
||||
|
||||
if (exceptionUserService != null)
|
||||
{
|
||||
Assert.IsNotNull(_user);
|
||||
Role role = new()
|
||||
{
|
||||
Name = "NewRole",
|
||||
IsNotEditable = false,
|
||||
Guid = Guid.NewGuid().ToString()
|
||||
};
|
||||
var user = await exceptionUserService.UpdateUserRoleAsync(_user!, role);
|
||||
Assert.Fail($"Expected exception instead of response: {user?.Guid}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"UserService is null");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.IsInstanceOfType(ex, typeof(Exception));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task DeleteUser()
|
||||
{
|
||||
|
||||
24
MainProject.Tests/TestsUtils/ExceptionSqlServerContext.cs
Normal file
24
MainProject.Tests/TestsUtils/ExceptionSqlServerContext.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using BasicDotnetTemplate.MainProject.Core.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
public class ExceptionSqlServerContext : SqlServerContext
|
||||
{
|
||||
public bool ThrowExceptionOnSave { get; set; }
|
||||
|
||||
public ExceptionSqlServerContext() : base(TestUtils.CreateInMemorySqlContextOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (ThrowExceptionOnSave)
|
||||
{
|
||||
throw new Exception("Database error");
|
||||
}
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@ public static class ModelsInit
|
||||
FirstName = "FirstName",
|
||||
LastName = "LastName",
|
||||
Email = "test-new@email.it",
|
||||
PasswordHash = "PasswordHash",
|
||||
PasswordPepper = "PasswordPepper",
|
||||
PasswordSalt = "PasswordSalt",
|
||||
PasswordIterations = 0,
|
||||
Password = "Password",
|
||||
Role = CreateRole(),
|
||||
IsTestUser = true
|
||||
@@ -32,4 +33,4 @@ public static class ModelsInit
|
||||
};
|
||||
return role;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +64,21 @@ public static class TestUtils
|
||||
return _appSettings.DatabaseSettings?.SqlServerConnectionString ?? String.Empty;
|
||||
}
|
||||
|
||||
public static SqlServerContext CreateInMemorySqlContext()
|
||||
public static string GetFakeConnectionString()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<SqlServerContext>()
|
||||
return "Server=127.0.0.1;Initial Catalog=MyFakeDatabase;User Id=MyFakeUser;Password='MyFakePassword';MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30";
|
||||
}
|
||||
|
||||
public static DbContextOptions<SqlServerContext> CreateInMemorySqlContextOptions()
|
||||
{
|
||||
return new DbContextOptionsBuilder<SqlServerContext>()
|
||||
.UseSqlite("DataSource=:memory:") // Database in-memory
|
||||
.Options;
|
||||
}
|
||||
|
||||
public static SqlServerContext CreateInMemorySqlContext()
|
||||
{
|
||||
var options = CreateInMemorySqlContextOptions();
|
||||
|
||||
var context = new SqlServerContext(options);
|
||||
context.Database.OpenConnection();
|
||||
@@ -79,8 +89,6 @@ public static class TestUtils
|
||||
public static BaseService CreateBaseService()
|
||||
{
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
var optionsBuilder = new DbContextOptionsBuilder<SqlServerContext>();
|
||||
optionsBuilder.UseSqlServer(GetSqlConnectionString(configuration));
|
||||
SqlServerContext sqlServerContext = CreateInMemorySqlContext();
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
return new BaseService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
@@ -89,8 +97,6 @@ public static class TestUtils
|
||||
public static AuthService CreateAuthService()
|
||||
{
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
var optionsBuilder = new DbContextOptionsBuilder<SqlServerContext>();
|
||||
optionsBuilder.UseSqlServer(GetSqlConnectionString(configuration));
|
||||
SqlServerContext sqlServerContext = CreateInMemorySqlContext();
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
@@ -105,6 +111,15 @@ public static class TestUtils
|
||||
return new UserService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
}
|
||||
|
||||
public static UserService CreateUserServiceException()
|
||||
{
|
||||
var sqlServerContext = new ExceptionSqlServerContext();
|
||||
sqlServerContext.ThrowExceptionOnSave = true;
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
return new UserService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
}
|
||||
|
||||
public static JwtService CreateJwtService()
|
||||
{
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
@@ -124,6 +139,32 @@ public static class TestUtils
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
return new RoleService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
}
|
||||
|
||||
public static RoleService CreateRoleServiceException()
|
||||
{
|
||||
var sqlServerContext = new ExceptionSqlServerContext();
|
||||
sqlServerContext.ThrowExceptionOnSave = true;
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
return new RoleService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
}
|
||||
|
||||
public static PermissionService CreatePermissionService()
|
||||
{
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
SqlServerContext sqlServerContext = CreateInMemorySqlContext();
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
return new PermissionService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
}
|
||||
|
||||
public static PermissionService CreatePermissionServiceException()
|
||||
{
|
||||
var sqlServerContext = new ExceptionSqlServerContext();
|
||||
sqlServerContext.ThrowExceptionOnSave = true;
|
||||
IConfiguration configuration = CreateConfiguration();
|
||||
var httpContextAccessor = new Mock<IHttpContextAccessor>();
|
||||
return new PermissionService(httpContextAccessor.Object, configuration, sqlServerContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -102,12 +102,12 @@ public class CryptoUtils_Tests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GenerateSalt()
|
||||
public void GeneratePepper()
|
||||
{
|
||||
try
|
||||
{
|
||||
var salt = CryptUtils.GenerateSalt();
|
||||
Assert.IsTrue(!String.IsNullOrEmpty(salt));
|
||||
var salt = CryptUtils.GeneratePepper();
|
||||
Assert.IsFalse(String.IsNullOrEmpty(salt));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -122,14 +122,14 @@ public class CryptoUtils_Tests
|
||||
try
|
||||
{
|
||||
var password = "P4ssw0rd@1!";
|
||||
var salt = CryptUtils.GenerateSalt();
|
||||
Assert.IsTrue(!String.IsNullOrEmpty(salt));
|
||||
var pepper = CryptUtils.GeneratePepper();
|
||||
Assert.IsFalse(String.IsNullOrEmpty(pepper));
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
|
||||
AppSettings appSettings = ProgramUtils.AddConfiguration(ref builder, System.AppDomain.CurrentDomain.BaseDirectory + "/JsonData");
|
||||
CryptUtils cryptoUtils = new CryptUtils(appSettings);
|
||||
var encryptedPassword = cryptoUtils.GeneratePassword(password, salt, 0);
|
||||
Assert.IsTrue(password != encryptedPassword);
|
||||
var salt = appSettings?.EncryptionSettings?.Salt ?? String.Empty;
|
||||
var encryptedPassword = CryptUtils.GeneratePassword(password, salt, 0, pepper);
|
||||
Assert.AreNotEqual(encryptedPassword, password);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -147,12 +147,7 @@ public class CryptoUtils_Tests
|
||||
var salt = "Afi7PQYgEL2sPbNyVzduvg==";
|
||||
var hashedPassword = "2lMeySZ9ciH1KtSg1Z7oSJRmJEjHMeDvdaNRcJcGutM=";
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
|
||||
AppSettings appSettings = ProgramUtils.AddConfiguration(ref builder, System.AppDomain.CurrentDomain.BaseDirectory + "/JsonData");
|
||||
CryptUtils cryptoUtils = new CryptUtils(appSettings);
|
||||
var verified = cryptoUtils.VerifyPassword(password, salt, 0, hashedPassword);
|
||||
Console.WriteLine(cryptoUtils.GeneratePassword(password, salt, 0));
|
||||
|
||||
var verified = CryptUtils.VerifyPassword(hashedPassword, password, salt, 0);
|
||||
Assert.IsTrue(verified);
|
||||
}
|
||||
catch (Exception ex)
|
||||
82
MainProject.Tests/Utils/FileUtils_Tests.cs
Normal file
82
MainProject.Tests/Utils/FileUtils_Tests.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
using BasicDotnetTemplate.MainProject.Models.Common;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class FileUtils_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ConvertFileToObject_NoFilePath()
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(String.Empty);
|
||||
Assert.Fail($"Expected exception instead of response: {permissionsFile}");
|
||||
}
|
||||
catch (ArgumentException argumentException)
|
||||
{
|
||||
Assert.IsInstanceOfType(argumentException, typeof(ArgumentException));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ConvertFileToObject_NoFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(System.AppDomain.CurrentDomain.BaseDirectory + "Config/no-permissions.json");
|
||||
Assert.Fail($"Expected exception instead of response: {permissionsFile}");
|
||||
}
|
||||
catch (FileNotFoundException fileNotFoundException)
|
||||
{
|
||||
Assert.IsInstanceOfType(fileNotFoundException, typeof(FileNotFoundException));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ConvertFileToObject()
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(System.AppDomain.CurrentDomain.BaseDirectory + "Config/permissions.json");
|
||||
Assert.IsNotNull(permissionsFile);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ConvertFileToObject_InvalidOperationException()
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionsFile? permissionsFile = FileUtils.ConvertFileToObject<PermissionsFile>(System.AppDomain.CurrentDomain.BaseDirectory + "Config/invalid-permissions.json");
|
||||
Assert.Fail($"Expected exception instead of response: {permissionsFile}");
|
||||
}
|
||||
catch (InvalidOperationException invalidOperationException)
|
||||
{
|
||||
Assert.IsInstanceOfType(invalidOperationException, typeof(InvalidOperationException));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class JwtTokenUtils_Tests
|
||||
AppSettings appSettings = ProgramUtils.AddConfiguration(ref builder, System.AppDomain.CurrentDomain.BaseDirectory + "/JsonData");
|
||||
JwtTokenUtils jwtUtils = new JwtTokenUtils(appSettings);
|
||||
var jwt = jwtUtils.GenerateToken(_guid);
|
||||
Assert.IsTrue(!String.IsNullOrEmpty(jwt));
|
||||
Assert.IsFalse(String.IsNullOrEmpty(jwt));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ public class JwtTokenUtils_Tests
|
||||
JwtTokenUtils jwtUtils = new JwtTokenUtils(appSettings);
|
||||
var jwt = jwtUtils.GenerateToken(_guid);
|
||||
var guid = jwtUtils.ValidateToken($"Bearer {jwt}");
|
||||
Assert.IsTrue(_guid == guid);
|
||||
Assert.AreEqual(_guid, guid);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
62
MainProject.Tests/Utils/PasswordUtils_Test.cs
Normal file
62
MainProject.Tests/Utils/PasswordUtils_Test.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
using BasicDotnetTemplate.MainProject.Models.Common;
|
||||
using BasicDotnetTemplate.MainProject.Enum;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class PasswordUtils_Test
|
||||
{
|
||||
[TestMethod]
|
||||
public void PasswordValidation_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> errors = PasswordUtils.ValidatePassword("#aBcDeFgHi01245#");
|
||||
Assert.IsTrue(errors == null || errors.Count == 0);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PasswordValidation_Invalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> errors = PasswordUtils.ValidatePassword("aAa1#");
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_LENGTH));
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_UPPER));
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_NUMBER));
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_SPECIAL));
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.IDENTICAL_CHARS));
|
||||
Assert.IsFalse(errors.Contains(PasswordValidationEnum.MIN_LOWER));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PasswordValidation_ToLowerInvalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> errors = PasswordUtils.ValidatePassword("AaBC0*TGH1#");
|
||||
Assert.IsTrue(errors.Contains(PasswordValidationEnum.MIN_LOWER));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.Fail($"An exception was thrown: {exception}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class ProgramUtils_Tests
|
||||
|
||||
AppSettings appSettings = new AppSettings();
|
||||
OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(appSettings);
|
||||
Assert.IsTrue(realOpenApiInfo != null);
|
||||
Assert.IsNotNull(realOpenApiInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -118,10 +118,10 @@ public class ProgramUtils_Tests
|
||||
OpenApiSettings = null
|
||||
};
|
||||
OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(appSettings);
|
||||
Assert.IsTrue(realOpenApiInfo != null);
|
||||
Assert.IsTrue(realOpenApiInfo.Title == appSettings.Settings.Name);
|
||||
Assert.IsTrue(realOpenApiInfo.Description == appSettings.Settings.Description);
|
||||
Assert.IsTrue(realOpenApiInfo.Version == appSettings.Settings.Version);
|
||||
Assert.IsNotNull(realOpenApiInfo);
|
||||
Assert.AreEqual(appSettings.Settings.Name, realOpenApiInfo.Title);
|
||||
Assert.AreEqual(appSettings.Settings.Description, realOpenApiInfo.Description);
|
||||
Assert.AreEqual(appSettings.Settings.Version, realOpenApiInfo.Version);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -151,11 +151,11 @@ public class ProgramUtils_Tests
|
||||
}
|
||||
};
|
||||
OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(appSettings);
|
||||
Assert.IsTrue(realOpenApiInfo != null);
|
||||
Assert.IsTrue(realOpenApiInfo.Title == appSettings.Settings.Name);
|
||||
Assert.IsTrue(realOpenApiInfo.Description == appSettings.Settings.Description);
|
||||
Assert.IsTrue(realOpenApiInfo.Version == appSettings.Settings.Version);
|
||||
Assert.IsTrue(realOpenApiInfo.TermsOfService == null);
|
||||
Assert.IsNotNull(realOpenApiInfo);
|
||||
Assert.AreEqual(appSettings.Settings.Name, realOpenApiInfo.Title);
|
||||
Assert.AreEqual(appSettings.Settings.Description, realOpenApiInfo.Description);
|
||||
Assert.AreEqual(appSettings.Settings.Version, realOpenApiInfo.Version);
|
||||
Assert.IsNull(realOpenApiInfo.TermsOfService);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -299,7 +299,6 @@ public class ProgramUtils_Tests
|
||||
ProgramUtils.AddDbContext(ref builder, realAppSettings);
|
||||
|
||||
var areEquals = expectedDbSettings.SqlServerConnectionString == realAppSettings.DatabaseSettings?.SqlServerConnectionString;
|
||||
Console.WriteLine(realAppSettings.DatabaseSettings?.SqlServerConnectionString);
|
||||
Assert.IsTrue(areEquals);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
32
MainProject/Config/permissions.json
Normal file
32
MainProject/Config/permissions.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"PermissionInfos": [
|
||||
{
|
||||
"System": "base",
|
||||
"RolePermissionModuleOperations": [
|
||||
{
|
||||
"Module": "roles",
|
||||
"Operations": [
|
||||
{ "Operation": "create", "Roles": [] },
|
||||
{ "Operation": "read", "Roles": [] },
|
||||
{ "Operation": "update", "Roles": [] },
|
||||
{ "Operation": "delete", "Roles": [] },
|
||||
{ "Operation": "list", "Roles": [] },
|
||||
{ "Operation": "use", "Roles": [] }
|
||||
]
|
||||
},
|
||||
{
|
||||
"Module": "users",
|
||||
"Operations": [
|
||||
{ "Operation": "create", "Roles": [] },
|
||||
{ "Operation": "read", "Roles": [] },
|
||||
{ "Operation": "update", "Roles": [] },
|
||||
{ "Operation": "delete", "Roles": [] },
|
||||
{ "Operation": "list", "Roles": [] },
|
||||
{ "Operation": "use", "Roles": [] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using BasicDotnetTemplate.MainProject.Models.Api.Request.Auth;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response.Auth;
|
||||
using BasicDotnetTemplate.MainProject.Services;
|
||||
using BasicDotnetTemplate.MainProject.Core.Filters;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
@@ -21,30 +22,17 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
this._authService = authService;
|
||||
}
|
||||
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPost("authenticate")]
|
||||
[ProducesResponseType<AuthenticateResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> AuthenticateAsync([FromBody] AuthenticateRequest request)
|
||||
public async Task<IActionResult> AuthenticateAsync([FromBody] AuthenticateRequest request) //NOSONAR
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(_requestNotWellFormed);
|
||||
}
|
||||
|
||||
if (
|
||||
request == null ||
|
||||
request.Data == null ||
|
||||
String.IsNullOrEmpty(request.Data.Email) ||
|
||||
String.IsNullOrEmpty(request.Data.Password)
|
||||
)
|
||||
{
|
||||
return BadRequest(_requestNotWellFormed);
|
||||
}
|
||||
var data = await this._authService.AuthenticateAsync(request.Data);
|
||||
var data = await this._authService.AuthenticateAsync(request!.Data!);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
@@ -55,14 +43,9 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var message = "Something went wrong";
|
||||
if (!String.IsNullOrEmpty(exception.Message))
|
||||
{
|
||||
message += $". {exception.Message}";
|
||||
}
|
||||
return InternalServerError(message);
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
protected readonly IMapper? _mapper;
|
||||
protected readonly IConfiguration _configuration;
|
||||
protected readonly AppSettings _appSettings;
|
||||
protected readonly string _requestNotWellFormed = "Request is not well formed";
|
||||
protected readonly string _somethingWentWrong = "Something went wrong";
|
||||
|
||||
protected BaseController(
|
||||
IConfiguration configuration
|
||||
@@ -66,12 +66,16 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
return StatusCode((int)HttpStatusCode.BadRequest, CreateResponse(HttpStatusCode.BadRequest, message, data));
|
||||
}
|
||||
|
||||
protected IActionResult InternalServerError(string message)
|
||||
protected IActionResult InternalServerError(Exception exception)
|
||||
{
|
||||
message = String.IsNullOrEmpty(message) ? "Internal server error" : message;
|
||||
var message = this._somethingWentWrong;
|
||||
if (!String.IsNullOrEmpty(exception.Message))
|
||||
{
|
||||
message += $". {exception.Message}";
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError, CreateResponse(HttpStatusCode.InternalServerError, message, new object()));
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
168
MainProject/Controllers/RoleController.cs
Normal file
168
MainProject/Controllers/RoleController.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using BasicDotnetTemplate.MainProject.Core.Attributes;
|
||||
using BasicDotnetTemplate.MainProject.Services;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Request.Role;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response.Role;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Role;
|
||||
using BasicDotnetTemplate.MainProject.Core.Filters;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
public class RoleController : BaseController
|
||||
{
|
||||
private readonly IRoleService _roleService;
|
||||
public RoleController(
|
||||
IConfiguration configuration,
|
||||
IRoleService roleService
|
||||
) : base(configuration)
|
||||
{
|
||||
this._roleService = roleService;
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpGet("get/{guid}")]
|
||||
[ProducesResponseType<GetRoleResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> GetRoleByGuidAsync(string guid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var role = await this._roleService.GetRoleByGuidAsync(guid);
|
||||
|
||||
if (role == null || String.IsNullOrEmpty(role.Guid))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var roleDto = _mapper?.Map<RoleDto>(role);
|
||||
|
||||
return Success(String.Empty, roleDto);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPost("create")]
|
||||
[ProducesResponseType<GetRoleResponse>(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> CreateRoleAsync([FromBody] CreateRoleRequest request) //NOSONAR
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await this._roleService.CheckIfNameIsValid(request!.Data!.Name))
|
||||
{
|
||||
var role = await this._roleService.CreateRoleAsync(request!.Data);
|
||||
|
||||
if (role == null || String.IsNullOrEmpty(role.Guid))
|
||||
{
|
||||
return BadRequest("Not created");
|
||||
}
|
||||
|
||||
var roleDto = _mapper?.Map<RoleDto>(role);
|
||||
|
||||
return Success(String.Empty, roleDto);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest("Invalid name");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPut("update/{guid}")]
|
||||
[ProducesResponseType<GetRoleResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateRoleAsync([FromBody] CreateRoleRequest request, string guid) //NOSONAR
|
||||
{
|
||||
try
|
||||
{
|
||||
var role = await this._roleService.GetRoleByGuidAsync(guid);
|
||||
|
||||
if (role == null || String.IsNullOrEmpty(role.Guid))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if (role.IsNotEditable)
|
||||
{
|
||||
return BadRequest("This role is not editable");
|
||||
}
|
||||
|
||||
if (
|
||||
await this._roleService.CheckIfNameIsValid(request!.Data!.Name) ||
|
||||
await this._roleService.CheckIfNameIsValid(request!.Data!.Name, guid)
|
||||
)
|
||||
{
|
||||
role = await this._roleService.UpdateRoleAsync(request.Data, role);
|
||||
|
||||
var roleDto = _mapper?.Map<RoleDto>(role);
|
||||
|
||||
return Success(String.Empty, roleDto);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest("Invalid name");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpDelete("{guid}")]
|
||||
[ProducesResponseType<GetRoleResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> DeleteRoleByGuidAsync(string guid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var role = await this._roleService.GetRoleByGuidAsync(guid);
|
||||
|
||||
if (role == null || String.IsNullOrEmpty(role.Guid))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
await this._roleService.DeleteRoleAsync(role);
|
||||
|
||||
return Success(String.Empty);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,4 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response.User;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.User;
|
||||
using BasicDotnetTemplate.MainProject.Core.Filters;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
@@ -25,7 +26,9 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
this._roleService = roleService;
|
||||
}
|
||||
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpGet("get/{guid}")]
|
||||
[ProducesResponseType<GetUserResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status404NotFound)]
|
||||
@@ -35,15 +38,6 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(_requestNotWellFormed);
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(guid))
|
||||
{
|
||||
return BadRequest(_requestNotWellFormed);
|
||||
}
|
||||
var user = await this._userService.GetUserByGuidAsync(guid);
|
||||
|
||||
if (user == null || String.IsNullOrEmpty(user.Guid))
|
||||
@@ -57,49 +51,30 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var message = "Something went wrong";
|
||||
if (!String.IsNullOrEmpty(exception.Message))
|
||||
{
|
||||
message += $". {exception.Message}";
|
||||
}
|
||||
return InternalServerError(message);
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPost("create")]
|
||||
[ProducesResponseType<GetUserResponse>(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> CreateUserAsync([FromBody] CreateUserRequest request)
|
||||
public async Task<IActionResult> CreateUserAsync([FromBody] CreateUserRequest request) //NOSONAR
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
if (await this._userService.CheckIfEmailIsValid(request!.Data!.Email))
|
||||
{
|
||||
return BadRequest(_requestNotWellFormed);
|
||||
}
|
||||
|
||||
if (request == null || request.Data == null ||
|
||||
String.IsNullOrEmpty(request.Data.FirstName) ||
|
||||
String.IsNullOrEmpty(request.Data.LastName) ||
|
||||
String.IsNullOrEmpty(request.Data.Email) ||
|
||||
String.IsNullOrEmpty(request.Data.Password)
|
||||
)
|
||||
{
|
||||
return BadRequest(_requestNotWellFormed);
|
||||
}
|
||||
|
||||
if (await this._userService.CheckIfEmailIsValid(request.Data.Email))
|
||||
{
|
||||
var role = await this._roleService.GetRoleForUser(request.Data.RoleGuid);
|
||||
var role = await this._roleService.GetRoleForUser(request!.Data!.RoleGuid);
|
||||
if (role == null)
|
||||
{
|
||||
return BadRequest("Role not found");
|
||||
}
|
||||
|
||||
var user = await this._userService.CreateUserAsync(request.Data, role);
|
||||
var user = await this._userService.CreateUserAsync(request!.Data, role);
|
||||
|
||||
if (user == null || String.IsNullOrEmpty(user.Guid))
|
||||
{
|
||||
@@ -118,17 +93,135 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var message = "Something went wrong";
|
||||
if (!String.IsNullOrEmpty(exception.Message))
|
||||
{
|
||||
message += $". {exception.Message}";
|
||||
}
|
||||
return InternalServerError(message);
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPut("update/{guid}")]
|
||||
[ProducesResponseType<GetUserResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateUserAsync([FromBody] UpdateUserRequest request, string guid) //NOSONAR
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await this._userService.GetUserByGuidAsync(guid);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
user = await this._userService.UpdateUserAsync(request!.Data!, user);
|
||||
|
||||
var userDto = _mapper?.Map<UserDto>(user);
|
||||
|
||||
return Success(String.Empty, userDto);
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPut("update/{guid}/password")]
|
||||
[ProducesResponseType<GetUserResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateUserPasswordAsync(string guid, string newPassword)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await this._userService.GetUserByGuidAsync(guid);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
user = await this._userService.UpdateUserPasswordAsync(user, newPassword);
|
||||
|
||||
var userDto = _mapper?.Map<UserDto>(user);
|
||||
|
||||
return Success(String.Empty, userDto);
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpPut("update/{guid}/role")]
|
||||
[ProducesResponseType<GetUserResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateUserRoleAsync(string guid, string roleGuid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var role = await this._roleService.GetRoleByGuidAsync(roleGuid);
|
||||
if (role == null)
|
||||
{
|
||||
return BadRequest("Role not found");
|
||||
}
|
||||
|
||||
var user = await this._userService.GetUserByGuidAsync(guid);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
user = await this._userService.UpdateUserRoleAsync(user, role);
|
||||
|
||||
var userDto = _mapper?.Map<UserDto>(user);
|
||||
|
||||
return Success(String.Empty, userDto);
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JwtAuthorization()]
|
||||
[ModelStateValidationHandledByFilterAttribute]
|
||||
[HttpDelete("{guid}")]
|
||||
[ProducesResponseType<GetUserResponse>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> DeleteUserByGuidAsync(string guid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await this._userService.GetUserByGuidAsync(guid);
|
||||
|
||||
if (user == null || String.IsNullOrEmpty(user.Guid))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
await this._userService.DeleteUserAsync(user);
|
||||
|
||||
return Success(String.Empty);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return InternalServerError(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
) : base(configuration) { }
|
||||
|
||||
[HttpGet("get")]
|
||||
public IActionResult GetVersion()
|
||||
{
|
||||
return Success(String.Empty, _appSettings?.Settings?.Version);
|
||||
}
|
||||
public IActionResult GetVersion() => Success(String.Empty, _appSettings?.Settings?.Version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Core.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that ModelState validation is handled automatically by an Action Filter.
|
||||
/// Used to suppress SonarCloud warnings about missing ModelState.IsValid checks.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class ModelStateValidationHandledByFilterAttribute : Attribute
|
||||
{ }
|
||||
}
|
||||
@@ -6,29 +6,75 @@ namespace BasicDotnetTemplate.MainProject.Core.Database
|
||||
{
|
||||
public class SqlServerContext : DbContext
|
||||
{
|
||||
private const string _isDeletedFalse = "[IsDeleted] = 0";
|
||||
private const string _isEnabled = "[Enabled] = 1";
|
||||
|
||||
public SqlServerContext(DbContextOptions<SqlServerContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<PermissionModule> PermissionModules { get; set; }
|
||||
public DbSet<PermissionOperation> PermissionOperations { get; set; }
|
||||
public DbSet<PermissionSystem> PermissionSystems { get; set; }
|
||||
public DbSet<PermissionSystemModule> PermissionSystemModules { get; set; }
|
||||
public DbSet<PermissionSystemModuleOperation> PermissionSystemModuleOperations { get; set; }
|
||||
public DbSet<RolePermissionSystemModuleOperation> RolePermissionSystemModuleOperations { get; set; }
|
||||
public DbSet<Role> Roles { get; set; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
#region "INDEXES"
|
||||
// Indexes
|
||||
|
||||
modelBuilder.Entity<User>()
|
||||
.HasIndex(x => x.Email, "IX_Email");
|
||||
|
||||
modelBuilder.Entity<User>()
|
||||
.HasIndex(x => new { x.IsDeleted, x.Guid }, "IX_IsDeleted_Guid")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
.HasFilter(_isDeletedFalse);
|
||||
|
||||
modelBuilder.Entity<Role>()
|
||||
.HasIndex(x => new { x.IsDeleted, x.Guid }, "IX_IsDeleted_Guid")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
.HasFilter(_isDeletedFalse);
|
||||
|
||||
modelBuilder.Entity<PermissionSystem>()
|
||||
.HasIndex(x => new { x.IsDeleted }, "IX_IsDeleted")
|
||||
.HasFilter(_isDeletedFalse);
|
||||
|
||||
modelBuilder.Entity<PermissionSystem>()
|
||||
.HasIndex(x => new { x.Enabled }, "IX_Enabled")
|
||||
.HasFilter(_isEnabled);
|
||||
|
||||
modelBuilder.Entity<PermissionSystem>()
|
||||
.HasIndex(x => new { x.IsDeleted, x.Name, x.Enabled }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter(_isEnabled)
|
||||
.HasFilter(_isDeletedFalse);
|
||||
|
||||
modelBuilder.Entity<PermissionModule>()
|
||||
.HasIndex(x => new { x.IsDeleted }, "IX_IsDeleted")
|
||||
.HasFilter(_isDeletedFalse);
|
||||
|
||||
modelBuilder.Entity<PermissionModule>()
|
||||
.HasIndex(x => new { x.Enabled }, "IX_Enabled")
|
||||
.HasFilter(_isEnabled);
|
||||
|
||||
modelBuilder.Entity<PermissionModule>()
|
||||
.HasIndex(x => new { x.IsDeleted, x.Name, x.Enabled }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter(_isEnabled)
|
||||
.HasFilter(_isDeletedFalse);
|
||||
|
||||
modelBuilder.Entity<PermissionOperation>()
|
||||
.HasIndex(x => new { x.IsDeleted, x.Name }, "IX_IsDeleted_Name");
|
||||
|
||||
modelBuilder.Entity<PermissionSystemModuleOperation>()
|
||||
.HasIndex(x => new { x.IsDeleted, x.Enabled, x.Guid }, "IX_IsDeleted_Enabled_Guid");
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
MainProject/Core/Filters/ValidationActionFilter.cs
Normal file
43
MainProject/Core/Filters/ValidationActionFilter.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Base;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Core.Filters
|
||||
{
|
||||
public class ValidationActionFilter : IAsyncActionFilter
|
||||
{
|
||||
private readonly string _requestNotWellFormedMessage = "Request is not well formed";
|
||||
|
||||
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
if (!context.ModelState.IsValid)
|
||||
{
|
||||
context.Result = new BadRequestObjectResult(new ValidationError
|
||||
{
|
||||
Message = _requestNotWellFormedMessage,
|
||||
Errors = context.ModelState.Where(m =>
|
||||
m.Value != null && m.Value.Errors.Any())
|
||||
.ToDictionary(
|
||||
m => m.Key,
|
||||
m => m.Value!.Errors.Select(e => e.ErrorMessage).ToList()
|
||||
)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var requestBody = context.ActionArguments.Values.FirstOrDefault(arg => arg != null && !arg.GetType().IsPrimitive && arg is not string);
|
||||
|
||||
if (requestBody == null)
|
||||
{
|
||||
context.Result = new BadRequestObjectResult(new ValidationError
|
||||
{
|
||||
Message = _requestNotWellFormedMessage
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await next();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.User;
|
||||
using SqlServerDatabase = BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using AutoMapper;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Role;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Core.Middlewares;
|
||||
@@ -8,6 +9,7 @@ public class AutoMapperConfiguration : Profile
|
||||
{
|
||||
public AutoMapperConfiguration()
|
||||
{
|
||||
CreateMap<SqlServerDatabase.Role, RoleDto>();
|
||||
CreateMap<SqlServerDatabase.User, UserDto>();
|
||||
|
||||
}
|
||||
|
||||
10
MainProject/Enum/PasswordValidationEnum.cs
Normal file
10
MainProject/Enum/PasswordValidationEnum.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Enum;
|
||||
public static class PasswordValidationEnum
|
||||
{
|
||||
public const string MIN_LENGTH = "Password must be at least 8 characters long";
|
||||
public const string MIN_UPPER = "Password must have at least 2 uppercase letters";
|
||||
public const string MIN_LOWER = "Password must have at least 2 lowercase letters";
|
||||
public const string MIN_NUMBER = "Password must be at least 2 numbers";
|
||||
public const string MIN_SPECIAL = "Password must be at least 2 special characters";
|
||||
public const string IDENTICAL_CHARS = "Password cannot have 3 or more consecutive identical characters";
|
||||
}
|
||||
@@ -10,41 +10,41 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.13" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2">
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Identity.Web" Version="3.7.1" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.28.0" />
|
||||
<PackageReference Include="MongoDB.EntityFrameworkCore" Version="8.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.Identity.Web" Version="3.9.3" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.4.0" />
|
||||
<PackageReference Include="MongoDB.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
|
||||
<PackageReference Include="NLog" Version="5.5.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.5.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
||||
543
MainProject/Migrations/20250426183010_AddingPermissionsTables.Designer.cs
generated
Normal file
543
MainProject/Migrations/20250426183010_AddingPermissionsTables.Designer.cs
generated
Normal file
@@ -0,0 +1,543 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BasicDotnetTemplate.MainProject.Core.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MainProject.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqlServerContext))]
|
||||
[Migration("20250426183010_AddingPermissionsTables")]
|
||||
partial class AddingPermissionsTables
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "Enabled" }, "IX_Enabled")
|
||||
.HasFilter("[Enabled] = 1");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted" }, "IX_IsDeleted")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name", "Enabled" }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("PermissionModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name" }, "IX_IsDeleted_Name");
|
||||
|
||||
b.ToTable("PermissionOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "Enabled" }, "IX_Enabled")
|
||||
.HasFilter("[Enabled] = 1");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted" }, "IX_IsDeleted")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name", "Enabled" }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("PermissionSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionModuleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PermissionSystemId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionModuleId");
|
||||
|
||||
b.HasIndex("PermissionSystemId");
|
||||
|
||||
b.ToTable("PermissionSystemModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionOperationId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PermissionSystemModuleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionOperationId");
|
||||
|
||||
b.HasIndex("PermissionSystemModuleId");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Enabled", "Guid" }, "IX_IsDeleted_Enabled_Guid");
|
||||
|
||||
b.ToTable("PermissionSystemModuleOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsNotEditable")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Guid" }, "IX_IsDeleted_Guid")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("Roles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.RolePermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("Active")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionSystemModuleOperationId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionSystemModuleOperationId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("RolePermissionSystemModuleOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsTestUser")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PasswordSalt")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.HasIndex(new[] { "Email" }, "IX_Email");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Guid" }, "IX_IsDeleted_Guid")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionModule", "PermissionModule")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystem", "PermissionSystem")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionModule");
|
||||
|
||||
b.Navigation("PermissionSystem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionOperation", "PermissionOperation")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionOperationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", "PermissionSystemModule")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionOperation");
|
||||
|
||||
b.Navigation("PermissionSystemModule");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.RolePermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", "PermissionSystemModuleOperation")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemModuleOperationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", "Role")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionSystemModuleOperation");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", "Role")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
283
MainProject/Migrations/20250426183010_AddingPermissionsTables.cs
Normal file
283
MainProject/Migrations/20250426183010_AddingPermissionsTables.cs
Normal file
@@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MainProject.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddingPermissionsTables : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PermissionModules",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Enabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
Guid = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreationUserId = table.Column<int>(type: "int", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UpdateUserId = table.Column<int>(type: "int", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletionUserId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PermissionModules", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PermissionOperations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Guid = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreationUserId = table.Column<int>(type: "int", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UpdateUserId = table.Column<int>(type: "int", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletionUserId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PermissionOperations", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PermissionSystems",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
Enabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
Guid = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreationUserId = table.Column<int>(type: "int", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UpdateUserId = table.Column<int>(type: "int", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletionUserId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PermissionSystems", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PermissionSystemModules",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PermissionSystemId = table.Column<int>(type: "int", nullable: false),
|
||||
PermissionModuleId = table.Column<int>(type: "int", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
Guid = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreationUserId = table.Column<int>(type: "int", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UpdateUserId = table.Column<int>(type: "int", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletionUserId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PermissionSystemModules", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PermissionSystemModules_PermissionModules_PermissionModuleId",
|
||||
column: x => x.PermissionModuleId,
|
||||
principalTable: "PermissionModules",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PermissionSystemModules_PermissionSystems_PermissionSystemId",
|
||||
column: x => x.PermissionSystemId,
|
||||
principalTable: "PermissionSystems",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PermissionSystemModuleOperations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PermissionSystemModuleId = table.Column<int>(type: "int", nullable: false),
|
||||
PermissionOperationId = table.Column<int>(type: "int", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
Guid = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreationUserId = table.Column<int>(type: "int", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UpdateUserId = table.Column<int>(type: "int", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletionUserId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PermissionSystemModuleOperations", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PermissionSystemModuleOperations_PermissionOperations_PermissionOperationId",
|
||||
column: x => x.PermissionOperationId,
|
||||
principalTable: "PermissionOperations",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PermissionSystemModuleOperations_PermissionSystemModules_PermissionSystemModuleId",
|
||||
column: x => x.PermissionSystemModuleId,
|
||||
principalTable: "PermissionSystemModules",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "RolePermissionSystemModuleOperations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
RoleId = table.Column<int>(type: "int", nullable: false),
|
||||
PermissionSystemModuleOperationId = table.Column<int>(type: "int", nullable: false),
|
||||
Active = table.Column<bool>(type: "bit", nullable: false),
|
||||
Guid = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreationUserId = table.Column<int>(type: "int", nullable: true),
|
||||
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UpdateUserId = table.Column<int>(type: "int", nullable: true),
|
||||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletionUserId = table.Column<int>(type: "int", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_RolePermissionSystemModuleOperations", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_RolePermissionSystemModuleOperations_PermissionSystemModuleOperations_PermissionSystemModuleOperationId",
|
||||
column: x => x.PermissionSystemModuleOperationId,
|
||||
principalTable: "PermissionSystemModuleOperations",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_RolePermissionSystemModuleOperations_Roles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "Roles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Enabled",
|
||||
table: "PermissionModules",
|
||||
column: "Enabled",
|
||||
filter: "[Enabled] = 1");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IsDeleted",
|
||||
table: "PermissionModules",
|
||||
column: "IsDeleted",
|
||||
filter: "[IsDeleted] = 0");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IsDeleted_Name_Enabled",
|
||||
table: "PermissionModules",
|
||||
columns: new[] { "IsDeleted", "Name", "Enabled" },
|
||||
filter: "[IsDeleted] = 0");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IsDeleted_Name",
|
||||
table: "PermissionOperations",
|
||||
columns: new[] { "IsDeleted", "Name" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IsDeleted_Enabled_Guid",
|
||||
table: "PermissionSystemModuleOperations",
|
||||
columns: new[] { "IsDeleted", "Enabled", "Guid" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PermissionSystemModuleOperations_PermissionOperationId",
|
||||
table: "PermissionSystemModuleOperations",
|
||||
column: "PermissionOperationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PermissionSystemModuleOperations_PermissionSystemModuleId",
|
||||
table: "PermissionSystemModuleOperations",
|
||||
column: "PermissionSystemModuleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PermissionSystemModules_PermissionModuleId",
|
||||
table: "PermissionSystemModules",
|
||||
column: "PermissionModuleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PermissionSystemModules_PermissionSystemId",
|
||||
table: "PermissionSystemModules",
|
||||
column: "PermissionSystemId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Enabled",
|
||||
table: "PermissionSystems",
|
||||
column: "Enabled",
|
||||
filter: "[Enabled] = 1");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IsDeleted",
|
||||
table: "PermissionSystems",
|
||||
column: "IsDeleted",
|
||||
filter: "[IsDeleted] = 0");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IsDeleted_Name_Enabled",
|
||||
table: "PermissionSystems",
|
||||
columns: new[] { "IsDeleted", "Name", "Enabled" },
|
||||
filter: "[IsDeleted] = 0");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RolePermissionSystemModuleOperations_PermissionSystemModuleOperationId",
|
||||
table: "RolePermissionSystemModuleOperations",
|
||||
column: "PermissionSystemModuleOperationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RolePermissionSystemModuleOperations_RoleId",
|
||||
table: "RolePermissionSystemModuleOperations",
|
||||
column: "RoleId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "RolePermissionSystemModuleOperations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PermissionSystemModuleOperations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PermissionOperations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PermissionSystemModules");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PermissionModules");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PermissionSystems");
|
||||
}
|
||||
}
|
||||
}
|
||||
542
MainProject/Migrations/20250617183212_AlterTableUsersForPasswordEncryption.Designer.cs
generated
Normal file
542
MainProject/Migrations/20250617183212_AlterTableUsersForPasswordEncryption.Designer.cs
generated
Normal file
@@ -0,0 +1,542 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BasicDotnetTemplate.MainProject.Core.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MainProject.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqlServerContext))]
|
||||
[Migration("20250617183212_AlterTableUsersForPasswordEncryption")]
|
||||
partial class AlterTableUsersForPasswordEncryption
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "Enabled" }, "IX_Enabled")
|
||||
.HasFilter("[Enabled] = 1");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted" }, "IX_IsDeleted")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name", "Enabled" }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("PermissionModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name" }, "IX_IsDeleted_Name");
|
||||
|
||||
b.ToTable("PermissionOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "Enabled" }, "IX_Enabled")
|
||||
.HasFilter("[Enabled] = 1");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted" }, "IX_IsDeleted")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name", "Enabled" }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("PermissionSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionModuleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PermissionSystemId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionModuleId");
|
||||
|
||||
b.HasIndex("PermissionSystemId");
|
||||
|
||||
b.ToTable("PermissionSystemModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionOperationId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PermissionSystemModuleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionOperationId");
|
||||
|
||||
b.HasIndex("PermissionSystemModuleId");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Enabled", "Guid" }, "IX_IsDeleted_Enabled_Guid");
|
||||
|
||||
b.ToTable("PermissionSystemModuleOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsNotEditable")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Guid" }, "IX_IsDeleted_Guid")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("Roles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.RolePermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("Active")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionSystemModuleOperationId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionSystemModuleOperationId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("RolePermissionSystemModuleOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsTestUser")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("PasswordIterations")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("PasswordPepper")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PasswordSalt")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("RoleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.HasIndex(new[] { "Email" }, "IX_Email");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Guid" }, "IX_IsDeleted_Guid")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionModule", "PermissionModule")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystem", "PermissionSystem")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionModule");
|
||||
|
||||
b.Navigation("PermissionSystem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionOperation", "PermissionOperation")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionOperationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", "PermissionSystemModule")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionOperation");
|
||||
|
||||
b.Navigation("PermissionSystemModule");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.RolePermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", "PermissionSystemModuleOperation")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemModuleOperationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", "Role")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionSystemModuleOperation");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", "Role")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MainProject.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AlterTableUsersForPasswordEncryption : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Users_Roles_RoleId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PasswordHash",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "RoleId",
|
||||
table: "Users",
|
||||
type: "int",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Password",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PasswordIterations",
|
||||
table: "Users",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "PasswordPepper",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Users_Roles_RoleId",
|
||||
table: "Users",
|
||||
column: "RoleId",
|
||||
principalTable: "Roles",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Users_Roles_RoleId",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PasswordIterations",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PasswordPepper",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "RoleId",
|
||||
table: "Users",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Password",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "PasswordHash",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Users_Roles_RoleId",
|
||||
table: "Users",
|
||||
column: "RoleId",
|
||||
principalTable: "Roles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,275 @@ namespace MainProject.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.2")
|
||||
.HasAnnotation("ProductVersion", "9.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "Enabled" }, "IX_Enabled")
|
||||
.HasFilter("[Enabled] = 1");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted" }, "IX_IsDeleted")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name", "Enabled" }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("PermissionModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name" }, "IX_IsDeleted_Name");
|
||||
|
||||
b.ToTable("PermissionOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex(new[] { "Enabled" }, "IX_Enabled")
|
||||
.HasFilter("[Enabled] = 1");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted" }, "IX_IsDeleted")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Name", "Enabled" }, "IX_IsDeleted_Name_Enabled")
|
||||
.HasFilter("[IsDeleted] = 0");
|
||||
|
||||
b.ToTable("PermissionSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionModuleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PermissionSystemId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionModuleId");
|
||||
|
||||
b.HasIndex("PermissionSystemId");
|
||||
|
||||
b.ToTable("PermissionSystemModules");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Enabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionOperationId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PermissionSystemModuleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionOperationId");
|
||||
|
||||
b.HasIndex("PermissionSystemModuleId");
|
||||
|
||||
b.HasIndex(new[] { "IsDeleted", "Enabled", "Guid" }, "IX_IsDeleted_Enabled_Guid");
|
||||
|
||||
b.ToTable("PermissionSystemModuleOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -72,6 +336,58 @@ namespace MainProject.Migrations
|
||||
b.ToTable("Roles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.RolePermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("Active")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime>("CreationTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("CreationUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletionTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("DeletionUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Guid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(45)
|
||||
.HasColumnType("nvarchar(45)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PermissionSystemModuleOperationId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("UpdateUserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PermissionSystemModuleOperationId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("RolePermissionSystemModuleOperations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -119,18 +435,19 @@ namespace MainProject.Migrations
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
b.Property<int>("PasswordIterations")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("PasswordPepper")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PasswordSalt")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("RoleId")
|
||||
b.Property<int?>("RoleId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdateTime")
|
||||
@@ -151,14 +468,69 @@ namespace MainProject.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionModule", "PermissionModule")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystem", "PermissionSystem")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionModule");
|
||||
|
||||
b.Navigation("PermissionSystem");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionOperation", "PermissionOperation")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionOperationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModule", "PermissionSystemModule")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemModuleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionOperation");
|
||||
|
||||
b.Navigation("PermissionSystemModule");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.RolePermissionSystemModuleOperation", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.PermissionSystemModuleOperation", "PermissionSystemModuleOperation")
|
||||
.WithMany()
|
||||
.HasForeignKey("PermissionSystemModuleOperationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", "Role")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PermissionSystemModuleOperation");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.User", b =>
|
||||
{
|
||||
b.HasOne("BasicDotnetTemplate.MainProject.Models.Database.SqlServer.Role", "Role")
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
|
||||
9
MainProject/Models/Api/Base/ValidationError.cs
Normal file
9
MainProject/Models/Api/Base/ValidationError.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Base;
|
||||
|
||||
public class ValidationError
|
||||
{
|
||||
public string? Message { get; set; }
|
||||
public Dictionary<string, List<string>>? Errors { get; set; }
|
||||
}
|
||||
11
MainProject/Models/Api/Common/Exceptions/CreateException.cs
Normal file
11
MainProject/Models/Api/Common/Exceptions/CreateException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
|
||||
|
||||
public class CreateException : Exception
|
||||
{
|
||||
public CreateException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
11
MainProject/Models/Api/Common/Exceptions/UpdateException.cs
Normal file
11
MainProject/Models/Api/Common/Exceptions/UpdateException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
|
||||
|
||||
public class UpdateException : Exception
|
||||
{
|
||||
public UpdateException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
14
MainProject/Models/Api/Common/Role/RoleDto.cs
Normal file
14
MainProject/Models/Api/Common/Role/RoleDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Common.Role;
|
||||
|
||||
public class RoleDto
|
||||
{
|
||||
#nullable enable
|
||||
public string? Guid { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public bool? IsNotEditable { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public class UserRole
|
||||
public string? Name { get; set; }
|
||||
#nullable disable
|
||||
|
||||
public UserRole() {}
|
||||
public UserRole() { }
|
||||
|
||||
public UserRole(DatabaseSqlServer.Role role)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ public class AuthenticatedUser
|
||||
FirstName = user.FirstName;
|
||||
LastName = user.LastName;
|
||||
Email = user.Email;
|
||||
Role = new UserRole();
|
||||
Role = new UserRole(user.Role!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Data.Auth;
|
||||
|
||||
public class AuthenticateRequestData
|
||||
{
|
||||
#nullable enable
|
||||
public string? Email { get; set; }
|
||||
public string? Password { get; set; }
|
||||
#nullable disable
|
||||
[Required(ErrorMessage = "Email is required")]
|
||||
public required string Email { get; set; }
|
||||
[Required(ErrorMessage = "Password is required")]
|
||||
public required string Password { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Data.Role;
|
||||
|
||||
public class CreateRoleRequestData
|
||||
{
|
||||
public string Name { get; set; } = String.Empty;
|
||||
[Required(ErrorMessage = "Name is required")]
|
||||
public required string Name { get; set; }
|
||||
public required bool IsNotEditable { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Data.User;
|
||||
|
||||
public class CreateUserRequestData
|
||||
public class CreateUserRequestData : UpdateUserRequestData
|
||||
{
|
||||
public string FirstName { get; set; } = String.Empty;
|
||||
public string LastName { get; set; } = String.Empty;
|
||||
public string Email { get; set; } = String.Empty;
|
||||
public string Password { get; set; } = String.Empty;
|
||||
[Required(ErrorMessage = "Email is required")]
|
||||
[StringLength(200, ErrorMessage = "Email's maxLength: 200")]
|
||||
public required string Email { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Password is required")]
|
||||
public required string Password { get; set; }
|
||||
|
||||
public string? RoleGuid { get; set; }
|
||||
|
||||
}
|
||||
|
||||
19
MainProject/Models/Api/Data/User/UpdateUserRequestData.cs
Normal file
19
MainProject/Models/Api/Data/User/UpdateUserRequestData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Data.User;
|
||||
|
||||
public class UpdateUserRequestData
|
||||
{
|
||||
[Required(ErrorMessage = "FirstName is required")]
|
||||
[StringLength(200, ErrorMessage = "FirstName's maxLength: 200")]
|
||||
public required string FirstName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "LastName is required")]
|
||||
[StringLength(200, ErrorMessage = "LastName's maxLength: 200")]
|
||||
public required string LastName { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.Auth;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Request.Auth;
|
||||
|
||||
public class AuthenticateRequest
|
||||
{
|
||||
#nullable enable
|
||||
public AuthenticateRequestData? Data { get; set; }
|
||||
#nullable disable
|
||||
[Required(ErrorMessage = "Data is required")]
|
||||
public required AuthenticateRequestData Data { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
MainProject/Models/Api/Request/Role/CreateRoleRequest.cs
Normal file
10
MainProject/Models/Api/Request/Role/CreateRoleRequest.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.Role;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Request.Role;
|
||||
|
||||
public class CreateRoleRequest
|
||||
{
|
||||
[Required(ErrorMessage = "Data is required")]
|
||||
public required CreateRoleRequestData? Data { get; set; }
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.User;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Request.User;
|
||||
|
||||
public class CreateUserRequest
|
||||
{
|
||||
#nullable enable
|
||||
public CreateUserRequestData? Data { get; set; }
|
||||
#nullable disable
|
||||
[Required(ErrorMessage = "Data is required")]
|
||||
public required CreateUserRequestData Data { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
14
MainProject/Models/Api/Request/User/UpdateUserRequest.cs
Normal file
14
MainProject/Models/Api/Request/User/UpdateUserRequest.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Data.User;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Request.User;
|
||||
|
||||
public class UpdateUserRequest
|
||||
{
|
||||
[Required(ErrorMessage = "Data is required")]
|
||||
public required UpdateUserRequestData Data { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace BasicDotnetTemplate.MainProject.Models.Api.Response.Auth;
|
||||
public class AuthenticateResponse : BaseResponse<AuthenticatedUser>
|
||||
{
|
||||
public AuthenticateResponse(int status, string? message, AuthenticatedUser? data) : base(status, message, data) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@ public class BaseResponse<T>
|
||||
|
||||
public virtual dynamic? Data { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
8
MainProject/Models/Api/Response/Role/GetRoleResponse.cs
Normal file
8
MainProject/Models/Api/Response/Role/GetRoleResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Common.Role;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Api.Response.Role;
|
||||
|
||||
public class GetRoleResponse : BaseResponse<RoleDto>
|
||||
{
|
||||
public GetRoleResponse(int status, string? message, RoleDto? data) : base(status, message, data) { }
|
||||
}
|
||||
@@ -5,4 +5,4 @@ namespace BasicDotnetTemplate.MainProject.Models.Api.Response.User;
|
||||
public class GetUserResponse : BaseResponse<UserDto>
|
||||
{
|
||||
public GetUserResponse(int status, string? message, UserDto? data) : base(status, message, data) { }
|
||||
}
|
||||
}
|
||||
|
||||
9
MainProject/Models/Common/OperationInfo.cs
Normal file
9
MainProject/Models/Common/OperationInfo.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Common;
|
||||
|
||||
public class OperationInfo
|
||||
{
|
||||
#nullable enable
|
||||
public string? Operation { get; set; }
|
||||
public List<string>? Roles { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
9
MainProject/Models/Common/PermissionInfo.cs
Normal file
9
MainProject/Models/Common/PermissionInfo.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Common;
|
||||
|
||||
public class PermissionInfo
|
||||
{
|
||||
#nullable enable
|
||||
public string? System { get; set; }
|
||||
public List<RolePermissionModuleOperation>? RolePermissionModuleOperations { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
8
MainProject/Models/Common/PermissionsFile.cs
Normal file
8
MainProject/Models/Common/PermissionsFile.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Common;
|
||||
|
||||
public class PermissionsFile
|
||||
{
|
||||
#nullable enable
|
||||
public List<PermissionInfo>? PermissionInfos { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Common;
|
||||
|
||||
public class RolePermissionModuleOperation
|
||||
{
|
||||
#nullable enable
|
||||
public string? Module { get; set; }
|
||||
public List<OperationInfo>? Operations { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
@@ -8,4 +8,4 @@ namespace BasicDotnetTemplate.MainProject.Models.Database.Mongo
|
||||
[BsonId]
|
||||
public ObjectId Id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
MainProject/Models/Database/SqlServer/PermissionModule.cs
Normal file
11
MainProject/Models/Database/SqlServer/PermissionModule.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Database.SqlServer
|
||||
{
|
||||
public class PermissionModule : Base
|
||||
{
|
||||
[MaxLength(100)]
|
||||
public required string Name { get; set; }
|
||||
public required bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
10
MainProject/Models/Database/SqlServer/PermissionOperation.cs
Normal file
10
MainProject/Models/Database/SqlServer/PermissionOperation.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Database.SqlServer
|
||||
{
|
||||
public class PermissionOperation : Base
|
||||
{
|
||||
[MaxLength(100)]
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
}
|
||||
11
MainProject/Models/Database/SqlServer/PermissionSystem.cs
Normal file
11
MainProject/Models/Database/SqlServer/PermissionSystem.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Database.SqlServer
|
||||
{
|
||||
public class PermissionSystem : Base
|
||||
{
|
||||
[MaxLength(100)]
|
||||
public required string Name { get; set; }
|
||||
public required bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Database.SqlServer
|
||||
{
|
||||
public class PermissionSystemModule : Base
|
||||
{
|
||||
public required int PermissionSystemId { get; set; }
|
||||
public required int PermissionModuleId { get; set; }
|
||||
public required PermissionSystem PermissionSystem { get; set; }
|
||||
public required PermissionModule PermissionModule { get; set; }
|
||||
public required bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Database.SqlServer
|
||||
{
|
||||
public class PermissionSystemModuleOperation : Base
|
||||
{
|
||||
public required int PermissionSystemModuleId { get; set; }
|
||||
public required int PermissionOperationId { get; set; }
|
||||
public required bool Enabled { get; set; }
|
||||
public required PermissionSystemModule PermissionSystemModule { get; set; }
|
||||
public required PermissionOperation PermissionOperation { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Database.SqlServer
|
||||
{
|
||||
public class RolePermissionSystemModuleOperation : Base
|
||||
{
|
||||
public required int RoleId { get; set; }
|
||||
public required int PermissionSystemModuleOperationId { get; set; }
|
||||
public required bool Active { get; set; }
|
||||
public required Role Role { get; set; }
|
||||
public required PermissionSystemModuleOperation PermissionSystemModuleOperation { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,10 @@ public class User : Base
|
||||
[MaxLength(200)]
|
||||
public required string Email { get; set; }
|
||||
public required string PasswordSalt { get; set; }
|
||||
public required string PasswordHash { get; set; }
|
||||
#nullable enable
|
||||
public string? PasswordPepper { get; set; }
|
||||
#nullable disable
|
||||
public required int PasswordIterations { get; set; }
|
||||
public required Role Role { get; set; }
|
||||
public required bool IsTestUser { get; set; }
|
||||
|
||||
|
||||
@@ -9,6 +9,6 @@ public class AppSettings
|
||||
public DatabaseSettings? DatabaseSettings { get; set; }
|
||||
public JwtSettings? JwtSettings { get; set; }
|
||||
public EncryptionSettings? EncryptionSettings { get; set; }
|
||||
|
||||
public PermissionsSettings? PermissionsSettings { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ public class DatabaseConnection
|
||||
public string? Postgres { get; set; }
|
||||
public string? Mongodb { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ public class DatabaseSettings
|
||||
public string? MongoDbConnectionString { get; set; }
|
||||
public string? PostgreSQLConnectionString { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
public class EncryptionSettings
|
||||
{
|
||||
#nullable enable
|
||||
public string? SaltKey { get; set; }
|
||||
public string? Salt { get; set; }
|
||||
public string? Pepper { get; set; }
|
||||
public int? Iterations { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ public class JwtSettings
|
||||
public int? ExpiredAfterMinsOfInactivity { get; set; }
|
||||
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ public class OpenApiSettings
|
||||
public OpenApiSettingsDetails? OpenApiContact { get; set; }
|
||||
public OpenApiSettingsDetails? OpenApiLicense { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ public class OpenApiSettingsDetails
|
||||
public string? Name { get; set; }
|
||||
public string? Url { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
8
MainProject/Models/Settings/PermissionsSettings.cs
Normal file
8
MainProject/Models/Settings/PermissionsSettings.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class PermissionsSettings
|
||||
{
|
||||
#nullable enable
|
||||
public string? FilePath { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
@@ -5,4 +5,4 @@ public class PrivateSettings
|
||||
#nullable enable
|
||||
public DatabaseConnection? DatabaseConnection { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user