Exemple #1
0
        public void ShouldExerciseCompetitionTeamRepositoryNHibernate()
        {
            var repo     = new CompetitionTeamRepository(new RepositoryNHibernate <CompetitionTeam>());
            var compRepo = new CompetitionRepository(new RepositoryNHibernate <Competition>());

            var comp1 = new Season(null, "Season 1", 1, null, null, null, null, false, false, 1, null);
            var comp2 = new Playoff(null, "Playoff 1", 1, 1, null, null, null, null, false, false, 1, null);

            compRepo.Update(comp1);
            compRepo.Update(comp2);

            for (int i = 0; i < 10; i++)
            {
                var syt = new CompetitionTeam(comp1, null, "Team " + i, null, null, 5, null, 1, null);
                repo.Update(syt);
            }

            for (int i = 0; i < 5; i++)
            {
                var syt = new CompetitionTeam(comp2, null, "Team " + (i * 100), null, null, 5, null, 1, null);
                repo.Update(syt);
            }

            //can we get them all?
            var teams = repo.GetAll().ToList();
            var test  = teams.Where(t => t.Competition.Id == comp1.Id).ToList();

            StrictEqual(15, teams.Count);
            teams = repo.GetByCompetition(comp1).ToList();
            StrictEqual(10, teams.Count());
            teams = repo.GetByCompetition(comp2).ToList();
            StrictEqual(5, teams.Count());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var competitionRepository = new CompetitionRepository();

            competitionRepository.AddCompetition(new Competition()
            {
                Name         = "Mistrzostwa świata",
                StarDateTime = DateTime.Today,
                Matches      = new List <Match>()
                {
                    new Match()
                    {
                        Date = DateTime.Today.AddDays(1)
                    },
                    new Match()
                    {
                        Date = DateTime.Today.AddDays(2)
                    }
                }
            });

            foreach (var competition in competitionRepository.Competitions)
            {
                Console.WriteLine($"{competition.Name}, date: {competition.StarDateTime}, matches count: {competition.Matches.Count}");
            }
            Console.ReadKey();
        }
Exemple #3
0
        public void ShouldExerciseStandingsRepository()
        {
            var compRepo = new CompetitionRepository(new RepositoryNHibernate <Competition>());

            var repo = new StandingsRepository(new RepositoryNHibernate <SeasonTeam>(), compRepo);


            var season      = new Season(null, "Season 1", 1, null, null, null, null, true, false, 1, null);
            var seasonTeams = new List <CompetitionTeam>()
            {
                new SeasonTeam(season, null, "Team 1", null, null, 5, null, 1, null, null, null),
                new SeasonTeam(season, null, "Team 2", null, null, 5, null, 1, null, null, null),
                new SeasonTeam(season, null, "Team 3", null, null, 5, null, 1, null, null, null),
                new SeasonTeam(season, null, "Team 4", null, null, 5, null, 1, null, null, null),
                new SeasonTeam(season, null, "Team 5", null, null, 5, null, 1, null, null, null),
                new SeasonTeam(season, null, "Team 6", null, null, 5, null, 1, null, null, null),
                new SeasonTeam(season, null, "Team 7", null, null, 5, null, 1, null, null, null),
            };

            season.Teams = seasonTeams;
            compRepo.Update(season);
            var teams = repo.GetByCompetition(compRepo.GetByNameAndYear("Season 1", 1).Id);

            StrictEqual(7, teams.Count);
        }
        public ActionResult SweatyTShirts(int userID, long competitionID)
        {
            if (userID <= 0)
            {
                throw new ApplicationException("Missing argument UserID");
            }

            ViewBag.IsUserAdmin  = IsUserAdmin;
            ViewBag.UserID       = UserID;
            ViewBag.ShowUserName = false;

            List <SweatyTShirt> list = null;

            using (CompetitionRepository competitionRepository = new CompetitionRepository())
            {
                list = competitionRepository.GetSweatyTShirtsForUser(userID, competitionID)
                       .OrderByDescending(o => o.CreatedDate)
                       .ToList();
            }

            //if DeleteSweatyTShirt redirected to here show the purr message
            if (TempData[ControllerHelpers.PURR] != null)
            {
                ViewBag.Purr = TempData[ControllerHelpers.PURR];
                TempData[ControllerHelpers.PURR] = null;
            }

            return(View("SweatyTShirts", list));
        }
        /// <summary>
        /// User clicked "Delete" on Competition/EditCompetition.cshtml, Home/Index.cshtml, or
        /// Competition/UserInCompetitions.cshtml.
        /// </summary>
        /// <param name="competitionID"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public ActionResult DeleteUserInCompetition(long competitionID,
                                                    int userID,
                                                    string redirectToAction,
                                                    string redirectToController = null)
        {
            using (CompetitionRepository repository = new CompetitionRepository())
            {
                repository.DeleteUserInCompetition(competitionID, userID);
            }

            TempData[ControllerHelpers.PURR] = new Purr()
            {
                Title = "Success", Message = "The User was successfully deleted from the Competition."
            };

            switch (redirectToAction.ToLower())
            {
            case "editcompetition":
                return(RedirectToAction(redirectToAction, new { competitionID = competitionID }));

            case "edituser":
                return(RedirectToAction(redirectToAction, redirectToController, new { userID = userID }));

            default:
                if (!string.IsNullOrEmpty(redirectToController))
                {
                    return(RedirectToAction(redirectToAction, redirectToController));
                }
                else
                {
                    return(RedirectToAction(redirectToAction));
                }
            }
        }
        public IEnumerable <Jump> GetAllForAthlete(int idAthlete)
        {
            ICompetitionRepository competitionRepository = new CompetitionRepository(context: _context);
            IEliminationRepository eliminationRepository = new EliminationRepository(_context);
            IContestRepository     contestRepository     = new ContestRepository(_context);

            var         competitions = competitionRepository.GetAllForAthlete(idAthlete);
            List <Jump> result       = new List <Jump>();

            foreach (var competition in competitions)
            {
                var elimination = eliminationRepository.GetEliminationByCompetitionID(competition.IdCompetition);
                var contest     = contestRepository.GetContestByCompetitionID(competition.IdCompetition);

                if (elimination != null)
                {
                    var jumps = GetAllForElimination(elimination.IdElimination).ToList();
                    result = result.Concat(second: jumps).ToList();
                }
                if (contest != null)
                {
                    var jumps = GetAllForContest(contest.IdContest).ToList();
                    result = result.Concat(second: jumps).ToList();
                }
            }

            return(result);
        }
        public ActionResult Create(CreateCompetitionViewModel createCompetitionViewModel)
        {
            if (ModelState.IsValid)
            {
                CompetitionRepository competitionRepository = new CompetitionRepository(db);
                Competition           competition           = new Competition();

                competition.Name              = createCompetitionViewModel.Name;
                competition.CompetitionType   = null;
                competition.CompetitionTypeId = createCompetitionViewModel.CompetitionTypeId;
                competition.Date              = createCompetitionViewModel.Date;
                competition.TotalMoney        = 0;
                competition.CreatedAt         = DateTime.Now;
                competition.UpdatedAt         = DateTime.Now;

                competitionRepository.Insert(competition);
                competitionRepository.Commit();
                return(RedirectToAction("Index"));
            }

            CompetitionTypeRepository competitionTypeRepository = new CompetitionTypeRepository(db);

            createCompetitionViewModel.CompetitionTypes = competitionTypeRepository.GetAll().ToList();
            createCompetitionViewModel.PageTitle        = "Create Competition";
            return(View(createCompetitionViewModel));
        }
        public ActionResult SweatyTShirts(long competitionID)
        {
            ViewBag.IsUserAdmin  = IsUserAdmin;
            ViewBag.UserID       = UserID;
            ViewBag.ShowUserName = true;

            List <SweatyTShirt> list = null;

            using (CompetitionRepository competitionRepository = new CompetitionRepository())
            {
                list = competitionRepository.GetSweatyTShirtsInCompetition(competitionID)
                       .OrderBy(o => o.UserProfile.FullName)
                       .OrderByDescending(o => o.CreatedDate)
                       .ToList();
            }

            //if DeleteSweatyTShirt redirected to here show the purr message
            if (TempData[ControllerHelpers.PURR] != null)
            {
                ViewBag.Purr = TempData[ControllerHelpers.PURR];
                TempData[ControllerHelpers.PURR] = null;
            }

            return(View(list));
        }
Exemple #9
0
        public void ShouldExerciseTeamRankingRepositoryNHibernate()
        {
            var compRepo = new CompetitionRepository(new RepositoryNHibernate <Competition>());
            var repo     = new TeamRankingRepository(new RepositoryNHibernate <TeamRanking>());

            var comp1 = new Season(null, "Season 1", 1, null, null, null, null, false, false, 1, null);
            var comp2 = new Playoff(null, "Playoff 1", 1, 1, null, null, null, null, false, false, 1, null);

            compRepo.Update(comp1);
            compRepo.Update(comp2);

            for (int i = 0; i < 10; i++)
            {
                var ranking = new TeamRanking(1, "Group 1", new CompetitionTeam(comp1, null, "Team " + (i * 10), null, null, 5, null, 1, null), 1);
                repo.Update(ranking);
            }

            for (int i = 0; i < 5; i++)
            {
                var ranking = new TeamRanking(1, "Group 5", new CompetitionTeam(comp2, null, "Team " + (i * 100), null, null, 5, null, 1, null), 1);
                repo.Update(ranking);
            }

            var rankings = repo.GetByCompetition(comp1.Id);

            StrictEqual(10, rankings.Count());
            rankings = repo.GetByCompetition(comp2.Id);
            StrictEqual(5, rankings.Count());
        }
        public void TestGetCompetitions()
        {
            CompetitionRepository repo = new CompetitionRepository(new CompetitionRepositoryLocalContext());

            List <Competition> comps = repo.GetUpcomingCompetitions();

            Assert.AreEqual(3, comps.Count);
        }
Exemple #11
0
 public AthletePerformanceController(
     AthleteRepository athleteRepository,
     AthletePerformanceRepository athletePerformanceRepository,
     CompetitionRepository competitionRepository)
 {
     _athleteRepository            = athleteRepository;
     _athletePerformanceRepository = athletePerformanceRepository;
     _competitionRepository        = competitionRepository;
 }
Exemple #12
0
 public void Handle(PlayGameCommand command)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         var competition = CompetitionRepository.GetOrCreate(_eventBus);
         competition.PlayGame(command.RedOffensive, command.RedDefensive, command.BlueOffensive, command.BlueDefensive, command.ScoreRed, command.ScoreBlue);
         session.SubmitChanges();
     }
 }
        private UnitOfWork()
        {
            Database.SetInitializer<AthletesFollowUpContext>(new DropCreateDatabaseIfModelChanges<AthletesFollowUpContext>());
            context = new AthletesFollowUpContext();

            AthleteRepository = new AthleteRepository(context);
            TrainingRepository = new TrainingRepository(context);
            CompetitionRepository = new CompetitionRepository(context);
        }
Exemple #14
0
 public CompetitionController(
     CompetitionRepository competitionRepository,
     SportsComplexRepository sportsComplexRepository,
     AthletePerformanceRepository athletePerformanceRepository)
 {
     _competitionRepository        = competitionRepository;
     _sportsComplexRepository      = sportsComplexRepository;
     _athletePerformanceRepository = athletePerformanceRepository;
 }
        public void GetCompetitionByIdAndReturnCompetition()
        {
            CompetitionRepository competitionRepository = new CompetitionRepository(_context, _mapper);

            //Act
            var items = competitionRepository.GetByID(1);

            //Assert
            Assert.Equal("Superliga Argentina", items.Name);
        }
        public void GetCompetitionsAndReturnExactQuantity()
        {
            CompetitionRepository competitionRepository = new CompetitionRepository(_context, _mapper);

            //Act
            var items = competitionRepository.GetCompetitions();

            //Assert
            Assert.Equal(2, items.Count);
        }
Exemple #17
0
        public virtual void SendEmails()
        {
            var sweatyTShirtEmails = new CompetitionRepository().SweatyTShirtEmails();

            if (sweatyTShirtEmails == null || sweatyTShirtEmails.Count <= 0)
            {
                return;
            }

            List <int> distinctUserIds = new List <int>();

            //if web.config has configuration is automatically reads it.
            using (SmtpClient smtpClient = new SmtpClient())
            {
                MailAddress fromAddress = new MailAddress(FromEmailAddress, "Sweaty T-Shirt");
                string      subject     = "Sweaty T-Shirt Added";

                foreach (var sweatyTShirtEmail in sweatyTShirtEmails)
                {
                    try
                    {
                        //because this runs on background thread cannot use MvcMail package, the httpContext is not available.
                        string emailBody = SweatyTShirtEmailHtml.Replace("@Title", subject)
                                           .Replace("@RecipientFullName", sweatyTShirtEmail.RecipientFullName)
                                           .Replace("@RecipientEmailAddress", sweatyTShirtEmail.RecipientEmailAddress)
                                           .Replace("@SweatyTShirtFullName", sweatyTShirtEmail.SweatyTShirtFullName)
                                           .Replace("@SweatyTShirtEmailAddress", sweatyTShirtEmail.SweatyTShirtEmailAddress)
                                           .Replace("@Description", sweatyTShirtEmail.Description)
                                           .Replace("@Amount", sweatyTShirtEmail.Amount.ToString());

                        MailAddress toAddress = new MailAddress(sweatyTShirtEmail.RecipientEmailAddress,
                                                                sweatyTShirtEmail.RecipientFullName);

                        MailMessage mailMessage = new MailMessage(fromAddress, toAddress)
                        {
                            Subject    = subject,
                            Body       = emailBody,
                            IsBodyHtml = true
                        };

                        smtpClient.Send(mailMessage);
                        if (!distinctUserIds.Contains(sweatyTShirtEmail.RecipientUserID))
                        {
                            new AccountRepository().UpdateLastEmailSent(sweatyTShirtEmail.RecipientUserID);
                            distinctUserIds.Add(sweatyTShirtEmail.RecipientUserID);
                        }
                    }
                    catch (Exception ex)
                    {
                        Exception ex2 = new Exception(string.Format("Error sending sweaty t shirt email to {0}", sweatyTShirtEmail.RecipientEmailAddress), ex);
                        Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(ex2));
                    }
                }
            }
        }
Exemple #18
0
 public void Handle(RegisterPlayarCommand command)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         var repository  = new PlayarRepository(_eventBus);
         var competition = CompetitionRepository.GetOrCreate(_eventBus);
         var id          = Guid.NewGuid();
         repository.Add(new Playar(id, command.Name));
         competition.AddPlayer(id);
         session.SubmitChanges();
     }
 }
        public void CreateByPOST_WhenDoesNotReceiveANameForTheCompetition_AddNewCompetitionToRepositoryWithARandomName()
        {
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            controller.Create(new CreateCompetitionModel());

            Assert.AreEqual(1, competitionRepository.Count);
            var compCreated = competitionRepository[0];
            Assert.IsNotNull(compCreated.Name);
        }
        private void DeleteSweatyTShirt(long sweatyTShirtID)
        {
            using (CompetitionRepository competitionRepository = new CompetitionRepository())
            {
                competitionRepository.DeleteSweatyTShirt(sweatyTShirtID);
            }

            TempData[ControllerHelpers.PURR] = new Purr()
            {
                Title = "Success", Message = "The Sweaty-T-Shirt was successfully deleted."
            };
        }
        public ActionResult AddUserInCompetition(long competitionID)
        {
            UserInCompetition userInCompetition = new UserInCompetition()
            {
                CompetitionID = competitionID
            };

            using (CompetitionRepository repository = new CompetitionRepository())
            {
                userInCompetition.Competition = repository.GetCompetition(competitionID);
            }
            return(View(userInCompetition));
        }
        public void CreateByPOST_WhenExecuteCorrectly_AddNewCompetitionToRepository()
        {
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            var createCompetitionModel = new CreateCompetitionModel();
            createCompetitionModel.Name = "name";

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            controller.Create(createCompetitionModel);

            Assert.AreEqual(1, competitionRepository.Count);
            var compCreated = competitionRepository[0];
            Assert.AreEqual(createCompetitionModel.Name, compCreated.Name);
        }
        public ActionResult ToggleUserInCompetition(long competitionID,
                                                    int userID,
                                                    string redirectToAction,
                                                    string redirectToController)
        {
            if (competitionID <= 0 || userID <= 0)
            {
                throw new ArgumentException(string.Format("Invalid competitionID or userID argument, both must be greater than zero: competitionID: {0}, userID: {1}", competitionID, userID));
            }

            string action = null;

            using (CompetitionRepository repository = new CompetitionRepository())
            {
                action = (repository.ToggleUserInCompetition(competitionID, userID) == true ? string.Empty : "de");
            }

            //entire page gets refreshed.  TODO: put the table on a partial view
            //and update it via a JSON call.
            if (string.IsNullOrEmpty(redirectToAction))
            {
                return(Content(string.Empty));
            }
            else
            {
                TempData[ControllerHelpers.PURR] = new Purr()
                {
                    Title = "Success", Message = string.Format("The User in the Competition was successfully {0}activated.", action)
                };
                switch (redirectToAction)
                {
                case "EditCompetition":
                    return(RedirectToAction(redirectToAction, new { competitionID = competitionID }));

                case "EditUser":
                    return(RedirectToAction(redirectToAction, redirectToController, new { userID = userID }));

                default:
                    if (!string.IsNullOrEmpty(redirectToController))
                    {
                        return(RedirectToAction(redirectToAction, redirectToController));
                    }
                    else
                    {
                        return(RedirectToAction(redirectToAction));
                    }
                }
            }
        }
        public ActionResult DeleteCompetition(long competitionID)
        {
            using (CompetitionRepository repository = new CompetitionRepository())
            {
                repository.DeleteCompetition(competitionID);
            }

            TempData[ControllerHelpers.PURR] = new Purr()
            {
                Title = "Success", Message = "Competition was successfully deleted."
            };

            //entire page gets refreshed
            return(RedirectToAction("Index"));
        }
        public void Admin_WhenExistsAtLeastACompetition_ShowListOfExistentCompetitions()
        {
            var competition = new Competition();
            var compRep = new CompetitionRepository {QueryableSession = new InMemoryQueryableSession<Competition>()};
            compRep.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = compRep;
            var result = controller.Admin() as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as IList<Competition>;
            Assert.IsNotNull(model);
            Assert.IsTrue(model.Contains(competition));
        }
Exemple #26
0
        public void DeleteByPOST_WhenExecuteCorrectly_RemoveTheCompetitionFromTheRepository()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Delete(competition.Id, new FormCollection());

            Assert.IsFalse(competitionRepository.Contains(competition), "The competition should have been removed from the repository");
        }
Exemple #27
0
        public void CreateByPOST_WhenDoesNotReceiveANameForTheCompetition_AddNewCompetitionToRepositoryWithARandomName()
        {
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Create(new CreateCompetitionModel());

            Assert.AreEqual(1, competitionRepository.Count);
            var compCreated = competitionRepository[0];

            Assert.IsNotNull(compCreated.Name);
        }
        public ActionResult AddUserInCompetition(UserInCompetition userInCompetition)
        {
            try
            {
                //HACK the competition property is set NULL in AddUserInCompetition.
                //this is needed to send email
                Competition competition = null;
                if (userInCompetition.SendEmail)
                {
                    competition = userInCompetition.Competition;
                }

                using (CompetitionRepository repository = new CompetitionRepository())
                {
                    repository.AddUserInCompetition(userInCompetition, AccountRepository.AllUsersPassword);
                }

                if (userInCompetition.SendEmail)
                {
                    userInCompetition.Competition = competition;
                    using (var msg = new SendMail().UserInCompetitionAdded(userInCompetition, true))
                    {
                        //msg.SendAsync(userState: userInCompetition.Email);
                        msg.Send();
                        //msg.Dispose();
                    }
                }

                TempData[ControllerHelpers.PURR] = new Purr()
                {
                    Title = "Success", Message = "The User was successfully added to the Competition."
                };

                //entire page gets refreshed when this view calls parent.location.reload.
                //TODO: put the users table on a partial view and update it via a JSON call.
                return(View("../Shared/ClosePopup"));
            }
            catch (RepositoryException ex)
            {
                //clear model errors for DateInvited
                ModelState.Clear();
                ModelState.AddModelError("AddUserInCompetition", ex.Message);
            }
            return(View(userInCompetition));
        }
        public ActionResult UserInCompetitions()
        {
            List <UserInCompetition> list = null;

            using (CompetitionRepository competitionRepository = new CompetitionRepository())
            {
                list = competitionRepository.GetUserInCompetitionsForUser(UserID);
            }

            //if another method redirected to here show the purr message
            if (TempData[ControllerHelpers.PURR] != null)
            {
                ViewBag.Purr = TempData[ControllerHelpers.PURR];
                TempData[ControllerHelpers.PURR] = null;
            }

            return(View(list));
        }
        public List <Prediction> GetAllPredictions(User u)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(PredictionQueries.GetAllPredictions(u), connection);
                connection.Open();
                try
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        CompetitionRepository compRepo = new CompetitionRepository(new CompetitionRepositorySQLContext());
                        List <Prediction>     list     = new List <Prediction>();
                        while (reader.Read())
                        {
                            Prediction p = new Prediction();
                            p.ID   = (int)reader["prediction_id"];
                            p.Name = (string)reader["name"];

                            p.User        = u;
                            p.Competition = compRepo.GetCompetition((int)reader["competition_id"]);
                            p.Components  = GetPredictionComponents(p.ID);

                            p.Checked = false;
                            foreach (var component in p.Components)
                            {
                                if (component.Checked == true)
                                {
                                    p.Points  = (int)reader["points"];
                                    p.Checked = true;
                                }
                            }

                            list.Add(p);
                        }
                        return(list);
                    }
                }
                catch (SqlException e)
                {
                    throw e;
                }
            }
        }
Exemple #31
0
        public void Delete_LoadTheCompetitionOnTheViewModel()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id);

            var result = actionResult as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(competition, result.Model);
        }
Exemple #32
0
        public void CreateByPOST_WhenExecuteCorrectly_AddNewCompetitionToRepository()
        {
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };
            var createCompetitionModel = new CreateCompetitionModel();

            createCompetitionModel.Name = "name";

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Create(createCompetitionModel);

            Assert.AreEqual(1, competitionRepository.Count);
            var compCreated = competitionRepository[0];

            Assert.AreEqual(createCompetitionModel.Name, compCreated.Name);
        }
Exemple #33
0
        public void Admin_WhenExistsAtLeastACompetition_ShowListOfExistentCompetitions()
        {
            var competition = new Competition();
            var compRep     = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            compRep.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = compRep;
            var result = controller.Admin() as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as IList <Competition>;

            Assert.IsNotNull(model);
            Assert.IsTrue(model.Contains(competition));
        }
Exemple #34
0
        public void Details_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();

            competition.Name = "testingCompetition";
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Details(competition.Name);

            var result = actionResult as ViewResult;

            Assert.AreEqual(competition, result.Model);
        }
        public void Delete_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id);

            var result = actionResult as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual(competition, result.Model);
        }
        public void DeleteByPOST_WhenExecuteCorrectly_RedirectToIndex()
        {
            var competition = new Competition();
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id, new FormCollection());

            var redirectToRouteResult = actionResult as RedirectToRouteResult;
            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Admin", redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual("The competition was deleted.", controller.TempData["InformationMessage"]);
        }
        public void DeleteByPOST_WhenExecuteCorrectly_RemoveTheCompetitionFromTheRepository()
        {
            var competition = new Competition();
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            controller.Delete(competition.Id, new FormCollection());

            Assert.IsFalse(competitionRepository.Contains(competition),"The competition should have been removed from the repository");
        }
        public void Details_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();
            competition.Name = "testingCompetition";
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Details(competition.Name);

            var result = actionResult as ViewResult;
            Assert.AreEqual(competition, result.Model);
        }