コード例 #1
0
        public async void HRCountriesOnGetFromPagingWithServiceNormalResultExpectCode200()
        {
            PagingParameterInModel model = new PagingParameterInModel()
            {
                PageNumber = 0,
                PageSize   = 10
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(new System.Collections.Generic.List <string>()
            {
                "XX"
            })
            {
                ThrowException = false
            };
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status200OK);
            }
        }
コード例 #2
0
        public async void HRCountriesOnGetFromPagingWithModelPageSizeGreaterThanMaxSizeExpectCodeStatus413PayloadTooLarge()
        {
            PagingParameterInModel model = new PagingParameterInModel()
            {
                PageNumber = 0,
                PageSize   = 51
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(null)
            {
                ThrowException = true
            };

            service.ExceptionToThrow = new IndexOutOfRangeException();
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status413PayloadTooLarge);
            }
        }
コード例 #3
0
        public async void HRCountriesControllerOnGetAllWithValidPagingInExpectItemsAndCodeStatus200()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>();

            for (int i = 0; i < 300; i++)
            {
                list.Add(new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"));
            }
            CoreCountriesServiceStub service      = new CoreCountriesServiceStub(list);
            HRCountriesController    ctrl         = new HRCountriesController(service, null);
            PagingParameterInModel   invalidModel = new PagingParameterInModel()
            {
                PageNumber = 1, PageSize = 100
            };
            Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null);
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK);
            Assert.True(resultService.Result.Item2 != null);
            Assert.True(resultService.Result.Item2.HasNextPage);
            Assert.True(resultService.Result.Item2.HasPreviousPage);
            Assert.True(resultService.Result.Item2.TotalItemsCount == 300);
            int j = 100;

            foreach (HRCountry iterator in resultService.Result.Item2.PageItems)
            {
                j++;
            }
            Assert.True(j == 200);
        }
コード例 #4
0
        public async void HRCountriesOnGetFromPagingWithServiceThrowingIndexOutOfRangeExceptionExpectStatus500InternalServerError()
        {
            PagingParameterInModel   model   = new PagingParameterInModel();
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(null)
            {
                ThrowException   = true,
                ExceptionToThrow = new IndexOutOfRangeException()
            };

            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status416RequestedRangeNotSatisfiable);
            }
        }
コード例 #5
0
        public async void HRCountriesOnGetFromPagingWithCanOrderReturnoingFalseExpectStatus400BadRequest()
        {
            PagingParameterInModel model = new PagingParameterInModel()
            {
                PageNumber = 0,
                PageSize   = 50
            };
            HRSortingParamModel sort = new HRSortingParamModel()
            {
                OrderBy = "FIELD1;ASC"
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(null)
            {
                ThrowException   = true,
                ExceptionToThrow = new IndexOutOfRangeException()
            };
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = false
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       sort,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status400BadRequest);
            }
        }
        public async void GetAllLangagesAsync_With_Service_OK_Return_Languages_Without_Update()
        {
            HRLangagesByContinentControllerForker forker = new HRLangagesByContinentControllerForker();
            CoreCountriesServiceStub serviceStub         = new CoreCountriesServiceStub(null);

            serviceStub.Languages = new List <Language>()
            {
                new Language()
                {
                    Iso6391 = "1"
                }, new Language()
                {
                    Iso6391 = "2"
                }
            };
            using (Task <(int, IEnumerable <Language>)> task = forker.GetAllLangagesAsync(serviceStub))
            {
                await task;
                Assert.True(task.Result.Item1 == StatusCodes.Status200OK);
                Assert.NotNull(task.Result.Item2);
                Assert.True(task.Result.Item2.ToList().Count == 2);
                Assert.True(task.Result.Item2.ToList()[0].Iso6391 == "1");
                Assert.True(task.Result.Item2.ToList()[1].Iso6391 == "2");
            }
        }
コード例 #7
0
        public void HRContinentController_On_GetID_With_Service_Exception_Return_HTTP500()
        {
            HRContinentControllerForker forfker = new HRContinentControllerForker();
            CoreCountriesServiceStub    service = new CoreCountriesServiceStub(null);

            service.ThrowException = true;
            (int, String)result    = forfker.Get(String.Empty, service);
            Assert.Equal(result.Item1, StatusCodes.Status500InternalServerError);
            Assert.Null(result.Item2);
        }
        public async void GetLangagesByContinentAsync_With_Convertible_Region_Return_Status_200()
        {
            HRLangagesByContinentControllerForker forker = new HRLangagesByContinentControllerForker();
            CoreCountriesServiceStub serviceStub         = new CoreCountriesServiceStub(null);

            using (Task <(int, IEnumerable <Language>)> task = forker.GetLangagesByContinentAsync(serviceStub, "Africa"))
            {
                await task;
                Assert.True(task.Result.Item1 == StatusCodes.Status200OK);
            }
        }
        public async void GetHRCountriesByContinentAsync_With_Null_Non_Convertible_Region_Return_Error400()
        {
            HRCountriesByContinentControllerForker forker = new HRCountriesByContinentControllerForker();
            CoreCountriesServiceStub serviceStub          = new CoreCountriesServiceStub(null);

            using (Task <(int, IEnumerable <HRCountry>)> task = forker.GetHRCountriesByContinentAsync(serviceStub, "NonConvertibleRegion"))
            {
                await task;
                Assert.True(task.Result.Item1 == StatusCodes.Status400BadRequest);
            }
        }
        public async void GetAllLangagesAsync_With_Service_Throwing_Exception_Return_Error500()
        {
            HRLangagesByContinentControllerForker forker = new HRLangagesByContinentControllerForker();
            CoreCountriesServiceStub serviceStub         = new CoreCountriesServiceStub(null);

            serviceStub.ExceptionToThrow = new Exception("A");
            using (Task <(int, IEnumerable <Language>)> task = forker.GetAllLangagesAsync(null))
            {
                await task;
                Assert.True(task.Result.Item1 == StatusCodes.Status500InternalServerError);
            }
        }
