Esempio n. 1
0
        private IActionResult TryPut(int id, MatchModelIn aMatch)
        {
            IActionResult result;

            try
            {
                SetSession();
                EncounterDto modified = encounterService.ModifyEncounter(id, aMatch.TeamIds, aMatch.Date, aMatch.SportName);
                modified.id = id;
                EncounterModelOut output = factory.CreateModelOut(modified);
                result = Ok(output);
            }
            catch (ServiceException e)
            {
                if (e.Error.Equals(ErrorType.ENTITY_NOT_FOUND))
                {
                    result = TryPostMatch(id, aMatch.TeamIds, aMatch.SportName, aMatch.Date);
                }
                else
                {
                    result = errors.GenerateError(e);
                }
            }
            return(result);
        }
        public void ModifyTest()
        {
            teamsRepo.Add(teamA);
            teamsRepo.Add(teamB);
            teamsRepo.Add(teamC);
            serviceToTest.AddEncounter(matchAvsBDto);
            EncounterDto modifiedAvsB = new EncounterDto()
            {
                id = 1, teamsIds = new List <int>()
                {
                    teamB.Id, teamA.Id
                }, date = matchAvsB.Date.AddDays(1), sportName = sport.Name
            };

            SetUpRepository();
            serviceToTest.ModifyEncounter(modifiedAvsB);
            EncounterDto modified = serviceToTest.GetEncounter(matchAvsB.Id);

            Assert.AreEqual(modifiedAvsB.teamsIds.Count, modified.teamsIds.Count);
            Assert.AreEqual(modifiedAvsB.date, modified.date);
        }
        public void ModifyNoDataAccessTest()
        {
            teamsRepo.Add(teamA);
            teamsRepo.Add(teamB);
            teamsRepo.Add(teamC);

            Mock <IEncounterRepository> fakeRepo = new Mock <IEncounterRepository>();

            fakeRepo.Setup(r => r.GetAll()).Throws(new DataInaccessibleException());
            serviceToTest = new EncounterService(fakeRepo.Object, teamsRepo, sportsRepo, usersRepo, auth.Object);

            EncounterDto modifiedAvsB = new EncounterDto()
            {
                id = 1, teamsIds = new List <int>()
                {
                    teamB.Id, teamA.Id
                }, date = matchAvsB.Date.AddDays(1), sportName = sport.Name
            };

            serviceToTest.ModifyEncounter(modifiedAvsB);
        }