public void When2PersonsGiven_CanCalculatesAgeDifference() { int diffReal = (int)(persons[1].BirthDate - persons[0].BirthDate).TotalDays; int diffCalculated = addressBookBusiness.CalculateAgeDifferenceInDays(persons[0].ID, persons[1].ID); addressBookRepositoryMock.Verify(abr => abr.RetrieveAllPersons(), Times.AtLeastOnce); Assert.AreEqual(diffReal, diffCalculated); }
private void ConfigureForCalculateAgeDifferenceCommand(CommandLineApplication cla) { cla.Command("calculateagediff", (application) => { application.Description = "With this command you can calculate the age difference between the given 2 people. The result will be presented in days; If the 1st person is older than 2nd one the result will be positive. If 2nd person is older than 1st person the result will be negative. Otherwise, the result will be 0."; CommandArgument idArgument1 = application.Argument("personID1", "The ID of Person.", (argument) => { argument.ShowInHelpText = true; }); CommandArgument idArgument2 = application.Argument("personID2", "The ID of Person.", (argument) => { argument.ShowInHelpText = true; }); application.OnExecute(() => { if (cla.OptionHelp.HasValue()) { application.ShowHelp("calculateagediff"); return(0); } bool parseSuccess; int person1ID, person2ID; parseSuccess = int.TryParse(idArgument1.Value, out person1ID); parseSuccess = parseSuccess & int.TryParse(idArgument2.Value, out person2ID); if (!parseSuccess) { application.Error.WriteLineAsync("The given arguments cannot be parsed."); return(-1); } int diff = addressBookBusiness.CalculateAgeDifferenceInDays(person1ID, person2ID); Console.WriteLine($"The age difference between the 2 people is {diff}"); return(0); }); }); }