コード例 #1
0
        public ActionResult Index(RequestProfileViewModel view)
        {
            string            csvProfilesPath = Server.MapPath(@"bin\MortalityProfiles.csv");
            MortalityReporter reporter        = new MortalityReporter(new TimeProvider(), csvProfilesPath);
            LifeReport        report          = reporter.GetLifeReport(view.Birthday.Value, view.Gender.Value, view.SelectedCountry);

            ViewProfileViewModel responseView = new ViewProfileViewModel(view);

            responseView.Countries           = CountryCatalog.GetCountryList();
            responseView.Messsage            = MortalityReporter.FormatMessage(report);
            responseView.LifeExpectancyGraph = CreateExpectancyGraph(report.WeeksLived, report.ExpectedWeeks);
            return(this.View("Report", responseView));
        }
コード例 #2
0
        public void MortalityReport_WhenProvidingDate_ReturnsAgeAndWeeks()
        {
            string myCountry = "Mexico";
            DateTime myBirthday = new DateTime(1981, 04, 29);
            GenderType myGender = GenderType.Male;

            Mock<ITimeProvider> myTime = new Mock<ITimeProvider>();
            myTime.Setup(x => x.GetCurrentDate()).Returns(new DateTime(2015, 04, 29));

            MortalityReporter reporter = new MortalityReporter(myTime.Object, "MortalityProfiles.csv");
            LifeReport report = reporter.GetLifeReport(myBirthday, myGender, myCountry);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.WeeksLived > 0);
            Assert.IsTrue(report.YearsLived > 0);
            Assert.AreEqual(34, report.YearsLived);
        }
コード例 #3
0
        public void MortalityReport_WhenProvidingDate_ReturnsAgeAndWeeks()
        {
            string     myCountry  = "Mexico";
            DateTime   myBirthday = new DateTime(1981, 04, 29);
            GenderType myGender   = GenderType.Male;

            Mock <ITimeProvider> myTime = new Mock <ITimeProvider>();

            myTime.Setup(x => x.GetCurrentDate()).Returns(new DateTime(2015, 04, 29));

            MortalityReporter reporter = new MortalityReporter(myTime.Object, "MortalityProfiles.csv");
            LifeReport        report   = reporter.GetLifeReport(myBirthday, myGender, myCountry);

            Assert.IsNotNull(report);
            Assert.IsTrue(report.WeeksLived > 0);
            Assert.IsTrue(report.YearsLived > 0);
            Assert.AreEqual(34, report.YearsLived);
        }