Ejemplo n.º 1
0
        public async Task <ActionResult <RolDTO> > Post([FromBody] RolCreateDTO rolCreate)
        {
            var rol    = mapper.Map <Rol>(rolCreate);
            var rolDTO = mapper.Map <RolDTO>(await repository.Save(rol));

            return(new CreatedAtRouteResult("ObtenerRolv1", new { id = rol.Id }, rolDTO));
        }
Ejemplo n.º 2
0
        public async Task Verificar_PostRol()
        {
            Rol nuevo = new Rol {
                Id = 3, Nombre = "Anciano"
            };
            RolCreateDTO nuevoCreate = new RolCreateDTO {
                Nombre = "Anciano"
            };
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper     = mockMapper.CreateMapper();
            var repository = new Mock <IRolRepository>();

            repository.Setup(x => x.Save(It.IsAny <Rol>())).ReturnsAsync(nuevo).Verifiable();
            var controller = new RolesController(repository.Object, mapper);

            //act
            var actionResult = await controller.Post(nuevoCreate);

            var result = actionResult.Result as CreatedAtRouteResult;
            var dto    = result.Value as RolDTO;

            Assert.Equal(3, dto.Id);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <RolDTO> > Put(int id, [FromBody] RolCreateDTO rolCreate)
        {
            var rol     = mapper.Map <Rol>(rolCreate);
            var rolRepo = await repository.Update(id, rol);

            if (rolRepo == null)
            {
                return(NotFound());
            }
            var rolDTO = mapper.Map <RolDTO>(rolRepo);

            return(new CreatedAtRouteResult("ObtenerRolv1", new { id = rol.Id }, rolDTO));
        }