Beispiel #1
0
        public void GEDCOMDocument_Save_Saves_Document_Regardless_Of_Record_Order_And_Type(string fileName, int recordCount)
        {
            //Arrange
            var document = new GEDCOMDocument();

            if (recordCount > 0)
            {
                document.AddRecord(Util.CreateIndividualRecord(1));
            }

            document.AddRecord(Util.CreateHeaderRecord(fileName));

            if (recordCount > 1)
            {
                document.AddRecord(Util.CreateIndividualRecord(2));
            }

            var sb     = new StringBuilder();
            var writer = GEDCOMWriter.Create(sb);

            writer.NewLine = "\n";

            //Act
            document.Save(writer);

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(fileName), sb);
        }
        public void GEDCOMReader_Read_Reads_Record_If_One_Individual_Record()
        {
            GEDCOMReader     reader;
            GEDCOMRecordList records;

            using (Stream s = GetEmbeddedFileStream("TwoIndividuals"))
            {
                reader  = GEDCOMReader.Create(s);
                records = reader.Read();
            }

            //Get first real record
            GEDCOMRecord record = records[2];

            //Assert that Name record is valid
            GEDCOMRecord nameRecord = record.ChildRecords.GetLineByTag(GEDCOMTag.NAME);

            GEDCOMAssert.IsValidRecord(nameRecord, 1, "John /Smith/", false, -1);

            //Assert that Sex record is valid
            GEDCOMRecord sexRecord = record.ChildRecords.GetLineByTag(GEDCOMTag.SEX);

            GEDCOMAssert.IsValidRecord(sexRecord, 1, "M", false, -1);

            //Assert that Birth record is valid
            GEDCOMRecord birthRecord = record.ChildRecords.GetLineByTag(GEDCOMTag.BIRT);

            GEDCOMAssert.IsValidRecord(birthRecord, 1, "", true, 2);
            Assert.AreEqual(GEDCOMTag.DATE, birthRecord.ChildRecords[0].TagName);
            Assert.AreEqual(GEDCOMTag.PLAC, birthRecord.ChildRecords[1].TagName);

            GEDCOMRecord dateRecord = birthRecord.ChildRecords.GetLineByTag(GEDCOMTag.DATE);

            GEDCOMAssert.IsValidRecord(dateRecord, 2, "10 Apr 1964", false, -1);

            GEDCOMRecord placeRecord = birthRecord.ChildRecords.GetLineByTag(GEDCOMTag.PLAC);

            GEDCOMAssert.IsValidRecord(placeRecord, 2, "AnyTown", false, -1);

            //Assert that Death record is valid
            GEDCOMRecord deathRecord = record.ChildRecords.GetLineByTag(GEDCOMTag.DEAT);

            GEDCOMAssert.IsValidRecord(deathRecord, 1, "", true, 2);
            Assert.AreEqual(GEDCOMTag.DATE, deathRecord.ChildRecords[0].TagName);
            Assert.AreEqual(GEDCOMTag.PLAC, deathRecord.ChildRecords[1].TagName);

            dateRecord = deathRecord.ChildRecords.GetLineByTag(GEDCOMTag.DATE);
            GEDCOMAssert.IsValidRecord(dateRecord, 2, "15 May 1998", false, -1);

            placeRecord = birthRecord.ChildRecords.GetLineByTag(GEDCOMTag.PLAC);
            GEDCOMAssert.IsValidRecord(placeRecord, 2, "AnyTown", false, -1);
        }
Beispiel #3
0
        public void GEDCOMDocument_Load_Loads_Document_With_Header_If_Document_Is_WellFormed(string fileName)
        {
            //Arrange
            var document = new GEDCOMDocument();

            //Act
            using (Stream s = GetEmbeddedFileStream(fileName))
            {
                document.Load(new StreamReader(s));
            }

            GEDCOMAssert.IsValidHeader(document.SelectHeader());
            GEDCOMAssert.HeaderIsEqual(Util.CreateHeaderRecord(fileName), document.SelectHeader());
        }
Beispiel #4
0
        public void GEDCOMWriter_WriterRecords_Correctly_Renders_Two_Individual_Records()
        {
            var          sb     = new StringBuilder();
            GEDCOMWriter writer = GEDCOMWriter.Create(sb);

            writer.NewLine = "\n";

            GEDCOMRecordList individuals = Util.CreateIndividualRecords();

            //write Individuals
            writer.WriteRecords(individuals);

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString("TwoIndividuals"), sb);
        }
Beispiel #5
0
        public void GEDCOMWriter_WriterRecord_Correctly_Renders_Individual_Record_And_Children()
        {
            var          sb     = new StringBuilder();
            GEDCOMWriter writer = GEDCOMWriter.Create(sb);

            writer.NewLine = "\n";

            GEDCOMIndividualRecord record = Util.CreateIndividualRecord(1);

            //write Header
            writer.WriteRecord(record);

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString("OneIndividual"), sb);
        }
