Example #1
0
        private ForecastRepository GetForecastRepositoryWithForecastsInContext()
        {
            var data = new List <Forecast>
            {
                new Forecast {
                    Latitude = 39.801f, Longitude = -87.901f, Date = DateTime.Now, MaximumTemperature = 50.0f
                },
                new Forecast {
                    Latitude = 37.801f, Longitude = -87.901f, Date = DateTime.Now, MaximumTemperature = 50.0f
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Forecast> >();

            mockSet.As <IDbAsyncEnumerable <Forecast> >()
            .Setup(m => m.GetAsyncEnumerator())
            .Returns(new TestDbAsyncEnumerator <Forecast>(data.GetEnumerator()));

            mockSet.As <IQueryable <Forecast> >()
            .Setup(m => m.Provider)
            .Returns(new TestDbAsyncQueryProvider <Forecast>(data.Provider));

            mockSet.As <IQueryable <Forecast> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Forecast> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Forecast> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var forecastContext = new Mock <ForecastContext>();

            forecastContext.Setup(c => c.Forecasts).Returns(mockSet.Object);

            var forecastService    = new Mock <IForecastService>();
            var forecastRepository = new ForecastRepository(forecastContext.Object, forecastService.Object);

            return(forecastRepository);
        }
            public void GetDateCountByForecastType_CanExtract()
            {
                // Arrange
                var user             = new GenericRepository <User>(Session).SaveOrUpdate(DataGenerator.GetUser());
                var client           = new GenericRepository <Company>(Session).SaveOrUpdate(DataGenerator.GetCustomer(user));
                var project          = new GenericRepository <Project>(Session).SaveOrUpdate(DataGenerator.GetProject(user, client));
                var forecastType     = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Client", "", true, false));
                var forecastTypeRepo = new ForecastTypeRepository(Session);

                forecastTypeRepo.SaveOrUpdate(forecastType);
                var clientForecastTypeId = forecastType.Id;

                var month = new ForecastMonth(1, 2013, 3, user, user);
                var repo  = new ForecastRepository(Session);

                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 1), forecastType, project, 3);
                forecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Vacation", "", false, false));
                forecastTypeRepo.SaveOrUpdate(forecastType);
                var vacationForecastTypeId = forecastType.Id;

                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 2), forecastType, null, 0);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 3), forecastType, null, 0);

                var monthRepo = new ForecastMonthRepository(Session);

                monthRepo.SaveOrUpdate(month);

                // Act
                var clientForecastCount   = repo.GetForecastCountByForecastType(1, clientForecastTypeId, DateSpan.YearDateSpan(2013));
                var vacationForecastcount = repo.GetForecastCountByForecastType(1, vacationForecastTypeId, DateSpan.YearDateSpan(2013));

                // Assert
                Assert.That(clientForecastCount, Is.EqualTo(1));
                Assert.That(vacationForecastcount, Is.EqualTo(2));
            }
Example #3
0
        public IHttpActionResult SearchWeatherReport([FromBody] ForecastSearchRequest request)
        {
            try {
                // fetch the forecast
                var      openWeatherApi = new OpenWeatherMapAPI(_apiKey);
                Forecast forecast       = openWeatherApi.QueryForecast($"{request.CityName}"); //,{request.CountryCode}

                // store the results
                var      forecastRepo = new ForecastRepository(_mongoDbPath);
                ObjectId?forecastId   = forecastRepo.StoreForecast(forecast);

                // return the query result
                if (forecastId.HasValue)
                {
                    return(Ok(forecastId.Value));
                }
                else
                {
                    return(BadRequest("Could not store results of query"));
                }
            }
            catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
Example #4
0
        public IController MakeForecastController()
        {
            IForecastRepository   repository           = new ForecastRepository();
            IFetchCurrentForecast fetchCurrentForecast = new FetchCurrentForecastService(repository);

            return(new Forecast.Presentation.Controllers.FactoryForecastController(fetchCurrentForecast));
        }
Example #5
0
        public void AmennyibenEgyForecastRepositoryFelparameterezveEsAdatokkal(string apiKey)
        {
            logger.Information("Create API request service");
            var service = new RequestService(new Options <ServiceOptions>(new ServiceOptions(apiKey)), logger);

            logger.Information("Create forecast repository");
            repository = new ForecastRepository(service, mapper);
        }
Example #6
0
        public IHttpActionResult GetWeatherForecastList()
        {
            try {
                var             forecastRepo = new ForecastRepository(_mongoDbPath);
                List <Forecast> summaries    = forecastRepo.GetForecasts().ToList();

                return(Ok(summaries));
            }
            catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
        private ViewModelLocator(string mashapeKey, IStorageService storageService)
        {
            _storageService = storageService;

            _document            = new Document();
            _citySelection       = new CitySelection();
            _weatherServiceAgent = new FakeWeatherServiceAgent(_document);
            _forecastRepository  = new ForecastRepository(
                _storageService,
                _weatherServiceAgent,
                _document);
        }
Example #8
0
        public BaseForecastRepositoryTests()
        {
            FactoryMock = new Mock <IHttpClientFactory>();
            fac         = new FileStorageFactory("data");

            config = new WeatherRepositoryConfig
            {
                BaseNWSURL = "https://api.weather.gov",
                UserAgent  = "SomeAgentDescriptor"
            };

            repository = new ForecastRepository(FactoryMock.Object, config);
        }
Example #9
0
        public MainViewModel(ForecastRepository forecastRepository, IMapper mapper, ILogger logger) : this()
        {
            this.forecastRepository = forecastRepository ?? throw new ArgumentNullException(nameof(forecastRepository));
            this.mapper             = mapper ?? throw new ArgumentNullException(nameof(mapper));
            this.logger             = logger ?? throw new ArgumentNullException(nameof(logger));

            //Ezek csak az éles felhasználáshoz kellenek, ezért a default konstruktorba nem kellenek
            //todo: ezt elmenteni beállíthatónak
            SelectedCity = SelectableCity.Single(x => x.Coordinates == "47.49801,19.03991");
            var code = Settings.Default.Culture.LanguageNameToCode();

            SelectedLanguage = SelectableLanguage.Single(x => x.Code == code);
        }
            public void GetRestOfYear_CanExtract()
            {
                // Arrange
                var user = new GenericRepository <User>(Session).SaveOrUpdate(DataGenerator.GetUser());

                var client = DataGenerator.GetCustomer(user);

                client.Internal = true;
                client          = new GenericRepository <Company>(Session).SaveOrUpdate(client);

                var project             = new GenericRepository <Project>(Session).SaveOrUpdate(DataGenerator.GetProject(user, client));
                var forecastType        = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Client", "", true, true));
                var illnessForecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Illness", "", false, true)
                {
                    StatisticsInclusion = false
                });
                var forecastTypeRepo = new ForecastTypeRepository(Session);

                forecastTypeRepo.SaveOrUpdate(forecastType);

                var repo  = new ForecastRepository(Session);
                var month = new ForecastMonth(1, 2013, 3, user, user);

                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 1), forecastType, project, 7.5m, 1);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 2), forecastType, project, 6, 1);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 3), forecastType, project, 5, 1);
                CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 4), illnessForecastType, null, 0, 7.5m);

                var monthRepo = new ForecastMonthRepository(Session);

                monthRepo.SaveOrUpdate(month);

                // Act
                var all           = repo.GetHourSumByCriteria(1, true, DateSpan.YearDateSpan(2013));
                var allExcluded   = repo.GetHourSumByCriteria(1, false, DateSpan.YearDateSpan(2013));
                var twoByDateSpan = repo.GetHourSumByCriteria(1, true, new DateSpan {
                    From = new DateTime(2013, 1, 1), To = new DateTime(2013, 1, 2)
                });

                // Assert
                Assert.That(all, Is.EqualTo(21.5m)); // 7.5 + 6 + 5 + 1 + 1 + 1 (projecthours and dedicated hours (1's))
                Assert.That(allExcluded, Is.EqualTo(0));
                Assert.That(twoByDateSpan, Is.EqualTo(15.5m));
            }
Example #11
0
        public IHttpActionResult GetWeatherForecast(string forecastId)
        {
            try {
                var      forecastRepo = new ForecastRepository(_mongoDbPath);
                Forecast forecast     = forecastRepo.GetForecast(forecastId);

                if (forecast is null)
                {
                    return(BadRequest($"could not locate forecast data with id: {forecastId}"));
                }
                else
                {
                    return(Ok(forecast));
                }
            }
            catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
Example #12
0
 public OpenWeatherService(ForecastRepository repository, OpenWeatherWebService webservice)
 {
     _repository = repository;
     _webservice = webservice;
 }
Example #13
0
 public ForecastRepositoryTest(ForecastDbContextFixture forecastDbContextFixture)
 {
     _context = forecastDbContextFixture.ForecastDbContext;
     _target  = new ForecastRepository(_context);
 }
Example #14
0
 public CityViewModel(City city, ForecastRepository forecastRepository)
 {
     _city = city;
     _forecastRepository = forecastRepository;
 }
Example #15
0
 public ForecastController()
 {
     this.computerRepository = new ForecastRepository();
 }
Example #16
0
 public ClothingItemController(ClothingItemFactory clothingItemFactory, ForecastRepository forecastRepository)
 {
     _clothingItemFactory = clothingItemFactory;
     _forecastRepository  = forecastRepository;
 }