public void Simple_Status_Candidate() { IRaceRepository raceRepository = Substitute.For <IRaceRepository>(); IPoliticalPartyRepository politicalPartyRepository = Substitute.For <IPoliticalPartyRepository>(); var f = new Fixture(); var race = f.Create <Race>(); var politicalParty = f.Create <PoliticalParty>(); var candidate = Create(); raceRepository.GetById(Arg.Any <Guid>()).Returns(race); politicalPartyRepository.GetById(Arg.Any <Guid>()).Returns(politicalParty); var candidateRepository = new CandidateRepository(ContextConnection(), politicalPartyRepository, raceRepository); candidateRepository.Save(candidate); candidateRepository.SetInactive(candidate); var inactive = candidateRepository.GetById(candidate.Id); Assert.That(inactive.Status == EntityStatus.Inactive); candidateRepository.SetActive(candidate); var active = candidateRepository.GetById(candidate.Id); Assert.That(active.Status == EntityStatus.Active); candidateRepository.SetAsDeleted(candidate); var deleted = candidateRepository.GetById(candidate.Id); Assert.That(deleted.Status == EntityStatus.Deleted); }
public ValidationResultInfo Validate(Candidate itemToValidate) { var validation = base.Validate(itemToValidate, GetAll(true).ToList()); var race = _raceRepository.GetById(itemToValidate.Race.Id); var politicalParty = _politicalPartyRepository.GetById(itemToValidate.PoliticalParty.Id); if (race == null) { validation.Results.Add(new ValidationResult("Invalid race reference.")); } if (politicalParty == null) { validation.Results.Add(new ValidationResult("Invalid political Party reference.")); } return(validation); }
public void SimpeHydrate_Candidate() { IRaceRepository raceRepository = Substitute.For <IRaceRepository>(); IPoliticalPartyRepository politicalPartyRepository = Substitute.For <IPoliticalPartyRepository>(); var f = new Fixture(); var race = f.Create <Race>(); var politicalParty = f.Create <PoliticalParty>(); var candidate = Create(); raceRepository.GetById(Arg.Any <Guid>()).Returns(race); politicalPartyRepository.GetById(Arg.Any <Guid>()).Returns(politicalParty); var candidateRepository = new CandidateRepository(ContextConnection(), politicalPartyRepository, raceRepository); var id = candidateRepository.Save(candidate); Assert.IsNotNull(id); Assert.AreEqual(id, candidate.Id); }
public void SimpeDeHydrateAll_Candidate() { IRaceRepository raceRepository = Substitute.For <IRaceRepository>(); IPoliticalPartyRepository politicalPartyRepository = Substitute.For <IPoliticalPartyRepository>(); var f = new Fixture(); var race = f.Create <Race>(); var politicalParty = f.Create <PoliticalParty>(); var candidate = Create(); raceRepository.GetById(Arg.Any <Guid>()).Returns(race); politicalPartyRepository.GetById(Arg.Any <Guid>()).Returns(politicalParty); var candidateRepository = new CandidateRepository(ContextConnection(), politicalPartyRepository, raceRepository); candidateRepository.Save(candidate); var owner = candidateRepository.GetAll(); Assert.That(owner.Any()); }
public void SetData(int raceId, string type) { Type = type; RaceId = raceId; _raceRepository = new RaceRepository(); var race = _raceRepository.GetById(raceId); var model = new List<ResultViewModel>(); if (race != null) { if (type == "Race") { model.AddRange(from result in race.GetRaceResults() let qualiResult = race.GetQualifyingResult(result.Entry) select new ResultViewModel { Name = result.Entrant.Driver.Name, Time = result.Entry.FastestLap.ToLapTime(true), Position = result.GetPositionString(true), Points = result.Points.ToString(), GridPosition = qualiResult.Position.ToString(), TotalPoints = (result.Points + qualiResult.Points).ToString(), HasQualifyingPoints = result.Entry.PointsSystem.GivesPointsForQualifying, HasFastestLap = race.GotFastestLap(result.Entrant.Driver), RaceTime = result.Entry.RaceTime }); } else { model.AddRange(race.GetQualificationResults().Select(result => new ResultViewModel { Name = result.Entrant.Driver.Name, Time = result.LapTime.ToLapTime(true), Position = result.GetQualifyingPositionString(true), Points = result.Points.ToString(), HasQualifyingPoints = result.Entry.PointsSystem.GivesPointsForQualifying })); } } InlineResultRepeater.DataSource = model; InlineResultRepeater.DataBind(); }