private void FreeMLBTVTest(GameState?gameState, String expectedResponse) { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "MLBTVFreeGame" }, { "Time", "DayOfWeek=today;" }, { "Team", "" }, }; 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"); if (gameState.HasValue) { BaseballGame game = CreateBaseballGame(gameState.Value, 5, 2, true, new List <String> { "MLB.tv" }); sensor.Setup(s => s.LoadAllScores(It.IsAny <DateTime>())).Returns(new List <BaseballGame> { game }); } else { sensor.Setup(s => s.LoadAllScores(It.IsAny <DateTime>())).Returns(new List <BaseballGame>()); } AddComponentToConfigurationManager(sensor.Object); CurrentConversation = new BaseballConversation(GetConfigurationManager(), new List <IOInterfaceReference>()); Assert.AreEqual(expectedResponse, RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadAllScores(It.IsAny <DateTime>()), Times.Exactly(1)); }
public void ScoresDoubleHeader() { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "Score" }, { "Time", "DayOfWeek=today;" }, { "Team", "mockteam" }, }; 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"); BaseballGame game1 = CreateBaseballGame(GameState.Completed, 1, 3, true, new List <string>()); BaseballGame game2 = CreateBaseballGame(GameState.Started, 4, 3, true, new List <string>()); game2.InningNumber = 5; game2.TopOfInning = true; game2.NumberOnBase = 3; game2.NumberOfOuts = 2; sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame> { game1, game2 }); AddComponentToConfigurationManager(sensor.Object); CurrentConversation = new BaseballConversation(GetConfigurationManager(), new List <IOInterfaceReference>()); Assert.AreEqual("In the first game, The Mockers lost to the Fakers by a score of 3 to 1.. In the second game, The Mockers are beating the Fakers 4 to 3. with 3 on and 2 outs in the top of the fifth..", RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0]), Times.Exactly(1)); }
public void WhichChannelOneGameFinishedOneInProgress() { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "TVChannel" }, { "Time", "DayOfWeek=today;" }, { "Team", "mockteam" }, }; 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"); BaseballGame completedGame = CreateBaseballGame(GameState.Completed, 5, 2, true, new List <String> { "ESPN" }); BaseballGame inProgressGame = CreateBaseballGame(GameState.Started, 5, 2, true, new List <String> { "ESPN" }); sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame> { completedGame, inProgressGame }); AddComponentToConfigurationManager(sensor.Object); CurrentConversation = new BaseballConversation(GetConfigurationManager(), new List <IOInterfaceReference>()); Assert.AreEqual("The Mockers game is available on ESPN.", RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0]), Times.Exactly(1)); }
private void TurnToChannelTest(GameState?gameState, bool isOnTV, bool includesRemotes, String expectedResponse) { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "TurnToGame" }, { "Time", "DayOfWeek=today;" }, { "Team", "mockteam" }, }; 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"); if (gameState.HasValue) { List <String> channels = new List <string>(); if (isOnTV) { channels.Add("ESPN"); } BaseballGame game = CreateBaseballGame(gameState.Value, 5, 2, true, channels); sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame> { game }); } else { sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame>()); } AddComponentToConfigurationManager(sensor.Object); List <IOInterfaceReference> references = new List <IOInterfaceReference>(); Mock <ITVRemote> remote = new Mock <ITVRemote>(MockBehavior.Strict); Semaphore channelTurn = new Semaphore(0, 1); if (includesRemotes) { remote.Setup(s => s.Name).Returns("Mock Name"); remote.Setup(s => s.GetChannels()).Returns(new List <String> { "ESPN" }); remote.Setup(s => s.SendChannel("ESPN")).Callback(() => channelTurn.Release()); AddComponentToConfigurationManager(remote.Object); IOInterfaceReference remoteRef = new IOInterfaceReference(); remoteRef.Properties.Single(s => s.Name.Equals("References")).Setter("Mock Name"); references.Add(remoteRef); } CurrentConversation = new BaseballConversation(GetConfigurationManager(), references); Assert.AreEqual(expectedResponse, RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0]), Times.Exactly(1)); if (includesRemotes) { channelTurn.WaitOne(); remote.Verify(s => s.SendChannel("ESPN"), Times.Exactly(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)); }
private void WhatChannelTest(GameState?gameState, bool isOnTV, String expectedResponse) { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "TVChannel" }, { "Time", "DayOfWeek=today;" }, { "Team", "mockteam" }, }; 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"); if (gameState.HasValue) { List <String> channels = new List <string>(); if (isOnTV) { channels.Add("ESPN"); } BaseballGame game = CreateBaseballGame(gameState.Value, 5, 2, true, channels); sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame> { game }); } else { sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame>()); } AddComponentToConfigurationManager(sensor.Object); CurrentConversation = new BaseballConversation(GetConfigurationManager(), new List <IOInterfaceReference>()); Assert.AreEqual(expectedResponse, RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0]), Times.Exactly(1)); }
private void SingleScoreTest(GameState?gameState, int mockScore, int fakeScore, bool isMockHome, bool isTopOfInning, String expectedResponse) { Dictionary <String, String> expectedParams = new Dictionary <string, string> { { "Command", "baseball" }, { "Parameter", "Score" }, { "Time", "DayOfWeek=today;" }, { "Team", "mockteam" }, }; 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"); if (gameState.HasValue) { BaseballGame game = CreateBaseballGame(gameState.Value, mockScore, fakeScore, isMockHome, new List <string>()); game.InningNumber = 5; game.TopOfInning = isTopOfInning; game.NumberOnBase = 3; game.NumberOfOuts = 2; sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame> { game }); } else { sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame>()); } AddComponentToConfigurationManager(sensor.Object); CurrentConversation = new BaseballConversation(GetConfigurationManager(), new List <IOInterfaceReference>()); Assert.AreEqual(expectedResponse, RunSingleConversation <BaseballConversation>(expectedParams)); sensor.Verify(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0]), Times.Exactly(1)); }