Beispiel #6
0
        public void GEDCOMStore_UpdateFamily_Should_Update_Properties_Of_The_Family(string fileName, string idToUpdate, string updatedFileName)
        {
            //Arrange
            string testFile = "UpdateFamily.ged";
            var    db       = CreateStore(String.Format("{0}.ged", fileName), testFile);

            Family updateFamily = db.Families.Single(ind => ind.Id == idToUpdate);

            //Act
            db.UpdateFamily(updateFamily);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
        public void GEDCOMReader_ReadHeader_Returns_GEDCOMHeaderRecord(string fileName)
        {
            GEDCOMReader       reader;
            GEDCOMHeaderRecord actualRecord;
            GEDCOMHeaderRecord expectedRecord = Util.CreateHeaderRecord(fileName);

            using (Stream s = GetEmbeddedFileStream(fileName))
            {
                reader       = GEDCOMReader.Create(s);
                actualRecord = reader.ReadHeader();
            }

            GEDCOMAssert.IsValidHeader(actualRecord);
            GEDCOMAssert.HeaderIsEqual(expectedRecord, actualRecord);
        }
Beispiel #8
0
        public void GEDCOMStore_AddFamily_Should_Add_Child(string fileName, string childId, string updatedFileName)
        {
            //Arrange
            const string testFile  = "AddFamily.ged";
            var          db        = CreateStore(String.Format("{0}.ged", fileName), testFile);
            var          newFamily = CreateTestFamily();
            var          child     = CreateTestIndividual(childId);

            newFamily.Children.Add(child);

            //Act
            db.AddFamily(newFamily);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
Beispiel #9
0
        public void GEDCOMStore_AddFamily_Should_Add_Husband_And_Wife(string fileName, string husbandId, string wifeId, string updatedFileName)
        {
            //Arrange
            const string testFile  = "AddFamily.ged";
            var          db        = CreateStore(String.Format("{0}.ged", fileName), testFile);
            Family       newFamily = CreateTestFamily();

            newFamily.HusbandId = husbandId;
            newFamily.WifeId    = wifeId;

            //Act
            db.AddFamily(newFamily);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
Beispiel #10
0
        public void GEDCOMDocument_SaveGEDCOM_Saves_Document(string fileName, int individualCount, int familyCount)
        {
            //Arrange
            var document = new GEDCOMDocument();

            document.AddRecord(Util.CreateHeaderRecord(fileName));
            for (int i = 1; i <= individualCount; i++)
            {
                document.AddRecord(Util.CreateIndividualRecord(i));
            }
            for (int i = 1; i <= familyCount; i++)
            {
                document.AddRecord(Util.CreateFamilyRecord(i));
            }

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(fileName), document.SaveGEDCOM());
        }
        public void GEDCOMStore_AddIndividual_Should_Create_Family_If_Father_Or_Mother_And_Family_Does_Not_Exist(string fileName, string id, string fatherId, string motherId, string updatedFileName)
        {
            //Arrange
            const string testFile = "AddIndividual.ged";
            var          db       = CreateStore($"{fileName}.ged", testFile);

            Individual newIndividual = CreateTestIndividual(id);

            newIndividual.FatherId = fatherId;
            newIndividual.MotherId = motherId;

            //Act
            db.AddIndividual(newIndividual);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
        public void GEDCOMStore_UpdateIndividual_Should_Update_Family_If_Father_Or_Mother_Is_Changed_And_New_Family_Exists(string fileName, string idToUpdate, string fatherId, string motherId, string updatedFileName)
        {
            //Arrange
            const string testFile = "UpdateIndividual.ged";
            var          db       = CreateStore($"{fileName}.ged", testFile);

            Individual updateIndividual = db.Individuals.Single(ind => ind.Id == idToUpdate);

            updateIndividual.FatherId = fatherId;
            updateIndividual.MotherId = motherId;

            //Act
            db.UpdateIndividual(updateIndividual);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
        public void GEDCOMStore_UpdateIndividual_Should_Update_Properties_Of_The_Individual(string fileName, string idToUpdate, string updatedFileName)
        {
            //Arrange
            const string testFile = "UpdateIndividual.ged";
            var          db       = CreateStore($"{fileName}.ged", testFile);

            Individual updateIndividual = db.Individuals.Single(ind => ind.Id == idToUpdate);

            updateIndividual.FirstName = TestConstants.IND_UpdateFirstName;
            updateIndividual.LastName  = TestConstants.IND_UpdateLastName;

            //Act
            db.UpdateIndividual(updateIndividual);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
        public void GEDCOMReader_ReadIndividual_Returns_Correct_GEDCOMIndividualRecord(string fileName, int recordNo)
        {
            GEDCOMReader           reader;
            GEDCOMIndividualRecord actualRecord   = null;
            GEDCOMIndividualRecord expectedRecord = Util.CreateIndividualRecord(recordNo);

            using (Stream s = GetEmbeddedFileStream(fileName))
            {
                reader = GEDCOMReader.Create(s);
                for (int i = 0; i < recordNo; i++)
                {
                    actualRecord = reader.ReadIndividual();
                }
            }

            GEDCOMAssert.IsValidIndividual(actualRecord);
            GEDCOMAssert.IndividualIsEqual(expectedRecord, actualRecord);
        }
        public void GEDCOMStore_DeleteIndividual_Should_Remove_The_Individual_From_Any_Families_In_The_Document(string fileName, string idToDelete, string updatedFileName)
        {
            //Arrange
            const string testFile   = "DeleteIndividual.ged";
            var          db         = CreateStore($"{fileName}.ged", testFile);
            Individual   individual = CreateTestIndividual(idToDelete);

            if (individual.Id == "2")
            {
                individual.Sex = Sex.Female;
            }

            //Act
            db.DeleteIndividual(individual);
            db.SaveChanges();

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(updatedFileName), GetFileString(testFile));
        }
Beispiel #16
0
        public void GEDCOMDocument_Save_Saves_Document_Using_TextWriter(string fileName, int recordCount)
        {
            //Arrange
            var document = new GEDCOMDocument();

            document.AddRecord(Util.CreateHeaderRecord(fileName));
            for (int i = 1; i <= recordCount; i++)
            {
                document.AddRecord(Util.CreateIndividualRecord(i));
            }

            var sb     = new StringBuilder();
            var writer = new StringWriter(sb);

            writer.NewLine = "\n";

            //Act
            document.Save(writer);

            //Assert
            GEDCOMAssert.IsValidOutput(GetEmbeddedFileString(fileName), sb);
        }