public ActionResult DeleteConfirmed(int id)
        {
            GameWeather gameWeather = db.GameWeathers.Find(id);

            db.GameWeathers.Remove(gameWeather);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task GetGameWeatherAsync_TeamKeyIsOk_ForecastFound()
        {
            // Arrange
            Game expectedGame = Game.Schedule
                                .Where(x => x.HomeTeam.Equals(Team.Packers) || x.AwayTeam.Equals(Team.Packers))
                                .Where(x => x.Date.Date > DateTime.UtcNow.AddDays(-1).Date)
                                .FirstOrDefault();

            GameWeather expected = new GameWeather(
                expectedGame,
                new Forecast()
            {
                Minimum = "9,3° C",
                Maximum = "12,5° C",
                Day     = "Showers",
                Night   = "Mostly cloudy"
            }
                );

            var mockForecastService = new Mock <IForecastService>();

            mockForecastService.Setup(x => x.GetForecastAsync(It.IsAny <float>(), It.IsAny <float>(), It.IsAny <DateTime>())).Returns(Task.FromResult <Forecast>(expected.Forecast));
            var mockLogger = new Mock <ILogger <GameWeatherService> >();

            GameWeatherService service = new GameWeatherService(mockForecastService.Object, mockLogger.Object);

            // Act
            GameWeather gameWeather = await service.GetNextGameWeatherAsync(Team.Packers.Key);

            // Assert
            mockForecastService.Verify(m => m.GetForecastAsync(It.IsAny <float>(), It.IsAny <float>(), It.IsAny <DateTime>()), Times.Once);

            // The commented line don't work because LogInformation is a extension method.
            // mockLogger.Verify(m => m.LogInformation(It.IsAny<string>()), Times.Once);
            mockLogger.Verify(
                m => m.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.Is <FormattedLogValues>(v => v.ToString().Contains("Found forecast for the game")),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()
                    )
                );

            Assert.Equal(expected.HomeTeam, gameWeather.HomeTeam);
            Assert.Equal(expected.AwayTeam, gameWeather.AwayTeam);
            Assert.Equal(expected.Stadium, gameWeather.Stadium);
            Assert.Equal(expected.Date, gameWeather.Date);
            Assert.Equal(expected.Forecast.Day, gameWeather.Forecast.Day);
            Assert.Equal(expected.Forecast.Night, gameWeather.Forecast.Night);
            Assert.Equal(expected.Forecast.Maximum, gameWeather.Forecast.Maximum);
            Assert.Equal(expected.Forecast.Minimum, gameWeather.Forecast.Minimum);
            Assert.Equal(expected.City, gameWeather.City);

            // The next line don't work because expected and gameWeather are not the same object (reference) despite having the same properties.
            //Assert.Equal(expected, gameWeather);
        }
 public ActionResult Edit([Bind(Include = "Id,gameId,gameWeek,gameDate,awayTeam,homeTeam,gameTimeET,tvStation,winner,stadium,isDome,geoLat,geoLong,low,high,forecast,windChill,windSpeed,domeImg,smallImg,mediumImg,largeImg")] GameWeather gameWeather)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gameWeather).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gameWeather));
 }
        // GET: GameWeathers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GameWeather gameWeather = db.GameWeathers.Find(id);

            if (gameWeather == null)
            {
                return(HttpNotFound());
            }
            return(View(gameWeather));
        }
        public GameWeather GetTeamWeather(string team)
        {
            GameWeather weather = new GameWeather();

            if (db.GameWeathers.Where(x => x.awayTeam == team).FirstOrDefault() != null)
            {
                weather = db.GameWeathers.Where(x => x.awayTeam == team).FirstOrDefault();
            }
            if (db.GameWeathers.Where(x => x.homeTeam == team).FirstOrDefault() != null)
            {
                weather = db.GameWeathers.Where(x => x.homeTeam == team).FirstOrDefault();
            }
            return(weather);
        }
        public ActionResult Create([Bind(Include = "Id,gameId,gameWeek,gameDate,awayTeam,homeTeam,gameTimeET,tvStation,winner,stadium,isDome,geoLat,geoLong,low,high,forecast,windChill,windSpeed,domeImg,smallImg,mediumImg,largeImg")] GameWeather gameWeather)
        {
            //    if (ModelState.IsValid)
            //    {
            //        db.GameWeathers.Add(gameWeather);
            //        db.SaveChanges();
            //        return RedirectToAction("Index");
            //    }

            //    return View(gameWeather);
            //}

            GameWeather           tempWeather = new GameWeather();
            List <List <string> > weatherList = new List <List <string> >();

            weatherList = NFL_API.GET_NFL.RunAsyncWeather();
            for (int i = 0; i < weatherList.Count; i++)
            {
                tempWeather.gameId     = weatherList[i][0];
                tempWeather.gameWeek   = weatherList[i][1];
                tempWeather.gameDate   = weatherList[i][2];
                tempWeather.awayTeam   = weatherList[i][3];
                tempWeather.homeTeam   = weatherList[i][4];
                tempWeather.gameTimeET = weatherList[i][5];
                tempWeather.tvStation  = weatherList[i][6];
                tempWeather.winner     = weatherList[i][7];
                tempWeather.stadium    = weatherList[i][8];
                tempWeather.isDome     = weatherList[i][9];
                tempWeather.geoLat     = weatherList[i][10];
                tempWeather.geoLong    = weatherList[i][11];
                tempWeather.low        = weatherList[i][12];
                tempWeather.high       = weatherList[i][13];
                tempWeather.forecast   = weatherList[i][14];
                tempWeather.windChill  = weatherList[i][15];
                tempWeather.windSpeed  = weatherList[i][16];
                tempWeather.domeImg    = weatherList[i][17];
                tempWeather.smallImg   = weatherList[i][18];
                tempWeather.mediumImg  = weatherList[i][19];
                tempWeather.largeImg   = weatherList[i][20];

                db.GameWeathers.Add(tempWeather);
                db.SaveChanges();
            }
            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            return(View(gameWeather));
        }
示例#7
0
        public async Task FindForecast_When_TeamKeyIsOkAndGameExist()
        {
            // Arrange
            Game expectedGame = Game.Schedule
                                .Where(x => x.HomeTeam.Equals(Team.Packers) || x.AwayTeam.Equals(Team.Packers))
                                .Where(x => x.Date.Date > DateTime.UtcNow.AddDays(-1).Date)
                                .FirstOrDefault();

            GameWeather expected = new GameWeather(
                expectedGame,
                new Forecast()
            {
                Minimum = "9,3° C",
                Maximum = "12,5° C",
                Day     = "Showers",
                Night   = "Mostly cloudy"
            }
                );

            var mockForecastService = new Mock <IForecastService>();

            mockForecastService.Setup(x => x.GetForecastAsync(It.IsAny <float>(), It.IsAny <float>(), It.IsAny <DateTime>())).Returns(Task.FromResult <Forecast>(expected.Forecast));
            var mockLogger = new Mock <ILogger <GameWeatherService> >();

            GameWeatherService service = new GameWeatherService(mockForecastService.Object, mockLogger.Object);

            // Act
            GameWeather gameWeather = await service.GetNextGameWeatherAsync(Team.Packers.Key);

            // Assert
            mockForecastService.Verify(m => m.GetForecastAsync(It.IsAny <float>(), It.IsAny <float>(), It.IsAny <DateTime>()), Times.Once);

            mockLogger.Verify(
                m => m.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.Is <FormattedLogValues>(v => v.ToString().Contains("Found forecast for the game")),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()
                    )
                );

            gameWeather.Should().BeEquivalentTo(expected);
        }
        public async Task GetGameWeatherAsync_TeamKeyIsOk_ForecastFound()
        {
            // Arrange
            Game expectedGame = Game.Schedule
                                .Where(x => x.HomeTeam.Equals(Team.Packers) || x.AwayTeam.Equals(Team.Packers))
                                .Where(x => x.Date.Date > DateTime.UtcNow.AddDays(-1).Date)
                                .FirstOrDefault();

            GameWeather expected = new GameWeather(
                expectedGame,
                new Forecast()
            {
                Minimum = "9,3° C",
                Maximum = "12,5° C",
                Day     = "Showers",
                Night   = "Mostly cloudy"
            }
                );

            var mockForecastService = new MockForecastService(expected.Forecast);
            var mockLogger          = new MockLogger();

            GameWeatherService service = new GameWeatherService(mockForecastService, mockLogger);

            // Act
            GameWeather gameWeather = await service.GetNextGameWeatherAsync(Team.Packers.Key);

            // Assert
            Assert.Equal(expected.HomeTeam, gameWeather.HomeTeam);
            Assert.Equal(expected.AwayTeam, gameWeather.AwayTeam);
            Assert.Equal(expected.Stadium, gameWeather.Stadium);
            Assert.Equal(expected.Date, gameWeather.Date);
            Assert.Equal(expected.Forecast.Day, gameWeather.Forecast.Day);
            Assert.Equal(expected.Forecast.Night, gameWeather.Forecast.Night);
            Assert.Equal(expected.Forecast.Maximum, gameWeather.Forecast.Maximum);
            Assert.Equal(expected.Forecast.Minimum, gameWeather.Forecast.Minimum);
            Assert.Equal(expected.City, gameWeather.City);

            //Assert.Equal(expected, gameWeather);
        }
示例#9
0
        public async Task GetGameWeatherAsync_TeamKeyIsOk_ForecastFound()
        {
            // Arrange
            Game expectedGame = Game.Schedule
                                .Where(x => x.HomeTeam.Equals(Team.Texans) || x.AwayTeam.Equals(Team.Texans))
                                .Where(x => x.Date.Date > DateTime.UtcNow.AddDays(-1).Date)
                                .FirstOrDefault();

            GameWeather expected = new GameWeather(
                expectedGame,
                new Forecast()
            {
                Minimum = "5,1° C",
                Maximum = "22,6° C",
                Day     = "Mostly cloudy",
                Night   = "Partly cloudy"
            }
                );

            FirstVersionService service = new FirstVersionService();

            // Act
            GameWeather gameWeather = await service.GetNextGameWeatherAsync(Team.Texans.Key);

            // Assert
            Assert.Equal(expected.HomeTeam, gameWeather.HomeTeam);
            Assert.Equal(expected.AwayTeam, gameWeather.AwayTeam);
            Assert.Equal(expected.Stadium, gameWeather.Stadium);
            Assert.Equal(expected.Date, gameWeather.Date);
            Assert.Equal(expected.Forecast.Day, gameWeather.Forecast.Day);
            Assert.Equal(expected.Forecast.Night, gameWeather.Forecast.Night);
            Assert.Equal(expected.Forecast.Maximum, gameWeather.Forecast.Maximum);
            Assert.Equal(expected.Forecast.Minimum, gameWeather.Forecast.Minimum);
            Assert.Equal(expected.City, gameWeather.City);

            //Assert.Equal(expected, gameWeather);
        }