public void WhisperNextAvailableCommands_WhenClosed_GivenUserIsBroadcasterOrModerator() { var sut = new GuessGame(GuessGameState.GuessesClosed); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); chatserviceMock.Setup(x => x.WhisperMessage(It.IsAny <string>(), It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { //"", }, ChatUser = new ChatUser() { DisplayName = "User1", Username = "******", IsBroadcaster = true } }; sut.Help(chatserviceMock.Object, cmd); chatserviceMock.Verify(service => service.BroadcastMessageOnChannel(It.IsAny <string>()), Times.Never); chatserviceMock.Verify(service => service.WhisperMessage(It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void NotBeAllowedForRegularChatters() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "close", }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User1", Username = "******" } }; Assert.Throws <InvalidOperationException>(() => sut.Close(chatserviceMock.Object, cmd)); //verify everything happened as needed chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(m => m == "Now taking guesses. Submit your guess with !guess 1:23 where 1 is minutes and 23 is seconds.")), Times.Never); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); }
public void BeAllowedForBroadcastersAndModerators() { var sut = new GuessGame(GuessGameState.NotStarted); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "open", }, ChatUser = new ChatUser() { IsBroadcaster = true, IsModerator = false, DisplayName = "User1", Username = "******" } }; sut.Open(chatserviceMock.Object, cmd); //verify everything happened as needed chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(m => m == "Now taking guesses. Submit your guess with !guess 1:23 where 1 is minutes and 23 is seconds.")), Times.Once); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); }
public void WhisperTheGameIsTakingGuesses_WhenTakingGuesses_GivenUserIsBroadcaster() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.WhisperMessage(It.IsAny <string>(), It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { //"", }, ChatUser = new ChatUser() { DisplayName = "User1", Username = "******", IsBroadcaster = true } }; sut.Help(chatserviceMock.Object, cmd); chatserviceMock.Verify(service => service.WhisperMessage( It.Is <string>(m => m == "user1"), It.Is <string>(m => m == "The time-guessing game is currently taking guesses. Guess a time with !guess 1:23, Your last guess will stand, and you can check your guess with !guess mine, OR close the guesses with !guess close")), Times.Once); }
public void AddTheValidGuessOfAUser() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "1:23", }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User1", Username = "******" } }; sut.Guess(chatserviceMock.Object, cmd); chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.IsAny <string>()), Times.Never); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); Assert.Equal(1, sut.GuessCount()); }
public void NumberToChoiceTest() { GuessGame game = new GuessGame(); Assert.IsTrue(game.numberToChoice >= 0); Assert.IsTrue(game.numberToChoice <= 100); }
public void BroadcastMinAndMaxGuesses() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "1:23", }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User1", Username = "******" } }; sut.Guess(chatserviceMock.Object, cmd); cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "1:59", }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User2", Username = "******" } }; sut.Guess(chatserviceMock.Object, cmd); cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "close", }, ChatUser = new ChatUser() { IsBroadcaster = true, IsModerator = false, DisplayName = "User1", Username = "******" } }; sut.Close(chatserviceMock.Object, cmd); //verify everything happened as needed chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(m => m == "No more guesses... the race is about to start with 2 guesses from 00:01:23 to 00:01:59")), Times.Once); Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState()); }
public void BroadcastInvalidGuess(string guess) { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { guess, }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User1", Username = "******" } }; sut.Guess(chatserviceMock.Object, cmd); chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(s => s == "Sorry user1, guesses are only accepted in the format !guess 1:23")), Times.Once); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); Assert.Equal(0, sut.GuessCount()); }
public void T1_1() { GuessGame g = new GuessGame(); g.init(3); g.init_test(5); string r1 = g.guess(3); Assert.AreEqual(GuessGame.Gr_less, r1); string r2 = g.guess(8); Assert.AreEqual(GuessGame.Gr_more, r2); string r3 = g.guess(10); Assert.AreEqual(GuessGame.Gr_lose, r3); g.init(3); g.init_test(5); string r4 = g.guess(5); Assert.AreEqual(GuessGame.Gr_equal, r4); }
public void SetTheGameToNotStartedState_GivenUserIsBroadcaster() { var sut = new GuessGame(GuessGameState.GuessesClosed); Mock <IChatService> chatService = new Mock <IChatService>(); chatService.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "reset", "1:23" }, ChatUser = new ChatUser() { DisplayName = "User1", Username = "******", IsBroadcaster = true } }; sut.Reset(chatService.Object, cmd); Assert.Equal(GuessGameState.NotStarted, sut.CurrentState()); Assert.Equal(0, sut.GuessCount()); //chatService.Verify(service => service.BroadcastMessageOnChannel(It.Is<string>(s => s == "user1 has not guessed yet!")), Times.Once()); }
[HttpGet]//default public ActionResult GuessingGame() { int randomNumber = random.Next(1, 101); this.Session["Answer"] = randomNumber; if (Session["History"] == null) { Session["History"] = new List <GuessingGameHistory>(); } List <GuessingGameHistory> history = (List <GuessingGameHistory>)Session["History"]; if (history.Count > 0) { history[history.Count - 1].Display = true; } history.Add(new GuessingGameHistory { Number = randomNumber, Display = false }); Session["History"] = history; this.Session["GuessList"] = new List <int>(); GuessGame guess = new GuessGame { Answer = (int)this.Session["Answer"], }; return(View(guess)); }
public void VerifyNumberTest() { GuessGame game = new GuessGame(); Assert.AreEqual(game.VerifyNumber(game.numberToChoice - 1), -1); Assert.AreEqual(game.VerifyNumber(game.numberToChoice + 1), 1); Assert.AreEqual(game.VerifyNumber(game.numberToChoice), 0); }
public void StartInState_WhenStatePassedToConstructor() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); sut = new GuessGame(GuessGameState.GuessesClosed); Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState()); }
static void DisplayResult(GuessGame g) { if (g.Result) { Console.WriteLine("\n-------------Result---------------"); Console.WriteLine("\nCongratulation! you win this game"); Console.WriteLine("Guess was " + g.GuessNumber); Console.WriteLine("Your Guess was " + g.GuessingNumber); Console.WriteLine("Total turns in your game is " + g.Turn); } }
public static GuessGameModel CreateGuessGameModel(GuessGame g) { GuessGameModel model = new GuessGameModel(); model.Id = g.Id; model.Name = g.Name; model.PasswordHash = g.PasswordHash; model.TournamentId = g.TournamentId; return(model); }
public ActionResult GuessingGame(GuessGame guess) { (this.Session["GuessList"] as List <int>).Add(guess.Num); ViewBag.guessList = (this.Session["GuessList"] as List <int>); guess.Answer = (int)this.Session["Answer"]; guess.Compare(); List <GuessingGameHistory> history = (List <GuessingGameHistory>)Session["History"]; history[history.Count - 1].Tried += 1; return(View(guess)); }
public async void BeforeAnyTestStarted() { // Perform setup here? GameDataService dataService = new GameDataService(); // Workaround for http async testing... var data = Task.Run(() => dataService.GetGameData()).Result; // Setup Guessing Game with data sut = new GuessGame(data); }
public static void AddUserToGuessGame(string userId, int guessGameId) { using (var db = new EC2016CodeFirst()) { ApplicationUser user = db.Users.Where(u => u.Id == userId).First(); GuessGame game = db.GuessGames.Where(g => g.Id == guessGameId).First(); user.GuessGames.Add(game); db.SaveChanges(); } }
static void Main(string[] args) { //Case 1 :- No use of Object oriented features,functional approach GuessGame guessGame = new GuessGame(); guessGame.SetNumberOfGuessByUser(0); guessGame.SetNumberToBeGuessed(); bool start = true; PlayTheGame(ref start, guessGame.GetNumberToBeGuessed(), guessGame.GetNumberOfGuessByUser(), ref guessGame); Console.ReadLine(); }
public void NotAllowMineCommand() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); sut.Mine(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>(), ChatUser = new ChatUser() { DisplayName = "a", Username = "******" } }); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); }
public void NotAllowCloseCommandFromChatter() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Assert.Throws <InvalidOperationException>(() => sut.Close(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>(), ChatUser = new ChatUser() { DisplayName = "a", Username = "******" } })); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); }
public void AllowCloseCommandFromModerator() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); sut.Close(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>(), ChatUser = new ChatUser() { DisplayName = "a", Username = "******", IsModerator = true } }); Assert.Equal(GuessGameState.GuessesClosed, sut.CurrentState()); }
public void NotAllowGuessCommand() { var sut = new GuessGame(); sut.Guess(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>(), ChatUser = new ChatUser() { DisplayName = "a", Username = "******" } }); Assert.Equal(GuessGameState.NotStarted, sut.CurrentState()); }
public void AllowOpenCommandFromBroadcaster() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Assert.Throws <InvalidOperationException>(() => sut.Open(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>() { }, ChatUser = new ChatUser() { IsBroadcaster = true, DisplayName = "a", Username = "******" } })); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); }
public void AllowOpenCommandFromBroadcaster() { var sut = new GuessGame(GuessGameState.GuessesClosed); sut.Open(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>() { }, ChatUser = new ChatUser() { IsBroadcaster = true, DisplayName = "a", Username = "******" } }); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); }
//public static int AddUser(string name, byte[] password) //{ // using (var db = new EC2016CodeFirst()) // { // User u = new User(); // u.Name = name; // u.PasswordHash = password; // db.Users1.Add(u); // db.SaveChanges(); // return u.Id; // } //} public static int AddGuessGame(string name, byte[] password, int tournamentId) { using (var db = new EC2016CodeFirst()) { GuessGame g = new GuessGame(); g.Name = name; g.PasswordHash = password; g.TournamentId = tournamentId; db.GuessGames.Add(g); db.SaveChanges(); return(g.Id); } }
public void AllowResetCommandFromModerator() { var sut = new GuessGame(GuessGameState.GuessesClosed); sut.Reset(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>() { "reset", "0:00" }, ChatUser = new ChatUser() { DisplayName = "a", Username = "******", IsModerator = true } }); Assert.Equal(GuessGameState.NotStarted, sut.CurrentState()); }
public void NotAllowResetCommand() { var sut = new GuessGame(); Assert.Throws <InvalidOperationException>(() => sut.Reset(new StubChat(_output), new GuessGameCommand() { ArgumentsAsList = new List <string>() { "reset", "0:00" }, ChatUser = new ChatUser() { DisplayName = "a", Username = "******" } })); Assert.Equal(GuessGameState.NotStarted, sut.CurrentState()); }
public void BroadcastWhenAlreadyGuessedByOtherUser() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatserviceMock = new Mock <IChatService>(); chatserviceMock.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "1:23", }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User1", Username = "******" } }; sut.Guess(chatserviceMock.Object, cmd); cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "1:23", }, ChatUser = new ChatUser() { IsBroadcaster = false, IsModerator = false, DisplayName = "User2", Username = "******" } }; sut.Guess(chatserviceMock.Object, cmd); chatserviceMock.Verify(x => x.BroadcastMessageOnChannel(It.Is <string>(s => s == "Sorry user2, user1 already guessed 00:01:23")), Times.Once); Assert.Equal(GuessGameState.OpenTakingGuesses, sut.CurrentState()); Assert.Equal(1, sut.GuessCount()); }
public void AnnounceAClosestWinner_GivenUserIsBroadcaster() { var sut = new GuessGame(GuessGameState.OpenTakingGuesses); Mock <IChatService> chatService = new Mock <IChatService>(); chatService.Setup(x => x.BroadcastMessageOnChannel(It.IsAny <string>())); var cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "1:24", }, ChatUser = new ChatUser() { DisplayName = "User1", Username = "******", IsBroadcaster = true } }; sut.Guess(chatService.Object, cmd); sut.Close(chatService.Object, cmd); cmd = new GuessGameCommand() { ArgumentsAsList = new List <string>() { "reset", "1:23", }, ChatUser = new ChatUser() { DisplayName = "User1", Username = "******", IsBroadcaster = true } }; sut.Reset(chatService.Object, cmd); Assert.Equal(GuessGameState.NotStarted, sut.CurrentState()); chatService.Verify(service => service.BroadcastMessageOnChannel(It.Is <string>(s => s == "No winners THIS time, but user1 was closest at just 1 seconds off!")), Times.Once()); }