public void AddTeamCorrect()
        {
            var teamDTO = new TeamDTO
            {
                Id   = 1,
                Naam = "Team A"
            };

            var response = new Response <TeamDTO> {
                DTO = teamDTO
            };

            //Arrange
            var mockService = new Mock <ITeamService>();

            mockService.Setup(x => x.AddTeam(It.IsAny <TeamDTO>())).Returns(response);
            var controller = new TeamController(mockService.Object);

            //Act
            var teamViewModel = new TeamViewModelRequest
            {
                //Id = 1,
                Naam = "Team A"
            };

            var addTeam = controller.Create(teamViewModel) as ObjectResult;
            var entity  = addTeam.Value as TeamViewModelResponse;

            //Assert
            Assert.DoesNotThrow(() => controller.Create(teamViewModel));
            Assert.That(entity.Id, Is.EqualTo(teamDTO.Id));
            Assert.That(entity.Naam, Is.EqualTo(teamDTO.Naam));
        }
 public static TeamDTO MapTeamViewModelRequestToTeamDTO(TeamViewModelRequest teammodel)
 {
     if (teammodel == null)
     {
         throw new NullReferenceException("team model is null");
     }
     return(new TeamDTO
     {
         //Id = teammodel.Id,
         Naam = teammodel.Naam,
         Email = teammodel.Email,
         EmailCreator = teammodel.EmailCreator
     });
 }
Esempio n. 3
0
        public IActionResult Create(TeamViewModelRequest teamViewModel)
        {
            try
            {
                var createDTO = TeamViewModelMapper.MapTeamViewModelRequestToTeamDTO(teamViewModel);
                var response  = _service.AddTeam(createDTO);


                if (response.DidError)
                {
                    return(BadRequest(response.Errors));
                }

                var createdTeam = TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(response.DTO);

                return(Ok(createdTeam));
            }
            catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }