Esempio n. 1
0
        public void TestControllerGetsAllHeroes()
        {
            var heroes = new List <Hero>
            {
                new Hero(),
                new Hero()
            };

            A.CallTo(() => _fakeHeroRepository.GetAllHeroes()).Returns(heroes);
            var result     = (ObjectResult)_controller.Get();
            var dataResult = (IEnumerable <Hero>)result.Value;

            Assert.AreEqual(200, result.StatusCode);
            Assert.AreEqual(2, dataResult.Count());
        }
Esempio n. 2
0
        public void ShouldReturnOkWhenUsingGet(Gender gender, GenerateNamePreference generateNamePreference)
        {
            // Arrange
            // heroServiceMock.Setup(h => h.GenerateHero(generateNamePreference)).Returns(new Hero(nameGenerator.GenerateName(gender)));
            //var s = new IHeroService();
            var unitToTest = new HeroController(new HeroService(nameGenerator));


            // Act
            var result = unitToTest.Get(generateNamePreference);

            // Asserts
            Assert.IsAssignableFrom <OkObjectResult>((OkObjectResult)result);
            var okObjectResult = result as OkObjectResult;

            Assert.IsAssignableFrom <Hero>(okObjectResult.Value);
            Assert.NotNull(okObjectResult.Value);
            Assert.Equal(StatusCodes.Status200OK, okObjectResult.StatusCode);
        }