public void TestChristmaPickServiceUsingTheSequentialNumberGeneratorWithOneRuleThatIsAlwaysPassingForOddChristmasYear()
        {
            PersonCollection pickList = new PersonCollection();

              Person MaxG = new Person("Max", "Gehred", new DateTime(2001, 9, 30), "31111111-2222-3333-4444-555555555555");
              Person CharlotteG = new Person("Charlotte", "Gehred", new DateTime(2005, 4, 21), "41111111-2222-3333-4444-555555555555");
              Person MadelineG = new Person("Madeline", "Gehred", new DateTime(1988, 4, 15), "14111111-2222-3333-4444-555555555555");
              Person CecilaG = new Person("Cecila", "Gehred", new DateTime(1990, 6, 21), "15111111-2222-3333-4444-555555555555");
              pickList.Add(MaxG);
              pickList.Add(CharlotteG);
              pickList.Add(MadelineG);
              pickList.Add(CecilaG);

              IPickListService testObj = new PickListServiceAdvanced(new SequentialNumberGenerator(pickList.Count), new TestRuleProvider(), pickList);

              XMasPickList actual = testObj.CreateChristmasPick(new DateTime(2007, 12, 25));

              XMasPick expectedFirstPick = new XMasPick(CharlotteG, MaxG);
              Assert.IsTrue((expectedFirstPick == actual[0]));

              XMasPick expectedSecondPick = new XMasPick(MaxG, CecilaG);
              Assert.IsTrue(expectedSecondPick == actual[1]);

              XMasPick expectedThirdPick = new XMasPick(CecilaG, MadelineG);
              Assert.IsTrue(expectedThirdPick == actual[2]);

              XMasPick expectedFourthPick = new XMasPick(MadelineG, CharlotteG);
              Assert.IsTrue(expectedFourthPick == actual[3]);
        }
예제 #2
0
        static void Main(string[] args)
        {
            DateTime christmasThisYear = new DateTime(2016, 12, 25);
                  string adultArchivePath = @"C:\Users\gehredbo\Source\Hobby\ChristmasPick\Archive\Adult\Archive.xml";
                  string kidArchivePath = @"C:\Users\gehredbo\Source\Hobby\ChristmasPick\Archive\Kids\Archive.xml";
                  IXMasArchivePersister adultPersister = new FileArchivePersister(adultArchivePath);
                  IXMasArchivePersister kidPersister = new FileArchivePersister(kidArchivePath);
                  IFamilyProvider familyProvider = new FileFamilyProvider(@"C:\Users\gehredbo\Source\Hobby\ChristmasPick\Archive\Gehred\GehredFamily.xml");
                  // Go ahead and get family
                  FamilyTree gehredFamily = familyProvider.GetFamilies();
                  XMasArchive adultArchive = adultPersister.LoadArchive();
                  XMasArchive kidArchive = kidPersister.LoadArchive();
                  // Create two poeple collections
                  PersonCollection kidList = gehredFamily.CreateChristmasKidList(christmasThisYear);
                  PersonCollection adultList = gehredFamily.CreateChristmasAdultList(christmasThisYear);

                  IPickListRuleProvider kidRules = new KidListRuleProvider(gehredFamily, kidArchive, 5);
                  IPickListService picker = new PickListServiceAdvanced(new RandomNumberGenerator(kidList.Count), kidRules, kidList);
                  XMasPickList kidPicklist = picker.CreateChristmasPick(christmasThisYear);
                  XMasPickListValidator validation = new XMasPickListValidator();
                  try
                  {
                      var checkList = validation.PickListToValidateWithPeopleList(kidList, kidPicklist);
                      if (validation.isPickListValid(checkList))
                      {
                          kidArchive.Add(christmasThisYear.Year, kidPicklist);
                          kidPersister.SaveArchive(kidArchive);
                      }
                      else
                      {
                          Console.WriteLine("The kid pick list has errors. Nothing was saved.");
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("An exception occurred validating kids picklist: {0}", ex.ToString());
                  }

                  IPickListRuleProvider adultRules = new AdultListRuleProvider(gehredFamily, adultArchive, 5);
                  IPickListService adultPicker = new PickListServiceAdvanced(new RandomNumberGenerator(adultList.Count), adultRules, adultList);
                  XMasPickList adultPickList = adultPicker.CreateChristmasPick(christmasThisYear);

                  try
                  {
                      var checkList = validation.PickListToValidateWithPeopleList(adultList, adultPickList);
                      if (validation.isPickListValid(checkList))
                      {
                          adultArchive.Add(christmasThisYear.Year, adultPickList);
                          adultPersister.SaveArchive(adultArchive);
                      }
                      else
                      {
                          Console.WriteLine("The adult pick list has errors. Nothing was saved.");
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("An exception occurred: {0}", ex.ToString());
                  }
        }