Exemplo n.º 1
0
        public void Validation_Success()
        {
            var city = new City("Poland", "Poznañ");

            service.AddCity(city);

            var existCity = service.CityList.FirstOrDefault(w => w.Name == city.Name);

            Assert.NotNull(existCity);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            GisService gisService = new GisService();

            //gisService.GetLocalData(); //Загружаем данные с локального источника
            gisService.GetData(); //Загружаем данные с сайта

            string       dbContext    = ConfigurationManager.AppSettings.Get("db.context");
            GisDbContext gisDbContext = new GisDbContext(dbContext);// подключаемся к БД

            CityService      cityService      = new CityService(gisDbContext);
            PrognosisService prognosisService = new PrognosisService(gisDbContext);

            do
            {
                // Если передаем аргумент при запуске, то считаем что это периодичность чтения данных,
                // иначе - проходим один раз и завершаем выполнение
                int period = (args.Length > 0) ? Int32.Parse(args[0]): 0;
                foreach (KeyValuePair <long, string> city in gisService.Cities)
                {
                    if (cityService.FindByName(city.Value) == null)
                    {
                        City cityObj = cityService.CreateCity(city.Key, city.Value);
                        cityService.AddCity(cityObj);
                    }
                    Prognosis prognosis = PrognosisService.ParsePrognosis(city.Key, gisService.GetPrognosisData(city.Key));
                    prognosisService.AddPrognosis(prognosis);
                }

                Thread.Sleep(period * 1000);
            } while (true && args.Length > 0);
        }
Exemplo n.º 3
0
        public async Task Throw_InvalidClientInputException_When_ParametersAreNotValid()
        {
            DbContextOptions <AlphaCinemaContext> contextOptions =
                new DbContextOptionsBuilder <AlphaCinemaContext>()
                .UseInMemoryDatabase(databaseName: "Throw_InvalidClientInputException_When_ParametersAreNotValid")
                .Options;

            // Arrange
            var cityName = "Te";

            var city = new City()
            {
                Name = cityName
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Cities.AddAsync(city);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var cityServices = new CityService(assertContext);
                await Assert.ThrowsExceptionAsync <InvalidClientInputException>(() =>
                                                                                cityServices.AddCity(cityName));
            }
        }
Exemplo n.º 4
0
        public async Task AddNewCity_WhenParametersAreCorrect(string cityName)
        {
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "AddNewCity_WhenParametersAreCorrect")
                                 .Options;

            var city = new City()
            {
                Name = cityName
            };

            using (var context = new AlphaCinemaContext(contextOptions))
            {
                await context.Cities.AddAsync(city);

                await context.SaveChangesAsync();

                var cityService = new CityService(context);

                city = await cityService.AddCity(cityName);
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                Assert.IsInstanceOfType(city, typeof(City));
                Assert.IsNotNull(city);
            }
        }
Exemplo n.º 5
0
        public void Throws_InvalidClientInputException_WhenCityNameIsNotCorrect(string cityName)
        {
            var mockContext = new Mock <AlphaCinemaContext>();

            var cityService = new CityService(mockContext.Object);

            Assert.ThrowsExceptionAsync <InvalidClientInputException>(() => cityService.AddCity(cityName));
        }
        public IActionResult Index()
        {
            CityService service = new CityService();

            service.AddCity(new DataTables.CityDataTable {
                Name = "Amman"
            });

            List <CityDataTable> list;

            list = service.ListCity();
            return(View());
        }
Exemplo n.º 7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            FillCityId();

            City objCity = new City
            {
                CityId  = Convert.ToInt32(txtCityId.Text),
                Name    = txtName.Text,
                StateId = (byte)cboStateId.SelectedValue
                          //StateId = Convert.ToByte(cboStateId.SelectedValue)
            };

            lblResult.Text = CityService.AddCity(objCity);

            CityService.ReadData(dgv);
        }
        public IActionResult Upload(IFormFile file, DateTime dateTime)
        {
            using var reader = new StreamReader(file.OpenReadStream());
            var    lines = new List <string>();
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                lines.Add(line);
            }

            String dt = dateTime.ToShortDateString();

            foreach (var l in lines)
            {
                if (l.StartsWith("\"\""))
                {
                    continue;
                }

                string[] words = l.Split(',');

                CityData TempCityData = new CityData
                {
                    Name = words[1].Substring(1, words[1].Length - 2),
                    Pop  = int.Parse(words[11])
                };

                _cityService.AddCity(TempCityData);

                CityDailyCaseData TempCityDailyCaseData = new CityDailyCaseData
                {
                    Name  = words[1].Substring(1, words[1].Length - 2),
                    Cases = int.Parse(words[2]),
                    Death = int.Parse(words[5]),
                    Test  = int.Parse(words[8]),
                    Date  = dateTime
                };

                _cityService.AddCityData(TempCityDailyCaseData);
            }

            ViewBag.dateTime = dt;
            return(View("Display", lines));
        }
Exemplo n.º 9
0
        public async Task Create_NewCity_When_CorrectParameters_ArePassed()
        {
            DbContextOptions <AlphaCinemaContext> contextOptions =
                new DbContextOptionsBuilder <AlphaCinemaContext>()
                .UseInMemoryDatabase(databaseName: "Create_NewCity_When_CorrectParameters_ArePassed")
                .Options;

            // Arrange
            var cityName = "TestCityName";

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var cityServices = new CityService(assertContext);
                var city         = await cityServices.AddCity(cityName);

                Assert.AreEqual(cityName, city.Name);
            }
        }
Exemplo n.º 10
0
        public void CallSaveChangesOnUsitData_WhenCityIsPassed()
        {
            // Arrange
            var mockedData  = new Mock <IUsitData>();
            var cityService = new CityService(mockedData.Object);

            var mockedCityRepository = new Mock <IGenericRepository <City> >();

            mockedData.Setup(d => d.Cities).Returns(mockedCityRepository.Object);

            var city = new City()
            {
                Id = 2, Name = "Name"
            };

            // Act
            cityService.AddCity(city);

            // Assert
            mockedData.Verify(d => d.SaveChanges(), Times.Once);
        }
Exemplo n.º 11
0
        public async Task <ActionResult <City> > PostCity(string cityName)
        {
            var newCity = await _cityService.AddCity(cityName);

            return(CreatedAtAction("PostCity", newCity));
        }