Example #1
0
        public async Task WhenExecuteAddCountryIfModelIsValidThenGetOkResult()
        {
            CountryDTO             country = new CountryDTO();
            Mock <ICountryService> mock    = new Mock <ICountryService>();

            mock.Setup(repo => repo.Add(country)).ReturnsAsync(country);

            TourController controller = new TourController(null, mock.Object, null, null, null, null, null, null, null, null);
            IActionResult  result     = await controller.AddCountry(country);

            object resCountry = (result as OkObjectResult)?.Value;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(resCountry, typeof(CountryDTO));
            Assert.IsNotNull(resCountry as CountryDTO);
        }
Example #2
0
        public async Task WhenExecuteAddCountryIfModelNotValidThenBadRequestResult()
        {
            CountryDTO             country = null;
            Mock <ICountryService> mock    = new Mock <ICountryService>();

            mock.Setup(repo => repo.Add(country)).ReturnsAsync(country);

            TourController controller = new TourController(null, mock.Object, null, null, null, null, null, null, null, null);

            controller.ModelState.AddModelError("", "");
            IActionResult result = await controller.AddCountry(country);

            object modelState = (result as BadRequestObjectResult)?.Value;

            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.IsInstanceOfType(modelState, typeof(SerializableError));
            Assert.IsNotNull(modelState as SerializableError);
        }