コード例 #11
0
        public void HRContinentController_On_GetID_With_UnExisting_ID_Return_HTTP404()
        {
            HRContinentControllerForker forfker = new HRContinentControllerForker();
            CoreCountriesServiceStub    service = new CoreCountriesServiceStub(new List <string>()
            {
                "200"
            });

            service.ThrowException = false;
            (int, String)result    = forfker.Get("HR", service);
            Assert.Equal(result.Item1, StatusCodes.Status404NotFound);
            Assert.Equal(String.Empty, result.Item2);
        }
コード例 #12
0
        public async void HRCountriesControllerOnGetByIDWithExistingItemExpectItemAndCodeStatus200()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>()
            {
                new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"),
                new MongoDB.Bson.ObjectId("507f191e810c19729de860eb")
            };
            CoreCountriesServiceStub service       = new CoreCountriesServiceStub(list);
            HRCountriesController    ctrl          = new HRCountriesController(service, null);
            Task <(int, HRCountry)>  resultService = ctrl.GetFromID("507f191e810c19729de860ea");
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK);
            Assert.True(resultService.Result.Item2 != null && resultService.Result.Item2._id.Equals(new MongoDB.Bson.ObjectId("507f191e810c19729de860ea")));
        }
コード例 #13
0
        public async void HRCountriesControllerOnGetByIDWithIDNotBsonIDExpectStatus500InternalServerError()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>()
            {
                new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"),
                new MongoDB.Bson.ObjectId("507f191e810c19729de860eb")
            };
            CoreCountriesServiceStub service       = new CoreCountriesServiceStub(list);
            HRCountriesController    ctrl          = new HRCountriesController(service, null);
            Task <(int, HRCountry)>  resultService = ctrl.GetFromID("507a");
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status500InternalServerError);
            Assert.True(resultService.Result.Item2 == null);
        }
コード例 #14
0
        public async void HRCountriesControllerOnGetByIDUnknownExpectStatusCode404()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>()
            {
                new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"),
                new MongoDB.Bson.ObjectId("507f191e810c19729de860eb")
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(list);
            HRCountriesController    ctrl    = new HRCountriesController(service, null);

            Task <(int, HRCountry)> resultService = ctrl.GetFromID("507f191e810c19729de860ec");
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status404NotFound);
            Assert.True(resultService.Result.Item2 == null);
        }
        public async void GetHRCountriesByContinentAsync_With_Convertible_Region_Return_Status_200()
        {
            HRCountriesByContinentControllerForker forker = new HRCountriesByContinentControllerForker();
            CoreCountriesServiceStub serviceStub          = new CoreCountriesServiceStub(new List <string>()
            {
                "1"
            });

            using (Task <(int, IEnumerable <HRCountry>)> task = forker.GetHRCountriesByContinentAsync(serviceStub, "Africa"))
            {
                await task;
                Assert.True(task.Result.Item1 == StatusCodes.Status200OK);
                Assert.NotNull(task.Result.Item2);
                Assert.NotEmpty(task.Result.Item2.ToList());
                Assert.True(task.Result.Item2.ToList().Count == 1);
                Assert.True(task.Result.Item2.ToList()[0].Alpha3Code == "1");
            }
        }
コード例 #16
0
        public async void HRCountriesControllerOnGetAllWithInvalidPagingInExpectStatus416RequestedRangeNotSatisfiable()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>()
            {
                new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"),
                new MongoDB.Bson.ObjectId("507f191e810c19729de860eb")
            };
            CoreCountriesServiceStub service      = new CoreCountriesServiceStub(list);
            HRCountriesController    ctrl         = new HRCountriesController(service, null);
            PagingParameterInModel   invalidModel = new PagingParameterInModel()
            {
                PageNumber = 2, PageSize = 100
            };
            Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null);
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status416RequestedRangeNotSatisfiable);
            Assert.True(resultService.Result.Item2 == null);
        }
コード例 #17
0
        public async void HRCountriesController_On_GetByID_Null_Expect_Status400_BadRequest()
        {
            List <String> list = new List <String>()
            {
                "FR",
                "US"
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(list);
            IHRCommonForkerUtils     util    = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(util);

            using (Task <(int, HRCountry)> resultService = forker.GetFromIDAsync(null, service))
            {
                await resultService;
                Assert.True(resultService.Result.Item1 == StatusCodes.Status400BadRequest);
                Assert.True(resultService.Result.Item2 == null);
            }
        }
コード例 #18
0
        public async void HRCountriesForkerOnGetFromPagingWithNullServiceExpectStatus500InternalServerError()
        {
            PagingParameterInModel   model    = new PagingParameterInModel();
            CoreCountriesServiceStub service  = null;
            HRCommonForkerUtilsStub  utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status500InternalServerError);
            }
        }
コード例 #19
0
        public async void HRCountriesControllerOnGetAllWithExceptionThrownByServiceExpectStatus500InternalServerError()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>()
            {
                new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"),
                new MongoDB.Bson.ObjectId("507f191e810c19729de860eb")
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(list)
            {
                ThrowException = true
            };
            HRCountriesController  ctrl         = new HRCountriesController(service, null);
            PagingParameterInModel invalidModel = new PagingParameterInModel()
            {
                PageNumber = 2, PageSize = 100
            };
            Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null);
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status500InternalServerError);
            Assert.True(resultService.Result.Item2 == null);
        }