using DAL.Repositories; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using StaffDBServer.Controllers; using Xunit; using XUnitWebApi.SharedConfig; using XUnitWebApi.Test; namespace XUnitWebApi.Controller { public class Test_Controller_Entity : TestBuilder { //----Check_GetEntityController [Fact] public async Task Check_GetSubsidiaryController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.SubsidiaryId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamInputFolderController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 49; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamInputFolderId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamSearchToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamSearchToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamSearchItemToWindreamSearchToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamSearchItemToWindreamSearchToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamSearchItemController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamSearchItemId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamSearchController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamSearchId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamIndexToWindreamSearchToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamIndexToWindreamSearchToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamIndexController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamIndexId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWindreamColumnsToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WindreamColumnsToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWebAppToWebAppRoleController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 2; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WebAppToWebAppRoleId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWebAppToWebAppAdditionalRoleController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 70; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WebAppToWebAppAdditionalRoleId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWebAppToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 100; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WebAppToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWebAppAdditionalRoleController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WebAppAdditionalRoleId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetEmployeeToWebAppController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 300; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.EmployeeToWebAppId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetEmployeeToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.EmployeeToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetEmployeeToAttributeController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 100; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.EmployeeToAttributeId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetEmployeeController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.EmployeeId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetDocumentArtToDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.DocumentArtToDepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetDepartmentToWebAppToEmployeeForWindreamController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.DepartmentToWebAppToEmployeeForWindreamId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWebAppRoleController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 10; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WebAppRoleId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetWebAppController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.WebAppId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetRangController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.RangId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetProjectController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.ProjectId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetEmployeeStatusController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.EmployeeStatusId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetEmployeeAttributeController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.EmployeeAttributeId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetDocumentArtController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.DocumentArtId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetDepartmentController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.DepartmentId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetCostCentreController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 100; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.CostCentreId); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_Employee() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 272; var repo = Provider.GetService(); var entity= await repo.GetByIdAsync(entityId); entity.PhoneNo = "1234"; await repo.SaveChangesAsync(); } catch (Exception ex) { throw ex; } } [Fact] public async Task Check_GetAdWebAppToWebAppRoleController() { Shared_Test_Config.Init_Webapi_Context(); try { int entityId = 1; var controller = Provider.GetService(); dynamic result = await controller.GetEntityAsync(entityId); Assert.NotNull(result); Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode); var entity = result.Result.Value; Assert.NotNull(entity); if (entityId > 0) Assert.Equal(entityId, entity.AdWebAppToWebAppRoleId); } catch (Exception ex) { throw ex; } } } }