GetCountries() private method

private GetCountries ( ) : IEnumerable
return IEnumerable
Esempio n. 1
0
        public async Task GetCountries_ShouldGetAllCountries()
        {
            // Arrange
            IEnumerable <CountryResource> expectedCountries = new[]
            {
                new CountryResource {
                    CountryId = 1
                },
                new CountryResource {
                    CountryId = 2
                }
            };

            Mock <IMediator> mediatorMock = new Mock <IMediator>();

            mediatorMock
            .Setup(m => m.Send(It.IsAny <GetCountriesQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(expectedCountries);

            CountryController controller = new CountryController(mediatorMock.Object);

            // Act
            ActionResult <IEnumerable <CountryResource> > response = await controller.GetCountries();

            // Assert
            OkObjectResult result = Assert.IsType <OkObjectResult>(response.Result);

            IEnumerable <CountryResource> actualCountries = (IEnumerable <CountryResource>)result.Value;

            Assert.Equal(2, actualCountries.Count());
        }
Esempio n. 2
0
        public async Task GetCountries_ReturnsAllCountries()
        {
            _mockRepositoryCountry.Setup(x => x.GetAll()).ReturnsAsync(_countries);

            var result = await _countryController.GetCountries();

            Assert.AreEqual(2, result.Count());
        }
        public void GetCountriesTests()
        {
            CountryController controller = new CountryController(_mockCountryService.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            var countries = controller.GetCountries();

            Assert.IsNotNull(countries);
        }
Esempio n. 4
0
        public async Task GetCountries_Returns_AllItems()
        {
            var data = new List <Country>()
            {
                new Country()
                {
                    CountryId = 1, IsoCode = "AA", Name = "C1"
                },
                new Country()
                {
                    CountryId = 2, IsoCode = "BB", Name = "C2"
                },
                new Country()
                {
                    CountryId = 3, IsoCode = "CC", Name = "C3"
                },
            };
            var asyncData = Task.FromResult(data.AsEnumerable());

            var repMock = new Mock <ICountryRepository>();

            repMock.Setup(m => m.GetAsync()).Returns(asyncData);
            var uowMock = new Mock <IUnitOfWork>();

            uowMock.Setup(m => m.CountryRepository).Returns(repMock.Object);
            var factoryMock = new Mock <IStoreFactory>();

            factoryMock.Setup(m => m.CreateUnitOfWork()).Returns(uowMock.Object);
            var urlHelper = new Mock <UrlHelper>();

            urlHelper.Setup(m => m.Link("PostCountry", null))
            .Returns("api/country");
            urlHelper.Setup(m => m.Link("Country", It.IsAny <object>()))
            .Returns("api/country/1");

            var c = new CountryController(factoryMock.Object);

            c.Url = urlHelper.Object;

            var result = await c.GetCountries();

            var contentResult = result as OkNegotiatedContentResult <GetCountriesResult>;

            Assert.IsNotNull(contentResult);
            Assert.IsTrue(contentResult.Content.PostURL == "api/country");
            Assert.IsTrue(contentResult.Content.Countries.All(x => x.GetUrl == "api/country/1"));
            Assert.IsTrue(contentResult.Content.Countries.Count() == 3);
        }
        public void Get_PassID_ReturnEntity()
        {
            using (IDataContext livekartFakeContext = new LiveKartFakeContext())
                using (IUnitOfWork unitOfWork = new UnitOfWork(livekartFakeContext))
                    using (CountryController controller = new CountryController(unitOfWork))
                    {
                        //arrenge
                        long CountryID = 10;

                        //act
                        var country = controller.GetCountries(CountryID);

                        //assert
                        Assert.AreEqual(13, 13);
                    }
        }
Esempio n. 6
0
        public async Task Get_All_Countries()
        {
            List <CountryDto> mockCountries = MockCountries();

            var mockRepository = new Mock <IRepository <Country, CountryDto, CountryId> >();

            mockRepository.Setup(repo => repo.GetAllDtoAsync())
            .Returns(() => Task.FromResult(mockCountries.AsEnumerable()));

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            var countryService = new CountryService(mockRepository.Object, mockUnitOfWork.Object);

            var countryController = new CountryController(countryService);
            var result            = await countryController.GetCountries();

            Assert.Equal(10, result.Count());
            mockRepository.Verify(mock => mock.GetAllDtoAsync(), Times.Once());
        }
Esempio n. 7
0
        public void Get_WhenCalled_ReturnsAllItems()
        {
            CountryController controller;
            var countries = GetIEnumerableCountry();
            var mockRepo  = new Mock <IRepositoryManager>();

            mockRepo.Setup(a => a.Country.GetAllCountriesAsync(false)).Returns(countries);
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper = mockMapper.CreateMapper();

            controller = new CountryController(mockRepo.Object, mapper);
            //Act
            var okResult = controller.GetCountries().Result as OkObjectResult;

            //Assert
            Assert.Equal(4, okResult.Value);
        }