public async Task MastermindCore_MastermindScorer(string secret, string userInput, string expected)
        {
            // Arrange
            var settings = new Mock <IOptionsMonitor <MastermindSettings> >();

            settings.Setup(x => x.CurrentValue).Returns(new MastermindSettings()
            {
                AllowedAttempts  = 10,
                SecretCodeLength = 4
            });
            var service = new MastermindService(settings.Object);
            var scorer  = new MastermindScorer(secret);
            var random  = new Random();

            // Act
            for (int i = 0; i < random.Next(0, 20); i++)
            {
                //ensures running the Score logic doesn't affect multiple scores on same instance
                await scorer.Score(service.GenerateSecretCode());
            }
            var result = await scorer.Score(userInput);

            // Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void TestCircleOfLife()
        {
            var service = new MastermindService();
            var guid    = service.CreateNewGame();
            var game    = service.GetGame(guid);
            var game2   = service.GetGame(guid);

            Assert.AreEqual(game, game2);

            service.QuitGame(guid);
            var game3 = service.GetGame(guid);

            Assert.IsNull(game3);
        }
Esempio n. 3
0
 public MastermindController(MastermindService service)
 {
     this.service = service;
 }