Esempio n. 1
0
        public WeatherForecastUOW(IRepositoryProvider repositoryProvider, ForecastDbContext dBContext)
        {
            this.DbContext = dBContext;

            repositoryProvider.DbContext = this.DbContext;
            this.RepositoryProvider      = repositoryProvider;
        }
Esempio n. 2
0
        static void GenerateData()
        {
            using (var dbContext = new ForecastDbContext())
            {
                dbContext.Database.EnsureCreated();

                if (!dbContext.ForecastDays.Any())
                {
                    Entities.SolarSystems.MeLi.MeLiSolarSystem meliSolarSystem = new Entities.SolarSystems.MeLi.MeLiSolarSystem();
                    for (int i = 0; i < (365 * 10); i++)
                    {
                        ForecastDay forecastDay = new ForecastDay();
                        forecastDay.Day                     = i;
                        forecastDay.FerengiPosition         = meliSolarSystem.FerengiPlanet.GetPosition(i).ToString();
                        forecastDay.FerengiAngle            = meliSolarSystem.FerengiPlanet.GetAngle(i);
                        forecastDay.BetasoidePosition       = meliSolarSystem.BetasoidePlanet.GetPosition(i).ToString();
                        forecastDay.BetasoideAngle          = meliSolarSystem.BetasoidePlanet.GetAngle(i);
                        forecastDay.VulcanoPosition         = meliSolarSystem.VulcanoPlanet.GetPosition(i).ToString();
                        forecastDay.VulcanoAngle            = meliSolarSystem.VulcanoPlanet.GetAngle(i);
                        forecastDay.AreAlignedWithTheSun    = meliSolarSystem.AreAlignedWithTheSun((uint)i);
                        forecastDay.AreAlignedWithoutTheSun = meliSolarSystem.AreAlignedWithoutTheSun((uint)i);
                        forecastDay.IsSunInside             = meliSolarSystem.IsSunInside((uint)i);
                        forecastDay.Weather                 = meliSolarSystem.GetWeather((uint)i);
                        forecastDay.TrianglePerimeter       = meliSolarSystem.GetTrianglePerimeter((uint)i);
                        dbContext.ForecastDays.Add(forecastDay);
                    }
                    dbContext.SaveChanges();
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            GenerateData();

            using (var dbContext = new ForecastDbContext())
            {
                dbContext.Database.EnsureCreated();

                var drougthDays = dbContext.ForecastDays.Where(f => f.Weather == "drought").ToList();
                var optimumDays = dbContext.ForecastDays.Where(f => f.Weather == "optimum pressure and temperature").ToList();
                var rainyDays   = dbContext.ForecastDays.OrderBy(f => f.Day).Where(f => f.Weather == "rainy" || f.Weather == "lot of rain").ToList();
                var rainiestDay = dbContext.ForecastDays.OrderByDescending(f => f.TrianglePerimeter).First();

                //Get rainy periods
                int rainyPeriods = 0;
                for (int i = 0; i < rainyDays.Count; i++)
                {
                    if (i + 1 < rainyDays.Count)
                    {
                        if (rainyDays.ElementAt(i + 1).Day == (rainyDays.ElementAt(i).Day + 1))
                        {
                            rainyPeriods++;
                        }
                    }
                }

                Console.WriteLine($"Drought periods: {drougthDays.Count}");
                Console.WriteLine($"Optimum pressure and temperature periods: {optimumDays.Count}");
                Console.WriteLine($"Rainy periods: {rainyPeriods}");
                Console.WriteLine($"Rainiest day: {rainiestDay.Day}");
                Console.ReadKey(true);
            }
        }
Esempio n. 4
0
        public ForecastDay Get(uint day)
        {
            ForecastDay result;

            using (var dbContext = new ForecastDbContext())
            {
                dbContext.Database.EnsureCreated();

                result = dbContext.ForecastDays.FirstOrDefault(f => f.Day == day);
                if (result == null)
                {
                    result = new ForecastDay();
                }
            }

            return(result);
        }
Esempio n. 5
0
        public ForecastDbContextFixture()
        {
            ForecastDbContext = new ForecastDbContext(new DbContextOptionsBuilder <ForecastDbContext>()
                                                      .UseInMemoryDatabase("unit testing")
                                                      .Options);

            // create data for test
            ForecastDbContext.Database.EnsureCreated();
            ForecastDbContext.WeathreForecasts.AddRange(
                new WeatherForecast {
                Id = 1, Date = DateTimeOffset.ParseExact("2020/04/01", "yyyy/MM/dd", null), Summary = "s1", TemperatureC = 0
            },
                new WeatherForecast {
                Id = 2, Date = DateTimeOffset.ParseExact("2020/04/02", "yyyy/MM/dd", null), Summary = "s2", TemperatureC = 10
            },
                new WeatherForecast {
                Id = 3, Date = DateTimeOffset.ParseExact("2020/04/03", "yyyy/MM/dd", null), Summary = "s3", TemperatureC = 20
            }
                );
            ForecastDbContext.SaveChanges();
        }
 public TemperatureService(ForecastDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Esempio n. 7
0
 public ForecastRepository(ForecastDbContext forecastDbContext)
 {
     _forecastDbContext = forecastDbContext ?? throw new ArgumentNullException(nameof(forecastDbContext));
 }
 public WeekService(ForecastDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Esempio n. 9
0
 public ForecastRepositoryTest(ForecastDbContextFixture forecastDbContextFixture)
 {
     _context = forecastDbContextFixture.ForecastDbContext;
     _target  = new ForecastRepository(_context);
 }