public void UpdateEncounterTeamOkTest()
        {
            ICollection <EncountersTeams> teams = new List <EncountersTeams>()
            {
                eNacional, ePeñarol
            };
            ICollection <EncountersTeams> updatedTeamList = new List <EncountersTeams>()
            {
                eCerro, ePeñarol
            };
            var encounter = new Encounter()
            {
                Id = 1, Date = DateTime.Now, SportId = football.Id, Teams = teams
            };

            encounterList.Add(encounter);
            mockEncounterRepo.Setup(x => x.Insert(It.IsAny <Encounter>())).Callback <Encounter>(x => encounterList.Add(encounter));
            mockEncounterRepo.Setup(x => x.Update(It.IsAny <Encounter>())).Callback <Encounter>(x => encounterList.First().Teams = updatedTeamList);
            mockEncounterRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(encounter);
            mockEncounterRepo.Setup(e => e.Get(It.IsAny <Expression <Func <Encounter, bool> > >(), null, "Teams")).Returns(encounterList);
            encounterBL.Add(encounter);
            encounter.Teams = updatedTeamList;
            encounterBL.Update(encounter);
            mockEncounterRepo.Verify(x => x.Insert(It.IsAny <Encounter>()), Times.Once());
            mockEncounterRepo.Verify(x => x.Update(It.IsAny <Encounter>()), Times.Once());
            mockEncounterRepo.Verify(x => x.Save(), Times.AtLeast(2));
        }
Exemplo n.º 2
0
        public ActionResult UpdateEncounter([FromBody] EncounterDTO data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var encounter = mapper.Map <Encounter>(data);
                encounterBusinessLogic.Update(encounter);
                return(Ok(mapper.Map <EncounterDTO>(encounter)));
            }
            catch (EncounterDoesNotExistException e)
            {
                return(NotFound(e.Message));
            }
            catch (EncounterException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }