using DAL.Models.Filters;
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_Filter : TestBuilder
    {
        //----Check_GetEntityFilteredListController

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

            try
            {
                WindreamInputFolderFilter filter = new WindreamInputFolderFilter();
                filter.ClientId = 24110;
                var controller = Provider.GetRequiredService<WindreamInputFolderController>();
                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;
                var controller = Provider.GetRequiredService<WindreamSearchToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<WindreamSearchItemToWindreamSearchToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<WindreamSearchItemController>();
                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;
                var controller = Provider.GetRequiredService<WindreamSearchController>();
                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;
                var controller = Provider.GetRequiredService<WindreamIndexToWindreamSearchToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<WindreamIndexController>();
                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;
                var controller = Provider.GetRequiredService<WindreamColumnsToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<WebAppToWebAppRoleController>();
                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;
                var controller = Provider.GetRequiredService<WebAppToWebAppAdditionalRoleController>();
                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;
                var controller = Provider.GetRequiredService<WebAppToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<WebAppAdditionalRoleController>();
                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";
                var controller = Provider.GetRequiredService<EmployeeToWebAppController>();
                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;
                var controller = Provider.GetRequiredService<EmployeeToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<EmployeeToAttributeController>();
                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;
                var controller = Provider.GetRequiredService<EmployeeController>();
                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;
                var controller = Provider.GetRequiredService<EmployeeController>();
                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 = "";
                var controller = Provider.GetRequiredService<EmployeeController>();
                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;
                var controller = Provider.GetRequiredService<DocumentArtToDepartmentController>();
                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;
                var controller = Provider.GetRequiredService<DepartmentToWebAppToEmployeeForWindreamController>();
                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;
            }
        }
    }
}