public ActionResult CreateTeam([FromBody] TeamDTO data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var team = mapper.Map <Team>(data); teamBusinessLogic.Add(team); return(Ok(mapper.Map <TeamDTO>(team))); } catch (SportDoesNotExistException e) { return(NotFound(e.Message)); } catch (TeamAlreadyInSportException e) { return(BadRequest(e.Message)); } catch (TeamException e) { return(BadRequest(e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public void AddTeamOkTest() { var team = new Team() { Id = 1, Name = "Nacional", SportId = 1 }; var sport = new Sport() { Id = 1, Name = "SportName" }; var teamsList = new List <Team>(); mockTeamRepo.Setup(x => x.Insert(It.IsAny <Team>())).Callback <Team>(x => teamsList.Add(team)); mockSportRepo.Setup(r => r.Get(It.IsAny <Expression <Func <Sport, bool> > >(), null, "Teams")).Returns(sportList); teamBL.Add(team); mockTeamRepo.Verify(x => x.Insert(It.IsAny <Team>()), Times.Once()); mockTeamRepo.Verify(x => x.Save(), Times.Once()); }