private String RespondToStandings(IBaseballSensor sensor, BaseballTeam team) { BaseballStandings standings = sensor.LoadStandings(); BaseballTeamStanding divisionStandings, wildcardStandings = null; BaseballStandingsWithWildcard fullStandings = standings as BaseballStandingsWithWildcard; bool gotStandingsSuccessful = false; if (fullStandings != null) { gotStandingsSuccessful = fullStandings.TryGetStandingsForTeam(team, out divisionStandings, out wildcardStandings); } else { gotStandingsSuccessful = standings.TryGetStandingsForTeam(team, out divisionStandings); } if (!gotStandingsSuccessful) { return(String.Format("I couldn't find any information about the {0} this year.", team.Name)); } else if (divisionStandings.GamesBack == 0) { return(String.Format("The {0} lead the {1}.", team.Name, team.Division)); } else if (wildcardStandings == null) { return(String.Format("The {0} are {1} games behind the leaders in the {2}.", team.Name, divisionStandings.GamesBack * -1, team.Division)); } else if (wildcardStandings.GamesBack > 0) { return(String.Format("The {0} are {1} games behind the leaders in the {2}, and lead the wildcard standings by {3} games.", team.Name, divisionStandings.GamesBack * -1, team.Division, wildcardStandings.GamesBack)); } else if (wildcardStandings.GamesBack == 0) { return(String.Format("The {0} are {1} games behind the leaders in the {2}, and just barely have a wildcard spot.", team.Name, divisionStandings.GamesBack * -1, team.Division)); } else { return(String.Format("The {0} are {1} games behind the leaders in the {2}, and are {3} games behind in the wildcard standings.", team.Name, divisionStandings.GamesBack * -1, team.Division, wildcardStandings.GamesBack * -1)); } }
private void StandingsTest(String teamName, int gamesBackDivisional, int?gamesBackWildcard, String expectedResponse) { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "Standings" }, { "Time", "DayOfWeek=today;" }, { "Team", teamName }, }; Mock <IBaseballSensor> sensor = new Mock <IBaseballSensor>(MockBehavior.Strict); sensor.Setup(s => s.IsValid).Returns(true); sensor.Setup(s => s.Teams).Returns(_mockTeams); sensor.Setup(s => s.League).Returns("MLB"); BaseballTeamStanding teamStandings = new BaseballTeamStanding(); teamStandings.Team = _mockTeams[0]; teamStandings.GamesBack = gamesBackDivisional; BaseballStandings standings; if (gamesBackWildcard.HasValue) { standings = new BaseballStandingsWithWildcard(); BaseballTeamStanding teamStandingsWildcard = new BaseballTeamStanding(); teamStandingsWildcard.Team = _mockTeams[0]; teamStandingsWildcard.GamesBack = gamesBackWildcard.Value; (standings as BaseballStandingsWithWildcard).AddStandingsForTeam(teamStandings, teamStandingsWildcard); } else { standings = new BaseballStandings(); standings.AddStandingsForTeam(teamStandings); } sensor.Setup(s => s.LoadStandings()).Returns(standings); AddComponentToConfigurationManager(sensor.Object); CurrentConversation = new BaseballConversation(GetConfigurationManager(), new List <IOInterfaceReference>()); Assert.AreEqual(expectedResponse, RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadStandings(), Times.Exactly(1)); }