Ejemplo n.º 1
0
        public void Given_GetIsNotOK_When_GetCountries_Then_CountriesNotFoundExceptionIsThrown()
        {
            //Arrange
            var mockHttpRequestFactory = new Mock <IHttpRequestFactory>();

            mockHttpRequestFactory.Setup(x => x.Get(
                                             It.IsAny <string>(), It.IsAny <string>()
                                             ))
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.NotFound
            });

            var mockOptions = new Mock <IOptions <ApiSettings> >();

            mockOptions.SetupGet(x => x.Value).Returns(new ApiSettings());

            var sut = new CountryApi(
                mockHttpRequestFactory.Object,
                mockOptions.Object
                );

            //Act
            Func <Task> func = async() => await sut.GetCountries();

            //Assert
            func.Should().Throw <CountriesNotFoundException>();
        }
Ejemplo n.º 2
0
        public IActionResult GetCountries()
        {
            var countries = CountryApi.GetCountries();

            if (countries == null)
            {
                return(NotFound());
            }

            return(Ok(countries));
        }
Ejemplo n.º 3
0
        public async void Given_GetIsOK_When_GetCountries_Then_ReturnList()
        {
            //Arrange
            var list = new List <CountryDto>
            {
                new CountryDto
                {
                    Name = "England"
                },
                new CountryDto
                {
                    Name = "Ireland"
                },
                new CountryDto
                {
                    Name = "Spain"
                }
            };

            var mockHttpRequestFactory = new Mock <IHttpRequestFactory>();

            mockHttpRequestFactory.Setup(x => x.Get(
                                             It.IsAny <string>(), It.IsAny <string>()
                                             ))
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new JsonContent(list)
            });

            var mockOptions = new Mock <IOptions <ApiSettings> >();

            mockOptions.SetupGet(x => x.Value).Returns(new ApiSettings());

            var sut = new CountryApi(
                mockHttpRequestFactory.Object,
                mockOptions.Object
                );

            //Act
            var result = await sut.GetCountries();

            //Assert
            result.Should().NotBeNull();
            result.ToList().Count().Should().Be(3);
        }