コード例 #1
0
        public void TestAgeCalculation_ReturnsCorrectAge()
        {
            //arrange
            string testDateOfBirthStr = "01/01/2000";

            //act
            var age = ageCalc.CalculateAge(testDateOfBirthStr);

            //assert
            Assert.AreEqual(age, 20);
        }
コード例 #2
0
        public IActionResult Index(AgeCalculator model)
        {
            SetViewBagValues();
            if (!ModelState.IsValid)
            {
                return(View());
            }

            model.Result = model.CalculateAge();
            return(View(model));
        }
コード例 #3
0
        public IActionResult Index(AgeCalculator model)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Age = model.CalculateAge();
            }
            else
            {
                ViewBag.Age = 0;
            }

            return(View(model));
        }
コード例 #4
0
        public async Task <PeopleViewModel> GetViewModel(string selectedName = "Name")
        {
            var peopleDataFilePath = System.Web.HttpContext.Current.Server.MapPath(@"App_Data") + "\\" + DATA_FILE_NAME;
            var viewData           = await peopleDataProvider.GetPeople(peopleDataFilePath);

            var         peopleNames    = PeopleModelMapper.MapToPeopleSelectItems(viewData);
            PeopleModel selectedPerson = !string.IsNullOrEmpty(selectedName) ?
                                         viewData.FirstOrDefault(d => d.Name.Trim().ToUpper() == selectedName.Trim().ToUpper())
                : new PeopleModel()
            {
                Name = string.Empty, BirthPlace = string.Empty, DateOfBirth = string.Empty, Height = string.Empty, Weight = string.Empty
            };

            selectedPerson.Age = !string.IsNullOrEmpty(selectedName) ? AgeCalculator.CalculateAge(selectedPerson.DateOfBirth) : 0;
            return(new PeopleViewModel()
            {
                People = selectedPerson, PeopleNames = peopleNames, SelectedName = selectedName
            });
        }