Ejemplo n.º 1
0
        public async Task GetNonExistingPurchasersForCountryFromDatabaseTest()
        {
            // arrange
            HAVIdatabaseContext dbContext         = CreateDbContext();
            CountryRepository   countryRepository = new CountryRepository(dbContext);
            Country             country           = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryName = "Name",
                CountryCode = "Code",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };
            PurchaserRepository repository = new PurchaserRepository(dbContext);
            await countryRepository.AddCountry(country);

            // act
            List <Purchaser> result = await repository.GetPurchasersForCountry(1);

            // assert
            Assert.IsTrue(result.Count == 0);

            dbContext.Dispose();
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> GetPurchasersForCountry(int id)
        {
            try
            {
                var result = await _purchaserRepository.GetPurchasersForCountry(id);

                if (result == null)
                {
                    return(Ok(new List <Purchaser>()));
                }
                return(Ok(result));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }