コード例 #1
0
ファイル: AppTests.cs プロジェクト: thunderholt/fortune-kata
        public void Run_GivenTheUserHasEnteredTheirName_ItGreetsTheUserAndTellsThemTheFortuneForTodayAndTheirBirthday(string nowDateString, string expectedGreeting)
        {
            // Arrange
            A.CallTo(() => _dateTimeOffset.Now).Returns(DateTimeOffset.ParseExact(nowDateString, "dd/MM/yyyy", null));
            A.CallTo(() => _console.Prompt("What's your name?")).Returns("Jane Doe");
            A.CallTo(() => _console.Prompt("When were you born (dd/mm/yyyy)?")).Returns("14/06/1982");
            A.CallTo(() => _fortuneCookie.GetTodaysFortune()).Returns("Certain bears do not harm humans. Today you will meet no such bears.");
            A.CallTo(() => _fortuneCookie.GetFortuneForDate(A <DateTimeOffset> .That.Matches(d => d.Year == 1982 && d.Month == 6 && d.Day == 14))).Returns("Today you will experience an average 1G of gravity.");

            // Act
            _app.Run();

            // Assert
            A.CallTo(() => _console.WriteLine(
                         expectedGreeting + "\nYour fortune for today is: {1}",
                         "Jane Doe",
                         "Certain bears do not harm humans. Today you will meet no such bears."))
            .MustHaveHappenedOnceExactly().Then(

                A.CallTo(() => _console.WriteLine(
                             "On the day you were born your fortune was: {0}",
                             "Today you will experience an average 1G of gravity."))
                .MustHaveHappenedOnceExactly()
                );
        }
コード例 #2
0
ファイル: App.cs プロジェクト: thunderholt/fortune-kata
        public void Run()
        {
            var name = _console.Prompt("What's your name?");

            var dobString = _console.Prompt("When were you born (dd/mm/yyyy)?");

            DateTimeOffset.TryParseExact(dobString, "dd/MM/yyyy", null, DateTimeStyles.None, out var dob);

            var person = new Person
            {
                Name        = name,
                DateOfBirth = dob
            };

            var  now             = _dateTimeOffset.Now;
            bool todayIsBirthday = now.Day == person.DateOfBirth.Day && now.Month == person.DateOfBirth.Month;

            string greeting = todayIsBirthday ? "Happy birthday, {0}!" : "Hi {0}!";

            _console.WriteLine(
                greeting + "\nYour fortune for today is: {1}",
                person.Name,
                _fortuneCookie.GetTodaysFortune());

            _console.WriteLine(
                "On the day you were born your fortune was: {0}",
                _fortuneCookie.GetFortuneForDate(person.DateOfBirth));
        }