Esempio n. 1
0
        public void Get_ServiceReturnsNumber_CorrectResponseProvided()
        {
            // ARRANGE
            string word = "word";
            int    numberOfCharacters           = 4;
            string expectedResponse             = $"The word '{word}' contains {numberOfCharacters} characters.";
            Mock <ICountCharactersService> mock = new Mock <ICountCharactersService>();

            mock
            .Setup(m => m.CountCharacters(It.IsAny <string>()))
            .Returns(numberOfCharacters);
            DummyController controller = new DummyController(mock.Object);

            // ACT
            IActionResult response = controller.Get(word);

            // ASSERT
            Assert.IsType <OkObjectResult>(response);
            OkObjectResult okResponse = (OkObjectResult)response;

            Assert.IsType <string>(okResponse.Value);
            string content = (string)okResponse.Value;

            Assert.Equal(expectedResponse, content);
        }