public void WebSiteBasicExample() { FtMeta meta = new FtMeta(); meta.LineCommentChar = '~'; meta.HeadingLineCount = 2; FtStringMetaField petNameMetaField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; petNameMetaField.Name = "PetName"; FtFloatMetaField ageMetaField = meta.FieldList.New(FtStandardDataType.Float) as FtFloatMetaField; ageMetaField.Name = "Age"; FtStringMetaField colorMetaField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; colorMetaField.Name = "Color"; FtDateTimeMetaField dateReceivedMetaField = meta.FieldList.New(FtStandardDataType.DateTime) as FtDateTimeMetaField; dateReceivedMetaField.Name = "DateReceived"; dateReceivedMetaField.Format = "d MMM yyyy"; FtDecimalMetaField priceMetaField = meta.FieldList.New(FtStandardDataType.Decimal) as FtDecimalMetaField; priceMetaField.Name = "Price"; FtBooleanMetaField needsWalkingMetaField = meta.FieldList.New(FtStandardDataType.Boolean) as FtBooleanMetaField; needsWalkingMetaField.Name = "NeedsWalking"; FtStringMetaField typeMetaField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; typeMetaField.Name = "Type"; string filePath = Path.Combine(TestFolder, BasicExampleFileName); FtWriterSettings writerSettings = new FtWriterSettings(); writerSettings.Declared = true; writerSettings.MetaReferenceType = FtMetaReferenceType.Embedded; writerSettings.EmbeddedMetaIndent = true; writerSettings.EmbeddedMetaIndentChars = " "; using (StreamWriter strmWriter = new StreamWriter(filePath, false, System.Text.Encoding.UTF8)) { using (FtWriter writer = new FtWriter(meta, strmWriter, writerSettings)) { FtStringField petNameField = writer.FieldList.Get(petNameMetaField.Name) as FtStringField; int petNameFieldIndex = writer.GetOrdinal(petNameMetaField.Name); FtFloatField ageField = writer.FieldList.Get(ageMetaField.Name) as FtFloatField; int ageFieldIndex = writer.GetOrdinal(ageMetaField.Name); FtStringField colorField = writer.FieldList.Get(colorMetaField.Name) as FtStringField; int colorFieldIndex = writer.GetOrdinal(colorMetaField.Name); FtDateTimeField dateReceivedField = writer.FieldList.Get(dateReceivedMetaField.Name) as FtDateTimeField; int dateReceivedFieldIndex = writer.GetOrdinal(dateReceivedMetaField.Name); FtDecimalField priceField = writer.FieldList.Get(priceMetaField.Name) as FtDecimalField; int priceFieldIndex = writer.GetOrdinal(priceMetaField.Name); FtBooleanField needsWalkingField = writer.FieldList.Get(needsWalkingMetaField.Name) as FtBooleanField; int needsWalkingFieldIndex = writer.GetOrdinal(needsWalkingMetaField.Name); FtStringField typeField = writer.FieldList.Get(typeMetaField.Name) as FtStringField; int typeFieldIndex = writer.GetOrdinal(typeMetaField.Name); for (int i = 0; i < headingArray.Length; i++) { petNameField.Headings[i] = headingArray[i].PetName; ageField.Headings[i] = headingArray[i].Age; colorField.Headings[i] = headingArray[i].Color; dateReceivedField.Headings[i] = headingArray[i].DateReceived; priceField.Headings[i] = headingArray[i].Price; needsWalkingField.Headings[i] = headingArray[i].NeedsWalking; typeField.Headings[i] = headingArray[i].Type; } for (int i = 0; i < 2; i++) { if (recArray[i].PetName != null) { petNameField.Value = recArray[i].PetName; } if (recArray[i].Age.HasValue) { // test assigning to AsObject as Single Single ageAsSingle = (Single)(recArray[i].Age.Value); ageField.AsObject = ageAsSingle; Assert.AreEqual <Single>(ageAsSingle, (Single)ageField.Value); // test assigning to AsObject as Decimal Decimal ageAsDecimal = (Decimal)(recArray[i].Age.Value); ageField.AsObject = ageAsDecimal; Assert.AreEqual <Decimal>(ageAsDecimal, (Decimal)ageField.Value); // assign as Double ageField.Value = recArray[i].Age.Value; } if (recArray[i].Color != null) { colorField.Value = recArray[i].Color; } if (recArray[i].DateReceived.HasValue) { dateReceivedField.Value = recArray[i].DateReceived.Value; } if (recArray[i].Price.HasValue) { // test assigning to AsObject as Single Single priceAsSingle = (Single)(recArray[i].Price.Value); priceField.AsObject = priceAsSingle; Assert.AreEqual <Single>(priceAsSingle, (Single)priceField.Value); // test assigning to AsObject as Double Double priceAsDouble = (Double)(recArray[i].Price.Value); priceField.AsObject = priceAsDouble; Assert.AreEqual <Double>(priceAsDouble, (Double)priceField.Value); // assign as Decimal priceField.Value = recArray[i].Price.Value; } if (recArray[i].NeedsWalking.HasValue) { needsWalkingField.Value = recArray[i].NeedsWalking.Value; } if (recArray[i].Type != null) { typeField.Value = recArray[i].Type; } writer.Write(); } for (int i = 2; i < 3; i++) { if (recArray[i].PetName == null) { writer.SetNull(i); } else { writer.SetString(petNameFieldIndex, recArray[i].PetName); } if (!recArray[i].Age.HasValue) { writer.SetNull(i); } else { // test assigning to AsObject as Single Single ageAsSingle = (Single)recArray[i].Age.Value; writer[ageMetaField.Name] = ageAsSingle; Assert.AreEqual <Single>(ageAsSingle, (Single)ageField.Value); // test assigning to AsObject as Decimal Decimal ageAsDecimal = (Decimal)(recArray[i].Age.Value); writer[ageMetaField.Name] = ageAsDecimal; Assert.AreEqual <Decimal>(ageAsDecimal, (Decimal)ageField.Value); // assign as Double writer.SetDouble(ageFieldIndex, recArray[i].Age.Value); } if (recArray[i].Color == null) { writer.SetNull(i); } else { writer.SetString(colorFieldIndex, recArray[i].Color); } if (!recArray[i].DateReceived.HasValue) { writer.SetNull(i); } else { writer.SetDateTime(dateReceivedFieldIndex, recArray[i].DateReceived.Value); } if (!recArray[i].Price.HasValue) { writer.SetNull(i); } else { // test assigning to AsObject as Single Single priceAsSingle = (Single)(recArray[i].Price.Value); writer[priceField.Name] = priceAsSingle; Assert.AreEqual <Single>(priceAsSingle, (Single)priceField.Value); // test assigning to AsObject as Double Double priceAsDouble = (Double)(recArray[i].Price.Value); writer[priceField.Name] = priceAsDouble; Assert.AreEqual <Double>(priceAsDouble, (Double)priceField.Value); // assign as Decimal writer.SetDecimal(priceFieldIndex, recArray[i].Price.Value); } if (!recArray[i].NeedsWalking.HasValue) { writer.SetNull(i); } else { writer.SetBoolean(needsWalkingFieldIndex, recArray[i].NeedsWalking.Value); } if (recArray[i].Type == null) { writer.SetNull(i); } else { writer.SetString(typeFieldIndex, recArray[i].Type); } writer.Write(); } for (int i = 3; i < recArray.Length; i++) { if (recArray[i].PetName == null) { writer[petNameMetaField.Name] = null; } else { writer[petNameMetaField.Name] = recArray[i].PetName; } if (!recArray[i].Age.HasValue) { writer[ageMetaField.Name] = null; } else { // test assigning to AsObject as Single Single ageAsSingle = (Single)recArray[i].Age.Value; writer[ageMetaField.Name] = ageAsSingle; Assert.AreEqual <Single>(ageAsSingle, (Single)ageField.Value); // test assigning to AsObject as Decimal Decimal ageAsDecimal = (Decimal)(recArray[i].Age.Value); writer[ageMetaField.Name] = ageAsDecimal; Assert.AreEqual <Decimal>(ageAsDecimal, (Decimal)ageField.Value); // assign as Double writer[ageMetaField.Name] = recArray[i].Age.Value; } if (recArray[i].Color == null) { writer[colorMetaField.Name] = null; } else { writer[colorMetaField.Name] = recArray[i].Color; } if (!recArray[i].DateReceived.HasValue) { writer[dateReceivedMetaField.Name] = null; } else { writer[dateReceivedMetaField.Name] = recArray[i].DateReceived.Value; } if (!recArray[i].Price.HasValue) { writer[priceMetaField.Name] = null; } else { // test assigning to AsObject as Single Single priceAsSingle = (Single)(recArray[i].Price.Value); writer[priceField.Name] = priceAsSingle; Assert.AreEqual <Single>(priceAsSingle, (Single)priceField.Value); // test assigning to AsObject as Double Double priceAsDouble = (Double)(recArray[i].Price.Value); writer[priceField.Name] = priceAsDouble; Assert.AreEqual <Double>(priceAsDouble, (Double)priceField.Value); // assign as Decimal writer[priceMetaField.Name] = recArray[i].Price.Value; } if (!recArray[i].NeedsWalking.HasValue) { writer[needsWalkingMetaField.Name] = null; } else { writer[needsWalkingMetaField.Name] = recArray[i].NeedsWalking.Value; } if (recArray[i].Type == null) { writer[typeMetaField.Name] = null; } else { writer[typeMetaField.Name] = recArray[i].Type; } writer.Write(); } } } string DataFilePath = Path.Combine(DataFolder, BasicExampleFileName); if (!TextFilesAreEqual(filePath, DataFilePath)) { Assert.Fail("BasicExample does not match Test Data"); } else { using (FtReader ftReader = new FtReader()) { ftReader.Open(filePath); using (StreamReader strmReader = new StreamReader(filePath)) { Assert.AreEqual <bool>(true, ftReader.Declared); Assert.AreEqual <bool>(true, ftReader.HeaderRead); Assert.AreEqual <int>(headingArray.Length, ftReader.HeadingLineReadCount); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.Embedded, ftReader.MetaReferenceType); Assert.AreEqual <FtLineType>(FtLineType.Heading, ftReader.LineType); // last line in header FtStringField petNameField = ftReader.FieldList.Get(petNameMetaField.Name) as FtStringField; int petNameFieldIndex = ftReader.GetOrdinal(petNameMetaField.Name); FtFloatField ageField = ftReader.FieldList.Get(ageMetaField.Name) as FtFloatField; int ageFieldIndex = ftReader.GetOrdinal(ageMetaField.Name); FtStringField colorField = ftReader.FieldList.Get(colorMetaField.Name) as FtStringField; int colorFieldIndex = ftReader.GetOrdinal(colorMetaField.Name); FtDateTimeField dateReceivedField = ftReader.FieldList.Get(dateReceivedMetaField.Name) as FtDateTimeField; int dateReceivedFieldIndex = ftReader.GetOrdinal(dateReceivedMetaField.Name); FtDecimalField priceField = ftReader.FieldList.Get(priceMetaField.Name) as FtDecimalField; int priceFieldIndex = ftReader.GetOrdinal(priceMetaField.Name); FtBooleanField needsWalkingField = ftReader.FieldList.Get(needsWalkingMetaField.Name) as FtBooleanField; int needsWalkingFieldIndex = ftReader.GetOrdinal(needsWalkingMetaField.Name); FtStringField typeField = ftReader.FieldList.Get(typeMetaField.Name) as FtStringField; int typeFieldIndex = ftReader.GetOrdinal(typeMetaField.Name); // skip comment lines string strmLine; do { strmLine = strmReader.ReadLine(); }while (strmLine[0] == ftReader.LineCommentChar); for (int i = 0; i < headingArray.Length; i++) { strmLine = strmReader.ReadLine(); Assert.AreEqual <string>(headingArray[i].PetName, petNameField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Age, ageField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Color, colorField.Headings[i]); Assert.AreEqual <string>(headingArray[i].DateReceived, dateReceivedField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Price, priceField.Headings[i]); Assert.AreEqual <string>(headingArray[i].NeedsWalking, needsWalkingField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Type, typeField.Headings[i]); } for (int i = 0; i < recArray.Length; i++) { ftReader.Read(); Assert.AreEqual <string>(strmLine, ftReader.Line); Assert.AreEqual <int>(-1, ftReader.IgnoreExtraCharsLinePosition); Assert.AreEqual <int>(i + 1, ftReader.RecordCount); Assert.AreEqual <int>(1, ftReader.TableCount); if (recArray[i].PetName == null) { Assert.AreEqual <bool>(true, petNameField.IsNull()); } else { Assert.AreEqual <string>(recArray[i].PetName, petNameField.Value); Assert.AreEqual <object>(recArray[i].PetName, ftReader[petNameMetaField.Name]); Assert.AreEqual <object>(recArray[i].PetName, ftReader[petNameFieldIndex]); Assert.AreEqual <string>(recArray[i].PetName, ftReader.GetString(petNameFieldIndex)); } if (!recArray[i].Age.HasValue) { Assert.AreEqual <bool>(true, ageField.IsNull()); Assert.AreEqual <bool>(true, ftReader.IsDBNull(ageFieldIndex)); } else { Assert.AreEqual <double>(recArray[i].Age.Value, ageField.Value); Assert.AreEqual <object>(recArray[i].Age, ftReader[ageMetaField.Name]); Assert.AreEqual <object>(recArray[i].Age, ftReader[ageFieldIndex]); Assert.AreEqual <double>(recArray[i].Age.Value, ftReader.GetDouble(ageFieldIndex)); } if (recArray[i].Color == null) { Assert.AreEqual <bool>(true, colorField.IsNull()); } else { Assert.AreEqual <string>(recArray[i].Color, colorField.Value); Assert.AreEqual <object>(recArray[i].Color, ftReader[colorMetaField.Name]); Assert.AreEqual <object>(recArray[i].Color, ftReader[colorFieldIndex]); Assert.AreEqual <string>(recArray[i].Color, ftReader.GetString(colorFieldIndex)); } if (!recArray[i].DateReceived.HasValue) { Assert.AreEqual <bool>(true, dateReceivedField.IsNull()); } else { Assert.AreEqual <DateTime>(recArray[i].DateReceived.Value, dateReceivedField.Value); Assert.AreEqual <object>(recArray[i].DateReceived, ftReader[dateReceivedMetaField.Name]); Assert.AreEqual <object>(recArray[i].DateReceived, ftReader[dateReceivedFieldIndex]); Assert.AreEqual <DateTime>(recArray[i].DateReceived.Value, ftReader.GetDateTime(dateReceivedFieldIndex)); } if (!recArray[i].Price.HasValue) { Assert.AreEqual <bool>(true, priceField.IsNull()); } else { Assert.AreEqual <decimal>(recArray[i].Price.Value, priceField.Value); Assert.AreEqual <object>(recArray[i].Price, ftReader[priceMetaField.Name]); Assert.AreEqual <object>(recArray[i].Price, ftReader[priceFieldIndex]); Assert.AreEqual <decimal>(recArray[i].Price.Value, ftReader.GetDecimal(priceFieldIndex)); } if (!recArray[i].NeedsWalking.HasValue) { Assert.AreEqual <bool>(true, needsWalkingField.IsNull()); } else { Assert.AreEqual <bool>(recArray[i].NeedsWalking.Value, needsWalkingField.Value); Assert.AreEqual <object>(recArray[i].NeedsWalking, ftReader[needsWalkingMetaField.Name]); Assert.AreEqual <object>(recArray[i].NeedsWalking, ftReader[needsWalkingFieldIndex]); Assert.AreEqual <bool>(recArray[i].NeedsWalking.Value, ftReader.GetBoolean(needsWalkingFieldIndex)); } if (recArray[i].Type == null) { Assert.AreEqual <bool>(true, typeField.IsNull()); } else { Assert.AreEqual <string>(recArray[i].Type, typeField.Value); Assert.AreEqual <object>(recArray[i].Type, ftReader[typeMetaField.Name]); Assert.AreEqual <object>(recArray[i].Type, ftReader[typeFieldIndex]); Assert.AreEqual <string>(recArray[i].Type, ftReader.GetString(typeFieldIndex)); } strmLine = strmReader.ReadLine(); } Assert.AreEqual <bool>(false, ftReader.Read()); Assert.AreEqual <int>(recArray.Length, ftReader.RecordCount); } // repeat but read header separately ftReader.Open(filePath, false); Assert.AreEqual <int>(0, ftReader.HeadingLineReadCount); Assert.AreEqual <int>(0, ftReader.RecordCount); Assert.AreEqual <int>(0, ftReader.TableCount); Assert.AreEqual <bool>(true, ftReader.Declared); Assert.AreEqual <bool>(false, ftReader.HeaderRead); ftReader.ReadHeader(); Assert.AreEqual <bool>(true, ftReader.HeaderRead); Assert.AreEqual <int>(headingArray.Length, ftReader.HeadingLineReadCount); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.Embedded, ftReader.MetaReferenceType); Assert.AreEqual <FtLineType>(FtLineType.Heading, ftReader.LineType); // last line in header ftReader.SeekEnd(); Assert.AreEqual <int>(recArray.Length, ftReader.RecordCount); // repeat but reading each line individually ftReader.Open(filePath, false); Assert.AreEqual <bool>(false, ftReader.HeaderRead); Assert.AreEqual <int>(0, ftReader.HeadingLineReadCount); Assert.AreEqual <int>(0, ftReader.RecordCount); Assert.AreEqual <int>(0, ftReader.TableCount); ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Signature, ftReader.LineType); ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Declaration2, ftReader.LineType); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.Embedded, ftReader.MetaReferenceType); for (int i = 0; i < 10; i++) { ftReader.ReadLine(); if (i == 0) { Assert.AreEqual <FtLineType>(FtLineType.Comment, ftReader.LineType); } else { Assert.AreEqual <FtLineType>(FtLineType.EmbeddedMeta, ftReader.LineType); } } for (int i = 0; i < headingArray.Length; i++) { ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Heading, ftReader.LineType); } Assert.AreEqual <int>(headingArray.Length, ftReader.HeadingLineReadCount); Assert.AreEqual <bool>(true, ftReader.HeaderRead); for (int i = 0; i < recArray.Length; i++) { ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Record, ftReader.LineType); } Assert.AreEqual <bool>(false, ftReader.Read()); Assert.AreEqual <int>(recArray.Length, ftReader.RecordCount); Assert.AreEqual <int>(1, ftReader.TableCount); } } }
public void MetaVariations() { foreach (MetaVariation variation in metaVariationArray) { FtMeta meta = new FtMeta(); variation.Properties.LoadIntoMeta(ref meta); foreach (MetaFieldDefinition metaFieldDefinition in metaFieldDefinitionArray) { FtMetaField metaField = meta.FieldList.New(metaFieldDefinition.DataType); // metaField.Name = "Field" + idx++.ToString(); metaFieldDefinition.Properties.LoadIntoMetaField(ref metaField, true); switch (metaFieldDefinition.DataType) { case FtStandardDataType.Boolean: FtBooleanMetaField booleanMetaField = metaField as FtBooleanMetaField; booleanMetaField.Styles = BooleanMetaFieldStyles; booleanMetaField.FalseText = BooleanMetaFieldFalseText; booleanMetaField.TrueText = BooleanMetaFieldTrueText; break; case FtStandardDataType.String: FtStringMetaField stringMetaField = metaField as FtStringMetaField; stringMetaField.Value = StringMetaFieldValue; break; case FtStandardDataType.Float: FtFloatMetaField floatMetaField = metaField as FtFloatMetaField; floatMetaField.Format = FloatMetaFieldFormat; floatMetaField.Styles = FloatMetaFieldStyles; break; case FtStandardDataType.DateTime: FtDateTimeMetaField dateTimeMetaField = metaField as FtDateTimeMetaField; dateTimeMetaField.Format = DateTimeMetaFieldFormat; dateTimeMetaField.Styles = DateTimeMetaFieldStyles; dateTimeMetaField.Value = DateTimeMetaFieldValue; break; } } string filePath = Path.Combine(TestFolder, variation.FileName); XmlWriter writer = XmlWriter.Create(filePath, xmlWriterSettings); FtMetaSerializer.Serialize(meta, writer); writer.Close(); string DataFilePath = Path.Combine(DataFolder, variation.FileName); if (!TextFilesAreEqual(filePath, DataFilePath)) { Assert.Fail(variation.FileName + " does not match Test Data"); } else { FtMeta deserialisedMeta = FtMetaSerializer.Deserialize(filePath); variation.Properties.AssertMetaAreEqual(meta); Assert.AreEqual <int>(metaFieldDefinitionArray.Length, deserialisedMeta.FieldList.Count); for (int i = 0; i < deserialisedMeta.FieldList.Count; i++) { FtMetaField metaField = deserialisedMeta.FieldList[i]; metaFieldDefinitionArray[i].Properties.AssertMetaFieldAreEqual(metaField, true); switch (metaFieldDefinitionArray[i].DataType) { case FtStandardDataType.Boolean: FtBooleanMetaField booleanMetaField = metaField as FtBooleanMetaField; Assert.AreEqual <FtBooleanStyles>(BooleanMetaFieldStyles, booleanMetaField.Styles); Assert.AreEqual <string>(BooleanMetaFieldFalseText, booleanMetaField.FalseText); Assert.AreEqual <string>(BooleanMetaFieldTrueText, booleanMetaField.TrueText); break; case FtStandardDataType.String: FtStringMetaField stringMetaField = metaField as FtStringMetaField; Assert.AreEqual <string>(StringMetaFieldValue, stringMetaField.Value); break; case FtStandardDataType.Float: FtFloatMetaField floatMetaField = metaField as FtFloatMetaField; Assert.AreEqual <string>(FloatMetaFieldFormat, floatMetaField.Format); Assert.AreEqual <NumberStyles>(FloatMetaFieldStyles, floatMetaField.Styles); break; case FtStandardDataType.DateTime: FtDateTimeMetaField dateTimeMetaField = metaField as FtDateTimeMetaField; Assert.AreEqual <string>(DateTimeMetaFieldFormat, dateTimeMetaField.Format); Assert.AreEqual <DateTimeStyles>(DateTimeMetaFieldStyles, dateTimeMetaField.Styles); Assert.AreEqual <DateTime>(DateTimeMetaFieldValue, dateTimeMetaField.Value); break; } } } } }
public void AllDefaults() { // Creates Meta with one sequence with one field of each type // Sets Meta and fields and sequence redirects properties to default values // Saves to XML (Serialize) // Compares XML to Expected // Creates Meta from XML (Deserialize) // Checks properties are as originally set state = State.Initialise; // Create Meta and set default properties FtMeta meta = new FtMeta(); defaultMetaProperties.LoadIntoMeta(ref meta); FtStringMetaField stringField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; stringField.Name = StringFieldName; FtBooleanMetaField booleanField = meta.FieldList.New(FtStandardDataType.Boolean) as FtBooleanMetaField; booleanField.Name = BooleanFieldName; FtIntegerMetaField integerField = meta.FieldList.New(FtStandardDataType.Integer) as FtIntegerMetaField; integerField.Name = IntegerFieldName; FtFloatMetaField floatField = meta.FieldList.New(FtStandardDataType.Float) as FtFloatMetaField; floatField.Name = FloatFieldName; FtDecimalMetaField decimalField = meta.FieldList.New(FtStandardDataType.Decimal) as FtDecimalMetaField; decimalField.Name = DecimalFieldName; FtDateTimeMetaField dateTimeField = meta.FieldList.New(FtStandardDataType.DateTime) as FtDateTimeMetaField; dateTimeField.Name = DateTimeFieldName; FtStringMetaField redirectStringField1 = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; redirectStringField1.Name = RedirectStringField1Name; FtBooleanMetaField redirectBooleanField2 = meta.FieldList.New(FtStandardDataType.Boolean) as FtBooleanMetaField; redirectBooleanField2.Name = RedirectBooleanField2Name; FtIntegerMetaField redirectIntegerField3 = meta.FieldList.New(FtStandardDataType.Integer) as FtIntegerMetaField; redirectIntegerField3.Name = RedirectIntegerField3Name; FtFloatMetaField redirectFloatField4 = meta.FieldList.New(FtStandardDataType.Float) as FtFloatMetaField; redirectFloatField4.Name = RedirectFloatField4Name; FtDecimalMetaField redirectDecimalField5 = meta.FieldList.New(FtStandardDataType.Decimal) as FtDecimalMetaField; redirectDecimalField5.Name = RedirectDecimalField5Name; FtDateTimeMetaField redirectDateTimeField6 = meta.FieldList.New(FtStandardDataType.DateTime) as FtDateTimeMetaField; redirectDateTimeField6.Name = RedirectDateTimeField6Name; // Create root sequence FtMetaSequence rootSequence = meta.SequenceList.New(); rootSequence.Name = "Root"; rootSequence.Root = true; // Create redirect target sequence FtMetaSequence redirectTargetSequence = meta.SequenceList.New(); redirectTargetSequence.Name = "RedirectTarget"; FtMetaSequenceItem sequenceItem; FtMetaSequenceRedirect sequenceRedirect; sequenceItem = redirectTargetSequence.ItemList.New(); sequenceItem.Field = redirectStringField1; sequenceItem = redirectTargetSequence.ItemList.New(); sequenceItem.Field = redirectBooleanField2; sequenceRedirect = sequenceItem.RedirectList.New(FtStandardSequenceRedirectType.Null); sequenceRedirect.Sequence = rootSequence; sequenceItem = redirectTargetSequence.ItemList.New(); sequenceItem.Field = redirectIntegerField3; sequenceItem = redirectTargetSequence.ItemList.New(); sequenceItem.Field = redirectFloatField4; sequenceRedirect = sequenceItem.RedirectList.New(FtStandardSequenceRedirectType.Null); sequenceRedirect.Sequence = rootSequence; sequenceItem = redirectTargetSequence.ItemList.New(); sequenceItem.Field = redirectDecimalField5; sequenceItem = redirectTargetSequence.ItemList.New(); sequenceItem.Field = redirectDateTimeField6; // Create one field of each type and set properties to defaults and put in sequence. Add default redirect to sequence item redirect list AllDefaults_Field(stringField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactString, 0); AllDefaults_Field(booleanField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.Boolean, 1); booleanField.FalseText = BooleanFalseText; booleanField.TrueText = BooleanTrueText; booleanField.Styles = BooleanStyles; AllDefaults_Field(integerField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactInteger, 2); integerField.Format = IntegerFieldFormat; integerField.Styles = IntegerFieldStyles; AllDefaults_Field(floatField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactFloat, 3); floatField.Format = FloatFieldFormat; floatField.Styles = FloatFieldStyles; AllDefaults_Field(decimalField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactDecimal, 4); decimalField.Format = DecimalFieldFormat; decimalField.Styles = DecimalFieldStyles; AllDefaults_Field(dateTimeField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactDateTime, 5); dateTimeField.Format = DateTimeFieldFormat; dateTimeField.Styles = DateTimeFieldStyles; // Add one substitution of default substitution type FtMetaSubstitution substitution = meta.SubstitutionList.New(); substitution.Type = SubstitutionType; substitution.Token = SubstitutionToken; substitution.Value = SubstitutionValue; // Serialize Meta XmlWriter writer = XmlWriter.Create(filePath, xmlWriterSettings); FtMetaSerializer.Serialize(meta, writer); writer.Close(); state = State.Assert; string DataFilePath = Path.Combine(DataFolder, AllDefaultsFileName); if (!TextFilesAreEqual(filePath, DataFilePath)) { Assert.Fail("AllDefaults does not match Test Data"); } else { FtMeta deserialisedMeta = FtMetaSerializer.Deserialize(filePath); defaultMetaProperties.AssertMetaAreEqual(meta); rootSequence = meta.SequenceList[0]; Assert.AreEqual <bool>(true, rootSequence.Root); Assert.AreEqual <int>(6, rootSequence.ItemList.Count); redirectTargetSequence = meta.SequenceList[1]; Assert.AreEqual <bool>(false, redirectTargetSequence.Root); Assert.AreEqual <int>(6, redirectTargetSequence.ItemList.Count); stringField = meta.FieldList[0] as FtStringMetaField; Assert.AreEqual <string>(StringFieldName, stringField.Name); AllDefaults_Field(stringField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactString, 0); booleanField = meta.FieldList[1] as FtBooleanMetaField; Assert.AreEqual <string>(BooleanFieldName, booleanField.Name); AllDefaults_Field(booleanField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.Boolean, 1); Assert.AreEqual <string>(BooleanFalseText, booleanField.FalseText); Assert.AreEqual <string>(BooleanTrueText, booleanField.TrueText); Assert.AreEqual <FtBooleanStyles>(BooleanStyles, booleanField.Styles); integerField = meta.FieldList[2] as FtIntegerMetaField; Assert.AreEqual <string>(IntegerFieldName, integerField.Name); AllDefaults_Field(integerField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactInteger, 2); Assert.AreEqual <string>(IntegerFieldFormat, integerField.Format); Assert.AreEqual <NumberStyles>(IntegerFieldStyles, integerField.Styles); floatField = meta.FieldList[3] as FtFloatMetaField; Assert.AreEqual <string>(FloatFieldName, floatField.Name); AllDefaults_Field(floatField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactFloat, 3); Assert.AreEqual <string>(FloatFieldFormat, floatField.Format); Assert.AreEqual <NumberStyles>(FloatFieldStyles, floatField.Styles); decimalField = meta.FieldList[4] as FtDecimalMetaField; Assert.AreEqual <string>(DecimalFieldName, decimalField.Name); AllDefaults_Field(decimalField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactDecimal, 4); Assert.AreEqual <string>(DecimalFieldFormat, decimalField.Format); Assert.AreEqual <NumberStyles>(DecimalFieldStyles, decimalField.Styles); dateTimeField = meta.FieldList[5] as FtDateTimeMetaField; Assert.AreEqual <string>(DateTimeFieldName, dateTimeField.Name); AllDefaults_Field(dateTimeField, rootSequence, redirectTargetSequence, FtStandardSequenceRedirectType.ExactDateTime, 5); Assert.AreEqual <string>(DateTimeFieldFormat, dateTimeField.Format); Assert.AreEqual <DateTimeStyles>(DateTimeFieldStyles, dateTimeField.Styles); redirectStringField1 = meta.FieldList[6] as FtStringMetaField; Assert.AreEqual <string>(RedirectStringField1Name, redirectStringField1.Name); redirectBooleanField2 = meta.FieldList[7] as FtBooleanMetaField; Assert.AreEqual <string>(RedirectBooleanField2Name, redirectBooleanField2.Name); Assert.AreEqual <string>(BooleanFalseText, redirectBooleanField2.FalseText); Assert.AreEqual <string>(BooleanTrueText, redirectBooleanField2.TrueText); Assert.AreEqual <FtBooleanStyles>(BooleanStyles, redirectBooleanField2.Styles); redirectIntegerField3 = meta.FieldList[8] as FtIntegerMetaField; Assert.AreEqual <string>(RedirectIntegerField3Name, redirectIntegerField3.Name); Assert.AreEqual <string>(IntegerFieldFormat, redirectIntegerField3.Format); Assert.AreEqual <NumberStyles>(IntegerFieldStyles, redirectIntegerField3.Styles); redirectFloatField4 = meta.FieldList[9] as FtFloatMetaField; Assert.AreEqual <string>(RedirectFloatField4Name, redirectFloatField4.Name); Assert.AreEqual <string>(FloatFieldFormat, redirectFloatField4.Format); Assert.AreEqual <NumberStyles>(FloatFieldStyles, redirectFloatField4.Styles); redirectDecimalField5 = meta.FieldList[10] as FtDecimalMetaField; Assert.AreEqual <string>(RedirectDecimalField5Name, redirectDecimalField5.Name); Assert.AreEqual <string>(DecimalFieldFormat, redirectDecimalField5.Format); Assert.AreEqual <NumberStyles>(DecimalFieldStyles, redirectDecimalField5.Styles); redirectDateTimeField6 = meta.FieldList[11] as FtDateTimeMetaField; Assert.AreEqual <string>(RedirectDateTimeField6Name, redirectDateTimeField6.Name); Assert.AreEqual <string>(DateTimeFieldFormat, redirectDateTimeField6.Format); Assert.AreEqual <DateTimeStyles>(DateTimeFieldStyles, redirectDateTimeField6.Styles); Assert.AreEqual <FtMetaField>(redirectStringField1, redirectTargetSequence.ItemList[0].Field); Assert.AreEqual <int>(0, redirectTargetSequence.ItemList[0].RedirectList.Count); Assert.AreEqual <FtMetaField>(redirectBooleanField2, redirectTargetSequence.ItemList[1].Field); Assert.AreEqual <int>(1, redirectTargetSequence.ItemList[1].RedirectList.Count); Assert.AreEqual <int>(FtStandardSequenceRedirectType.Null, redirectTargetSequence.ItemList[1].RedirectList[0].Type); Assert.AreEqual <FtMetaField>(redirectIntegerField3, redirectTargetSequence.ItemList[2].Field); Assert.AreEqual <int>(0, redirectTargetSequence.ItemList[2].RedirectList.Count); Assert.AreEqual <FtMetaField>(redirectFloatField4, redirectTargetSequence.ItemList[3].Field); Assert.AreEqual <int>(1, redirectTargetSequence.ItemList[3].RedirectList.Count); Assert.AreEqual <int>(FtStandardSequenceRedirectType.Null, redirectTargetSequence.ItemList[3].RedirectList[0].Type); Assert.AreEqual <FtMetaField>(redirectDecimalField5, redirectTargetSequence.ItemList[4].Field); Assert.AreEqual <int>(0, redirectTargetSequence.ItemList[4].RedirectList.Count); Assert.AreEqual <FtMetaField>(redirectDateTimeField6, redirectTargetSequence.ItemList[5].Field); Assert.AreEqual <int>(0, redirectTargetSequence.ItemList[5].RedirectList.Count); } }