public async Task GetLocationShouldAddTheLocationIfItIsNotThere()
        {
            var list = new List <Location>()
            {
                new Location
                {
                    Id      = 1,
                    Name    = "Plovdiv/Bulgaria",
                    Country = new Country
                    {
                        Name = "Bulgaria",
                    },
                },
                new Location
                {
                    Id      = 2,
                    Name    = "Sofia/Bulgaria",
                    Country = new Country
                    {
                        Name = "Bulgaria",
                    },
                },
                new Location
                {
                    Id      = 3,
                    Name    = "Stara Zagora/Bulgaria",
                    Country = new Country
                    {
                        Name = "Bulgaria",
                    },
                },
            };

            var repository = new Mock <IRepository <Location> >();

            repository.Setup(r => r.All()).Returns(() => list.AsQueryable());
            repository.Setup(r => r.AddAsync(It.IsAny <Location>())).Callback((Location location) => list.Add(location));
            var service = new LocationsService(repository.Object);

            var location = await service.GetLocation("Peshtera", new Country { Name = "Bulgaria" });

            Assert.Equal("Peshtera/Bulgaria", location.Name);
            repository.Verify(x => x.AddAsync(It.IsAny <Location>()), Times.Once);
        }
        public async Task GetLocationShouldReturnTheCorrectLocation()
        {
            var list = new List <Location>()
            {
                new Location
                {
                    Id      = 1,
                    Name    = "Plovdiv/Bulgaria",
                    Country = new Country
                    {
                        Name = "Bulgaria",
                    },
                },
                new Location
                {
                    Id      = 2,
                    Name    = "Sofia/Bulgaria",
                    Country = new Country
                    {
                        Name = "Bulgaria",
                    },
                },
                new Location
                {
                    Id      = 3,
                    Name    = "Stara Zagora/Bulgaria",
                    Country = new Country
                    {
                        Name = "Bulgaria",
                    },
                },
            };

            var repository = new Mock <IRepository <Location> >();

            repository.Setup(r => r.All()).Returns(() => list.AsQueryable());
            var service = new LocationsService(repository.Object);

            var location = await service.GetLocation("Plovdiv", new Country { Name = "Bulgaria" });

            Assert.Equal(list[0].Name, location.Name);
            repository.Verify(x => x.All(), Times.Once);
        }
Esempio n. 3
0
 public ActionResult <string> GetPlaces(string id)
 {
     return(_locationsService.GetLocation(id));
 }