public void AddManyEncountersOkTest()
        {
            ICollection <EncountersTeams> teams = new List <EncountersTeams>()
            {
                eNacional, ePeñarol
            };
            DateTime date      = new DateTime(2018, 9, 27, 8, 30, 00);
            var      encounter = new Encounter()
            {
                Id = 1, Date = date, SportId = football.Id, Teams = teams
            };
            var encounter2 = new Encounter()
            {
                Id = 2, Date = date.AddDays(5), SportId = football.Id, Teams = teams
            };

            mockEncounterRepo.Setup(x => x.Insert(encounter)).Callback <Encounter>(x => encounterList.Add(encounter));
            mockEncounterRepo.Setup(x => x.Insert(encounter2)).Callback <Encounter>(x => encounterList.Add(encounter2));
            var encounters = new List <Encounter>()
            {
                encounter, encounter2
            };

            encounterBL.AddMany(encounters);
            mockEncounterRepo.Verify(x => x.Insert(It.IsAny <Encounter>()), Times.Exactly(2));
            mockEncounterRepo.Verify(x => x.Save(), Times.Once());
        }
コード例 #2
0
        public ActionResult CreateManyEncounters([FromBody] ICollection <EncounterDTO> data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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