コード例 #1
0
        public void CreateNewRider_WithAllRequiredInformation_ShouldReturnRiderNumber()
        {
            // AAA
            // Arrange
            IRiderRepository riderRepository = Substitute.For<IRiderRepository>();
            riderRepository.Add(Arg.Any<Rider>()).Returns(
                 new Rider() {   DateOfBirth = DateTime.Parse("08/03/2000"),
                                FirstName = "Try",
                                LastName = "Me",
                                Number = 1 });

            RiderService riderService = new RiderService(riderRepository);
            Rider rider = new Rider()
                            {
                                DateOfBirth = DateTime.Parse("08/03/2000"),
                                FirstName = "Try",
                                LastName = "Me"
                            };

            // Act
            int riderNumber = riderService.CreateNewRider(  rider.FirstName,
                                                            rider.LastName,
                                                            rider.DateOfBirth);

            // Assert
            riderNumber.Should().Be(1);
        }
コード例 #2
0
        public void GetAge_RiderIsBornThisYear_ShouldBeZero()
        {
            // AAA
            // Arrange
            RiderSerivce riderSerivce = new RiderSerivce();
            Rider rider = new Rider()
            {
                City = "Atlanta",
                Country = "USA",
                DateOfBirth = DateTime.Parse("10/21/2012"),
                FirstName = "Chase",
                LastName = "Me",
                GenderEnum = GenderEnum.Male,
                Number = 431,
                RiderId = 1,
                SkillLevelEnum = RiderSkillLevelEnum.Beginner
            };

            // Act
            int age = riderSerivce.GetAge(rider, DateTime.Now);

            // Assert
            //Assert.AreEqual(0,age);
            age.Should().Be(0);
        }
コード例 #3
0
        public int GetAge(Rider pxRider, DateTime pdtDateAsAt)
        {
            // No Error Check at this pt

            //
            return pdtDateAsAt.Year - pxRider.DateOfBirth.Year
                   - (pxRider.DateOfBirth.DayOfYear < pdtDateAsAt.DayOfYear ? 0 : 1);
        }
コード例 #4
0
        public ActionResult Create(Rider rider)
        {
            if (ModelState.IsValid)
            {
                context.Riders.Add(rider);
                context.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(rider);
        }
コード例 #5
0
        public int CreateNewRider(string psFirstName, string psLastName, DateTime pdtDateOfBirth)
        {
            Rider rider = new Rider()
                {
                    DateOfBirth = pdtDateOfBirth,
                    FirstName = psFirstName,
                    LastName = psLastName
                };

            // validate last name
            if (string.IsNullOrWhiteSpace(rider.LastName)) throw new ArgumentNullException("Rider Last Name must be entered.");

            rider = _RiderRepository.Add(rider);

            return rider.Number;
        }
コード例 #6
0
        public string GetRiderClassification(
            Rider pxRider, int piAge, int currentFirstPlaceFinishes, int currentTopThreeFinishes)
        {
            // No Error Check at this pt
            //if ( piAge < 4 ) throw new Exception("Rider is not of age to race. Rider must be at least 4 years of age.");

            string classification = "{0} {1} - {2}";
            string skillLevel = RiderSkillLevelEnum.Beginner.ToString();

            if (currentFirstPlaceFinishes >= 3 && currentTopThreeFinishes >= 5) skillLevel = RiderSkillLevelEnum.Intermediate.ToString();
            else if (currentFirstPlaceFinishes >= 8 && currentTopThreeFinishes >= 10) skillLevel = RiderSkillLevelEnum.Expert.ToString();

            if (piAge > 3 && piAge <= 6)
                classification = string.Format(classification, pxRider.GenderEnum.ToString(), "6 and under", skillLevel);
            else if (piAge > 6 && piAge < 9)
                classification = string.Format(classification, pxRider.GenderEnum.ToString(), "9 and under", skillLevel);
            else if (piAge > 9 && piAge < 13)
                classification = string.Format(classification, pxRider.GenderEnum.ToString(), "12 and under", skillLevel);
            else if (piAge > 12 && piAge < 15)
                classification = string.Format(classification, pxRider.GenderEnum.ToString(), "14 and under", skillLevel);

            return classification;
        }
コード例 #7
0
 public ActionResult Edit(Rider rider)
 {
     if (ModelState.IsValid)
     {
         context.Entry(rider).State = EntityState.Modified;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(rider);
 }
コード例 #8
0
        public static TestableRiderService Create()
        {
            IRiderRepository riderRepository = Substitute.For<IRiderRepository>();
            riderRepository.Add(Arg.Any<Rider>()).Returns(
                new Rider()
                {
                    DateOfBirth = DateTime.Parse("08/03/2000"),
                    FirstName = "Try",
                    LastName = "Me",
                    Number = 1
                }
                );

            Rider rider = new Rider()
            {
                DateOfBirth = DateTime.Parse("08/03/2000"),
                FirstName = "Try",
                LastName = "Me"
            };

            return new TestableRiderService(riderRepository, rider);
        }
コード例 #9
0
 public TestableRiderService(IRiderRepository pxRepository, Rider pxRider)
     : base(pxRepository)
 {
     this._riderRepository = pxRepository;
     this.Rider = pxRider;
 }