public void SetUp()
        {
            football = new SportDTO()
            {
                Name = "Futbol"
            };
            river = new TeamDTO()
            {
                Name = "River", SportName = "Futbol"
            };
            boca = new TeamDTO()
            {
                Name = "Boca", SportName = "Futbol"
            };

            encounterServicesMock    = new Mock <IEncounterSimpleServices>();
            encounterQueryServices   = new Mock <IEncounterQueryServices>();
            fixtureGeneratorServices = new Mock <IFixtureServices>();
            teamServices             = new Mock <ITeamServices>();

            santiago = new UserDTO()
            {
                UserName = "******",
                Name     = "Mauricio",
                Surname  = "Santiago",
                Password = "******",
                Mail     = "*****@*****.**",
                IsAdmin  = true
            };
        }
示例#2
0
        public SportDTO deleteSport(int id)
        {
            using (var uow = new UnitOfWork())
            {
                var sportRepository = uow.GetRepository <Sport>();
                var sportEventRepo  = uow.GetRepository <SportEvent>();
                var sport           = sportRepository.GetById(id);

                if (sport == null)
                {
                    return(null);
                }
                else
                {
                    var existSporEvents = sportEventRepo.FindBy(sp => sp.CategoryId == id).FirstOrDefault();
                    if (existSporEvents != null)
                    {
                        return(null);
                    }

                    sportRepository.Delete(id);
                    uow.SaveChanges();

                    SportMapper sportMapper = new SportMapper();
                    SportDTO    sportVM     = sportMapper.MapToDTO(sport);
                    return(sportVM);
                }
            }
        }
示例#3
0
        public async Task <SportDTO> CreateSport(SportDTO sport)
        {
            var mappedSport   = _mapper.Map <Sport>(sport);
            var returnedSport = await _sportRepository.CreateSport(mappedSport);

            return(_mapper.Map <SportDTO>(returnedSport));
        }
        public void CreateInvalidNullSportTest()
        {
            SportServices service = new SportServices(login, sportRepo);
            SportDTO      sport   = new SportDTO();

            service.CreateSport(sport);
        }
示例#5
0
        public void CreateSportAlreadyExistsSportsController()
        {
            sportServicesMock.Setup(s => s.CreateSport(It.IsAny <SportDTO>())).Throws(new ServicesException());


            ILoginServices login = new LoginServicesMock(rodolfo);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new SportsController(login, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            SportDTO footballIn = new SportDTO()
            {
                Name = "Futbol"
            };
            var result = controller.CreateSport(footballIn);

            sportServicesMock.Verify(s => s.CreateSport(It.IsAny <SportDTO>()), Times.AtMostOnce);
            var createdResult = result as BadRequestObjectResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(400, createdResult.StatusCode);
        }
示例#6
0
        public void CreateSportOkSportsController()
        {
            sportServicesMock.Setup(s => s.CreateSport(It.IsAny <SportDTO>()));
            ILoginServices login = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new SportsController(login, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            SportDTO footballIn = new SportDTO()
            {
                Name = "Futbol"
            };
            var result = controller.CreateSport(footballIn);

            sportServicesMock.Verify(s => s.CreateSport(It.IsAny <SportDTO>()), Times.AtMostOnce);
            var createdResult = result as CreatedAtRouteResult;
            var footballOut   = createdResult.Value as SportDTO;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual("GetSport", createdResult.RouteName);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual(footballIn.Name, footballOut.Name);
        }
示例#7
0
        public void DeleteSportWithoutPermissionSportsController()
        {
            string name    = "Futbol";
            var    modelIn = new SportDTO()
            {
                Name = name
            };


            sportServicesMock.Setup(s => s.DeleteSport(name)).Throws(new InsufficientPermissionException());



            ILoginServices loginServices = new LoginServicesMock(mariano);

            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Authorization"] = "";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var controller = new SportsController(loginServices, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object)
            {
                ControllerContext = controllerContext,
            };

            var result = controller.DeleteSport(name);

            sportServicesMock.Verify(s => s.DeleteSport(name), Times.AtMostOnce);
            var badRequestResult = result as UnauthorizedResult;

            Assert.AreEqual(401, badRequestResult.StatusCode);
        }
示例#8
0
 private void AddSport(URN id, SportDTO item, CultureInfo culture)
 {
     lock (_mergeLock)
     {
         try
         {
             if (Sports.ContainsKey(id))
             {
                 SportCI ci;
                 Sports.TryGetValue(id, out ci);
                 ci?.Merge(new SportCI(item, _dataRouterManager, culture), culture);
             }
             else
             {
                 Sports.Add(id, new SportCI(item, _dataRouterManager, culture));
             }
             if (item.Categories != null)
             {
                 foreach (var categoryData in item.Categories)
                 {
                     AddCategory(categoryData.Id, categoryData, culture);
                 }
             }
         }
         catch (Exception e)
         {
             ExecutionLog.Error($"Error saving SportDTO for {id} and lang={culture.TwoLetterISOLanguageName}.", e);
         }
     }
 }
示例#9
0
        public ActionResult UpdateSport([FromBody] SportDTO data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var sport = mapper.Map <Sport>(data);
                sportBusinessLogic.Update(sport);
                return(Ok(mapper.Map <SportDTO>(sport)));
            }
            catch (SportDoesNotExistException e)
            {
                return(NotFound(e.Message));
            }
            catch (SportException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public void RecoverAllFollowedTeams()
        {
            ILoginServices loginServices = new LoginServices(userRepo, teamRepo);
            IUserServices  userServices  = new UserServices(loginServices, userRepo, teamRepo, sportRepo);
            ITeamServices  teamServices  = new TeamServices(loginServices, teamRepo, sportRepo, userRepo);
            ISportServices sportServices = new SportServices(loginServices, sportRepo);

            loginServices.CreateSession("sSanchez", "user");

            TeamDTO cavaliers = new TeamDTO()
            {
                Name      = "Cavaliers",
                Logo      = EncondeImage(Image.FromFile(GetResourcePath("Cavaliers.jpg"))),
                SportName = "Baskteball"
            };
            SportDTO basketball = new SportDTO()
            {
                Name = "Baskteball"
            };

            TeamDTO team = new TeamDTO()
            {
                Name      = "Cavaliers",
                Logo      = EncondeImage(Image.FromFile(GetResourcePath("Cavaliers.jpg"))),
                SportName = "Baskteball"
            };

            sportServices.CreateSport(basketball);
            teamServices.CreateTeam(team);
            teamServices.AddFollowedTeam("Cavaliers_Baskteball");

            IEnumerable <TeamDTO> followedTeams = userServices.GetFollowedTeams();

            Assert.AreEqual(cavaliers.Name, followedTeams.First().Name);
        }
        internal LotteryDTO(lottery item)
            : base(new sportEvent
        {
            id   = item == null ? "wns:lottery:1" : item.id,
            name = item.name,
            scheduledSpecified = false,
            scheduled          = DateTime.MinValue,
            tournament         = item.sport == null
                    ? null
                    : new tournament
            {
                sport = item.sport
            }
        })
        {
            Guard.Argument(item, nameof(item)).NotNull();

            if (item.sport != null)
            {
                Sport = new SportDTO(item.sport.id, item.sport.name, (IEnumerable <tournamentExtended>)null);
            }
            if (item.category != null)
            {
                Category = new CategorySummaryDTO(item.category);
            }
            if (item.bonus_info != null)
            {
                BonusInfo = new BonusInfoDTO(item.bonus_info);
            }
            if (item.draw_info != null)
            {
                DrawInfo = new DrawInfoDTO(item.draw_info);
            }
        }
示例#12
0
        public Sport MapFromDTO(SportDTO source)
        {
            Sport target = new Sport();

            target.Id   = source.Id;
            target.Name = source.Name;
            return(target);
        }
示例#13
0
        public SportDTO MapToDTO(Sport source)
        {
            SportDTO target = new SportDTO();

            target.Id   = source.Id;
            target.Name = source.Name;
            return(target);
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SportCI"/> class.
        /// </summary>
        /// <param name="data">A <see cref="SportDTO" /> instance containing sport data</param>
        /// <param name="dataRouterManager">The <see cref="IDataRouterManager"/> used to obtain categories</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the provided data</param>
        public SportCI(SportDTO data, IDataRouterManager dataRouterManager, CultureInfo culture)
            : base(data.Id, data.Name, culture)
        {
            if (data.Categories != null)
            {
                CategoryIds = new ReadOnlyCollection <URN>(data.Categories.Select(i => i.Id).ToList());
            }

            _dataRouterManager = dataRouterManager;
        }
示例#15
0
        public IHttpActionResult Delete(int id)
        {
            var      sportService = new SportService();
            SportDTO svm          = sportService.deleteSport(id);

            if (svm == null)
            {
                return(BadRequest("This sport does not exist in DB"));
            }
            return(Ok(svm));
        }
示例#16
0
        public IHttpActionResult Post(SportDTO sportVM)
        {
            var      sportService = new SportService();
            SportDTO svm          = sportService.addSport(sportVM);

            if (svm == null)
            {
                return(BadRequest("This sport already exist in DB"));
            }

            return(Ok(svm));
        }
示例#17
0
        public IHttpActionResult Get(int id)
        {
            var sportService = new SportService();

            SportDTO account = sportService.getSportById(id);

            if (account == null)
            {
                return(NotFound());
            }

            return(Ok(account));
        }
示例#18
0
        public async Task <ActionResult <SportDTO> > CreateSport([FromBody] SportDTO sport)
        {
            try
            {
                var returnedSport = await _sportService.CreateSport(sport);

                return(Ok(returnedSport));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
 public void TestInit()
 {
     contextFactory = GetContextFactory();
     sportRepo      = new SportRepository(contextFactory);
     teamRepo       = new TeamRepository(contextFactory);
     futbol         = CreateFutbol();
     rugby          = CreateRugby();
     boca           = CreateBocaTeam();
     river          = CreateTeamThatBelongsInTheB();
     sportRepo.Add(new Sport("Futbol"));
     teamRepo.Add(new Team(boca.Name, new Sport("Futbol")));
     teamRepo.Add(new Team(river.Name, new Sport("Futbol")));
     login = CreateLoginServices();
 }
示例#20
0
        public void ModifySport(SportDTO sportDTO)
        {
            validator.ValidatePermissions();
            Sport sport = sportMapper.Map(sportDTO);

            try
            {
                sportRepository.Update(sport);
            }
            catch (DataAccessException e)
            {
                throw new ServicesException($"Failure to modify sport with name {sportDTO.Name}.", e);
            }
        }
示例#21
0
        public void  Post(SportDTO sport)
        {
            var result = dBContext.Sports.Where(x => x.Name == sport.Name).SingleOrDefault();

            if (result != null)
            {
                return;
            }
            dBContext.Sports.Add(new DB.Models.Sport()
            {
                Name = sport.Name
            });
            dBContext.SaveChanges();
        }
示例#22
0
        public SportDTO CreateSport(SportDTO sportDTO)
        {
            validator.ValidatePermissions();
            Sport sport = sportMapper.Map(sportDTO);

            try
            {
                sportRepository.Add(sport);
                return(sportMapper.Map(sport));
            }
            catch (DataAccessException e)
            {
                throw new ServicesException($"Failure to create sport with name {sportDTO.Name}.", e);
            }
        }
示例#23
0
 private void SaveTournamentDataFromSport(SportDTO sportDTO, CultureInfo culture)
 {
     if (sportDTO.Categories != null)
     {
         foreach (var categoryData in sportDTO.Categories)
         {
             if (categoryData.Tournaments != null)
             {
                 foreach (var tournamentData in categoryData.Tournaments)
                 {
                     SaveTournamentDataToSportEventCache(tournamentData, tournamentData.CurrentSeason?.Id, culture);
                 }
             }
         }
     }
 }
 public IActionResult CreateSport(SportDTO sport)
 {
     try
     {
         CreateSession();
         return(TryToCreate(sport));
     }
     catch (InsufficientPermissionException)
     {
         return(Unauthorized());
     }
     catch (ServicesException e)
     {
         return(BadRequest(e.Message));
     }
 }
        public void FollowTeam()
        {
            ILoginServices loginServices = new LoginServicesMock(pepe);
            ITeamServices  teamServices  = new TeamServices(loginServices, teamRepo, sportRepo, userRepo);
            ISportServices sportServices = new SportServices(loginServices, sportRepo);

            SportDTO basketball = new SportDTO()
            {
                Name = "Basketball"
            };

            sportServices.CreateSport(basketball);

            TeamDTO cavaliers = new TeamDTO()
            {
                Name      = "Cavaliers",
                Logo      = EncondeImage(Image.FromFile(GetResourcePath("Cavaliers.jpg"))),
                SportName = "Basketball"
            };

            teamServices.CreateTeam(cavaliers);
            userRepo.Add(new User()
            {
                UserName = pepe.UserName,
                Name     = pepe.Name,
                Surname  = pepe.Surname,
                Mail     = pepe.Mail,
                Password = pepe.Password,
                Role     = pepe.IsAdmin ? Role.Administrator : Role.Follower
            });
            userRepo.Add(new User()
            {
                UserName = pablo.UserName,
                Name     = pablo.Name,
                Surname  = pablo.Surname,
                Mail     = pablo.Mail,
                Password = pablo.Password,
                Role     = pablo.IsAdmin ? Role.Administrator : Role.Follower
            });
            loginServices = new LoginServicesMock(pablo);
            teamServices.AddFollowedTeam("Cavaliers_Basketball");

            User        recovered     = userRepo.Get(pepe.UserName);
            List <Team> followedTeams = recovered.FollowedTeams.ToList();

            Assert.IsTrue(followedTeams.First().Name == "Cavaliers");
        }
示例#26
0
        public async Task <ActionResult <SportDTO> > UpdateSport([FromBody] SportDTO sport)
        {
            try
            {
                var returnedSport = await _sportService.UpdateSport(sport);

                return(Ok(returnedSport));
            }
            catch (ArgumentNullException exception)
            {
                return(NotFound(exception.Message));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
示例#27
0
        public void SportDTOMappingTest()
        {
            var tours = RMF.GetTournamentExtendedList(100);

            var dto = new SportDTO("sr:sport:1", "name", tours);

            Assert.AreEqual(tours.Count, dto.Categories.Select(c => c.Tournaments).Count());

            foreach (var t in tours)
            {
                var cat = dto.Categories.ToList().Find(c => c.Id.ToString() == t.category.id);
                Assert.IsNotNull(cat, "Category missing.");
                Assert.AreEqual(t.category.id, cat.Id.ToString(), "Category id wrong.");
                Assert.AreEqual(t.category.name, cat.Name, "Category name wrong.");

                ValidateTournamentExtended(t, cat.Tournaments.First(c => c.Id.ToString() == t.id));
            }
        }
示例#28
0
        public SportDTO getSportById(int id)
        {
            using (var uow = new UnitOfWork())
            {
                var   sportRepository = uow.GetRepository <Sport>();
                Sport sport           = sportRepository.GetById(id);

                if (sport == null)
                {
                    return(null);
                }

                SportMapper sportMapper = new SportMapper();

                SportDTO svm = sportMapper.MapToDTO(sport);
                return(svm);
            }
        }
示例#29
0
        public IEnumerable <SportDTO> getAllSports()
        {
            using (var uow = new UnitOfWork())
            {
                var sportRepository = uow.GetRepository <Sport>();
                var sports          = sportRepository.GetAll().ToList();

                List <SportDTO> list        = new List <SportDTO>();
                SportMapper     sportMapper = new SportMapper();
                foreach (var sport in sports)
                {
                    SportDTO sportVM = sportMapper.MapToDTO(sport);
                    list.Add(sportVM);
                }

                list.OrderBy(sp => sp.Name);
                return(list);
            }
        }
示例#30
0
        public void SetUp()
        {
            football = new SportDTO()
            {
                Name = "Futbol"
            };
            tennis = new SportDTO()
            {
                Name = "Tenis"
            };
            encounterQueryServices = new Mock <IEncounterQueryServices>();
            encounterServicesMock  = new Mock <IEncounterSimpleServices>();
            sportServicesMock      = new Mock <ISportServices>();
            positionServicesMock   = new Mock <IPositionsServices>();
            teamServicesMock       = new Mock <ITeamServices>();

            CreateUserMariano();
            CreateUserRodolfo();
        }