Exemplo n.º 1
0
        public async Task Get_given_non_existing_returns_404()
        {
            var repository = new Mock <ISuperheroRepository>();

            var controller = new SuperheroesController(repository.Object);

            var actual = await controller.Get(42);

            Assert.IsType <NotFoundResult>(actual.Result);
        }
        public async Task Delete_given_repository_returns_response_returns_returnType(Response response, Type returnType)
        {
            var repository = new Mock <ISuperheroRepository>();

            repository.Setup(s => s.DeleteAsync(42)).ReturnsAsync(response);

            var logger = new Mock <ILogger <SuperheroesController> >();

            var controller = new SuperheroesController(repository.Object, logger.Object);

            var actual = await controller.Delete(42);

            Assert.IsType(returnType, actual);
        }
Exemplo n.º 3
0
        public async Task Get_given_existing_returns_superhero()
        {
            var superhero = new SuperheroDetailsDTO();

            var repository = new Mock <ISuperheroRepository>();

            repository.Setup(s => s.Read(42)).ReturnsAsync(superhero);

            var controller = new SuperheroesController(repository.Object);

            var actual = await controller.Get(42);

            Assert.Equal(superhero, actual.Value);
        }
        public async Task Get_id_given_repository_returns_null_returns_NotFound()
        {
            var superhero  = new SuperheroDetailsDTO();
            var repository = new Mock <ISuperheroRepository>();

            repository.Setup(m => m.ReadAsync(42)).ReturnsAsync(default(SuperheroDetailsDTO));

            var logger = new Mock <ILogger <SuperheroesController> >();

            var controller = new SuperheroesController(repository.Object, logger.Object);

            var result = await controller.Get(42);

            Assert.IsType <NotFoundResult>(result.Result);
        }
        public async Task Get_id_returns_result_from_repository()
        {
            var superhero  = new SuperheroDetailsDTO();
            var repository = new Mock <ISuperheroRepository>();

            repository.Setup(m => m.ReadAsync(42)).ReturnsAsync(superhero);

            var logger = new Mock <ILogger <SuperheroesController> >();

            var controller = new SuperheroesController(repository.Object, logger.Object);

            var result = await controller.Get(42);

            Assert.Equal(superhero, result.Value);
        }
        public async Task Put_given_repository_returns_response_returns_returnType(Response response, Type returnType)
        {
            var superhero = new SuperheroUpdateDTO {
                Id = 12
            };
            var repository = new Mock <ISuperheroRepository>();

            repository.Setup(s => s.UpdateAsync(superhero)).ReturnsAsync(response);

            var logger = new Mock <ILogger <SuperheroesController> >();

            var controller = new SuperheroesController(repository.Object, logger.Object);

            var actual = await controller.Put(12, superhero);

            Assert.IsType(returnType, actual);
        }
        public async Task Post_returns_CreatedAtAction_with_id()
        {
            var superhero = new SuperheroCreateDTO();

            var repository = new Mock <ISuperheroRepository>();

            repository.Setup(s => s.CreateAsync(superhero)).ReturnsAsync((Created, 42));

            var logger = new Mock <ILogger <SuperheroesController> >();

            var controller = new SuperheroesController(repository.Object, logger.Object);

            var actual = await controller.Post(superhero);

            Assert.Equal("Get", actual.ActionName);
            Assert.Equal(42, actual.RouteValues["id"]);
        }