using DAL.Models.Filters;
using DAL.Repositories;
using Microsoft.AspNetCore.Http;
using StaffDBServer.Controllers;
using Xunit;
using XUnitWebApi.SharedConfig;

namespace XUnitWebApi.Controller
{
    public class Test_Controller_Filter
    {
        //----Check_GetEntityFilteredListController

        [Fact]
        public async Task Check_GetWindreamInputFolderFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                WindreamInputFolderFilter filter = new WindreamInputFolderFilter();
                filter.ClientId = 24110;
                WindreamInputFolderRepository repository = new WindreamInputFolderRepository();
                WindreamInputFolderController controller = new WindreamInputFolderController(repository);
                dynamic result = await controller.GetWindreamInputFolderListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamSearchToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                DepartmentFilter filter = new DepartmentFilter();
                filter.DepartmentId = 16;
                WindreamSearchToDepartmentRepository repository = new WindreamSearchToDepartmentRepository();
                WindreamSearchToDepartmentController controller = new WindreamSearchToDepartmentController(repository);
                dynamic result = await controller.GetWindreamSearchToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamSearchItemToWindreamSearchToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                WindreamSearchToDepartmentFilter filter = new WindreamSearchToDepartmentFilter();
                filter.DepartmentId = 16;
                WindreamSearchItemToWindreamSearchToDepartmentRepository repository = new WindreamSearchItemToWindreamSearchToDepartmentRepository();
                WindreamSearchItemToWindreamSearchToDepartmentController controller = new WindreamSearchItemToWindreamSearchToDepartmentController(repository);
                dynamic result = await controller.GetWindreamSearchItemToWindreamSearchToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamSearchItemFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                ClientIdFilter filter = new ClientIdFilter();
                filter.ClientId = 24110;
                WindreamSearchItemRepository repository = new WindreamSearchItemRepository();
                WindreamSearchItemController controller = new WindreamSearchItemController(repository);
                dynamic result = await controller.GetWindreamSearchItemListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamSearchFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                ClientIdFilter filter = new ClientIdFilter();
                filter.ClientId = 24110;
                WindreamSearchRepository repository = new WindreamSearchRepository();
                WindreamSearchController controller = new WindreamSearchController(repository);
                dynamic result = await controller.GetWindreamSearchListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamIndexToWindreamSearchToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                WindreamSearchToDepartmentFilter filter = new WindreamSearchToDepartmentFilter();
                filter.DepartmentId = 16;
                WindreamIndexToWindreamSearchToDepartmentRepository repository = new WindreamIndexToWindreamSearchToDepartmentRepository();
                WindreamIndexToWindreamSearchToDepartmentController controller = new WindreamIndexToWindreamSearchToDepartmentController(repository);
                dynamic result = await controller.GetWindreamIndexToWindreamSearchToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamIndexFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                ClientIdFilter filter = new ClientIdFilter();
                filter.ClientId = 24110;
                WindreamIndexRepository repository = new WindreamIndexRepository();
                WindreamIndexController controller = new WindreamIndexController(repository);
                dynamic result = await controller.GetWindreamIndexListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWindreamColumnsToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                DepartmentFilter filter = new DepartmentFilter();
                filter.DepartmentId = 16;
                WindreamColumnsToDepartmentRepository repository = new WindreamColumnsToDepartmentRepository();
                WindreamColumnsToDepartmentController controller = new WindreamColumnsToDepartmentController(repository);
                dynamic result = await controller.GetWindreamColumnsToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWebAppToWebAppRoleFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                WebAppFilter filter = new WebAppFilter();
                filter.WebAppId = 1;
                WebAppToWebAppRoleRepository repository = new WebAppToWebAppRoleRepository();
                WebAppToWebAppRoleController controller = new WebAppToWebAppRoleController(repository);
                dynamic result = await controller.GetWebAppToWebAppRoleListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWebAppToWebAppAdditionalRoleFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeToWebAppFilter filter = new EmployeeToWebAppFilter();
                filter.EmployeeToWebAppId = 73;
                WebAppToWebAppAdditionalRoleRepository repository = new WebAppToWebAppAdditionalRoleRepository();
                WebAppToWebAppAdditionalRoleController controller = new WebAppToWebAppAdditionalRoleController(repository);
                dynamic result = await controller.GetWebAppToWebAppAdditionalRoleListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWebAppToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeToWebAppFilter filter = new EmployeeToWebAppFilter();
                filter.EmployeeToWebAppId = 39;
                WebAppToDepartmentRepository repository = new WebAppToDepartmentRepository();
                WebAppToDepartmentController controller = new WebAppToDepartmentController(repository);
                dynamic result = await controller.GetWebAppToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetWebAppAdditionalRoleFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                WebAppFilter filter = new WebAppFilter();
                filter.WebAppId = 3;
                WebAppAdditionalRoleRepository repository = new WebAppAdditionalRoleRepository();
                WebAppAdditionalRoleController controller = new WebAppAdditionalRoleController(repository);
                dynamic result = await controller.GetWebAppAdditionalRoleListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetEmployeeToWebAppFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFilter filter = new EmployeeFilter();
                filter.LoginName = "y.kochetenko";
                EmployeeToWebAppRepository repository = new EmployeeToWebAppRepository();
                EmployeeToWebAppController controller = new EmployeeToWebAppController(repository);
                dynamic result = await controller.GetEmployeeToWebAppListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetEmployeeToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFilter filter = new EmployeeFilter();
                filter.EmployeeId = 29;
                EmployeeToDepartmentRepository repository = new EmployeeToDepartmentRepository();
                EmployeeToDepartmentController controller = new EmployeeToDepartmentController(repository);
                dynamic result = await controller.GetEmployeeToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetEmployeeToAttributeFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFilter filter = new EmployeeFilter();
                filter.EmployeeId = 29;
                EmployeeToAttributeRepository repository = new EmployeeToAttributeRepository();
                EmployeeToAttributeController controller = new EmployeeToAttributeController(repository);
                dynamic result = await controller.GetEmployeeToAttributeListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetEmployeeFilteredClientIdController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFullFilter filter = new EmployeeFullFilter();
                filter.ClientId = 24110;
                EmployeeRepository repository = new EmployeeRepository();
                EmployeeController controller = new EmployeeController(repository);
                dynamic result = await controller.GetEmployeeListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetEmployeeFilteredisActive()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFullFilter filter = new EmployeeFullFilter();
                filter.IsActive = false;
                EmployeeRepository repository = new EmployeeRepository();
                EmployeeController controller = new EmployeeController(repository);
                dynamic result = await controller.GetEmployeeListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetEmployeeFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFullFilter filter = new EmployeeFullFilter();
                filter.Name = "";
                EmployeeRepository repository = new EmployeeRepository();
                EmployeeController controller = new EmployeeController(repository);
                dynamic result = await controller.GetEmployeeListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetDocumentArtToDepartmentFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                DepartmentFilter filter = new DepartmentFilter();
                filter.DepartmentId = 16;
                DocumentArtToDepartmentRepository repository = new DocumentArtToDepartmentRepository();
                DocumentArtToDepartmentController controller = new DocumentArtToDepartmentController(repository);
                dynamic result = await controller.GetDocumentArtToDepartmentListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        [Fact]
        public async Task Check_GetDepartmentToWebAppToEmployeeForWindreamFilteredListController()
        {
            Shared_Test_Config.Init_Webapi_Context();

            try
            {
                EmployeeFilter filter = new EmployeeFilter();
                filter.EmployeeId = 29;
                DepartmentToWebAppToEmployeeForWindreamRepository repository = new DepartmentToWebAppToEmployeeForWindreamRepository();
                DepartmentToWebAppToEmployeeForWindreamController controller = new DepartmentToWebAppToEmployeeForWindreamController(repository);
                dynamic result = await controller.GetDepartmentToWebAppToEmployeeForWindreamListAsync(filter);
                Assert.NotNull(result);
                Assert.Equal(StatusCodes.Status200OK, result.StatusCode);

                var entity = result.Value;
                Assert.NotNull(entity);

                Assert.NotEqual(entity.Count, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}