public void Deserialize()
        {
            var inputXml = LoadInputXml10();

            var actual    = HelperXmlSerializer.Deserialize <InputDefinitionFile10>(inputXml);
            var outputXml = HelperXmlSerializer.Serialize(actual);

            TestContext.WriteLine(outputXml);

            Assert.AreEqual(inputXml, outputXml);
        }
Beispiel #2
0
        public void Deserialize()
        {
            var testDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var path          = Path.Combine(testDirectory, "TestFiles", "FXWDCSV.definition.20.xml");
            var inputXml      = File.ReadAllText(path);

            var actual    = HelperXmlSerializer.Deserialize <InputDefinitionFile20>(inputXml);
            var outputXml = HelperXmlSerializer.Serialize(actual);

            TestContext.WriteLine(outputXml);

            Assert.AreEqual(inputXml, outputXml);
        }
        public void Deserialize_Given_an_input_file_that_uses_default_values_Should_deserialise()
        {
            var inputXml = LoadInputXml10();
            var path     = Path.Combine(_testDirectory, "TestFiles", "FXWDCSV-default-values.definition.xml");
            var inputXmlWithDefaultValues = File.ReadAllText(path);

            var actual    = HelperXmlSerializer.Deserialize <InputDefinitionFile10>(inputXmlWithDefaultValues);
            var outputXml = HelperXmlSerializer.Serialize(actual);

            TestContext.WriteLine(outputXml);

            Assert.AreEqual(inputXml, outputXml);
        }
Beispiel #4
0
        public void Serialize()
        {
            var target = new InputDefinitionFile20
            {
                Name             = "TestFile",
                Description      = "Demo definition file with two data types",
                Version          = "1.0",
                FrameworkVersion = "2.0"
            };

            target.Header = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("FileType", "Record Type Header", "TextDecoder", "HD", ValidationResultType.Error),
                    CreateFieldDefinition("CreationDate", "Creation Date", "DateDecoder", "MMddyyyy", ValidationResultType.Error)
                }
            };

            var depositRow = new RowDefinition
            {
                DataType = "DP",
                Fields   = new FieldDefinition[]
                {
                    CreateFieldDefinition("RecordType", "Record Type Deposit", "TextDecoder", "DP", ValidationResultType.Error),
                    CreateFieldDefinition("ConsumerId", "Consumer Id", "TextDecoder", "[a-zA-Z0-9]{1,16}", ValidationResultType.Error),
                    CreateFieldDefinition("Date", "Date of deposit", "DateDecoder", "MMddyyyy", ValidationResultType.Error),
                    CreateFieldDefinition("Amount", "Amount", "DecimalDecoder", @"(?!0+)([0-9]{1,2},)?([0-9]{1,3},)?([0-9]{1,3},)?[0-9]{1,3}\.[0-9]{2}", ValidationResultType.Error)
                }
            };

            var changeRow = new RowDefinition
            {
                DataType = "CH",
                Fields   = new FieldDefinition[]
                {
                    CreateFieldDefinition("RecordType", "Record Type Change", "TextDecoder", "CH", ValidationResultType.Error),
                    CreateFieldDefinition("ConsumerId", "Consumer Id", "TextDecoder", "[a-zA-Z0-9]{1,16}", ValidationResultType.Error),
                    CreateFieldDefinition("Date", "Date of change", "DateDecoder", "MMddyyyy", ValidationResultType.Error),
                    CreateFieldDefinition("AddressLine1", "Street address", "TextDecoder", @"\s*(?:\S\s*){3,100}", ValidationResultType.Error),
                    CreateFieldDefinition("AddressLine2", "Apartment or suite", "TextDecoder", @"\s*(?:\S\s*){3,100}", ValidationResultType.Error)
                }
            };

            target.Datas = new Datas
            {
                KeyField       = "ConsumerId",
                DataTypeField  = "RecordType",
                MasterDataType = "DP",
                Rows           = new RowDefinition[] { depositRow, changeRow }
            };

            target.Trailer = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("RecordType", "Record Type Tariler", "TextDecoder", "TR", ValidationResultType.Error),
                    CreateFieldDefinition("DepositCount", "Record Count for Deposit", "IntegerDecoder", @"\d{1,5}", ValidationResultType.Error),
                    CreateFieldDefinition("ChangeCount", "Record Count for Change", "IntegerDecoder", @"\d{1,5}", ValidationResultType.Error),
                    CreateFieldDefinition("DepositTotal", "Total deposit amounts", "DecimalDecoder", @"(?!0+)([0-9]{1,2},)?([0-9]{1,3},)?([0-9]{1,3},)?[0-9]{1,3}\.[0-9]{2}", ValidationResultType.Error),
                }
            };

            var xml = HelperXmlSerializer.Serialize(target);

            TestContext.WriteLine(xml);
        }
        public void Serialize()
        {
            var sequenceNumberFieldDefinition = CreateFieldDefinition("SequenceNumber", "Sequence Number", "IntegerDecoder", "(?!0{4})[0-9]{4}", ValidationResultType.Error);

            var minNumberFieldRule = new RuleDefinition
            {
                Name                 = "SequenceNumber-MinNumberFieldRule",
                Description          = "Sequence number should be greater or equal to 10",
                Rule                 = "MinNumberFieldRule",
                FailValidationResult = ValidationResultType.Error
            };

            var maxNumberFieldRule = new RuleDefinition
            {
                Name        = "SequenceNumber-MaxNumberFieldRule",
                Description = "Sequence number should be equal or less than 100",
                Rule        = "MinNumberFieldRule",
                Args        = new ArgDefinition[] { new ArgDefinition {
                                                        Name = "ruleValue", Value = "100"
                                                    } },
                FailValidationResult = ValidationResultType.Error
            };

            sequenceNumberFieldDefinition.Rules = new RuleDefinition[] { minNumberFieldRule, maxNumberFieldRule };

            var originatorName = CreateFieldDefinition("OriginatorName", "Originator Name", "TextDecoder", @"[a-zA-Z\s-']{2,35}", ValidationResultType.Error);

            originatorName.Aggregators = new AggregatorDefinition[]
            {
                new AggregatorDefinition("BalanceAggregator", "Balance aggregator", "SumAggregator")
            };

            var target = new InputDefinitionFile10
            {
                Name             = "FXWDCSV",
                Description      = "Demo defining part of FXWDCSV",
                Version          = "1.0",
                FrameworkVersion = "1.0"
            };

            target.Header = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("FileType", "File Type", "TextDecoder", "PAYMENT", ValidationResultType.Error),
                    CreateFieldDefinition("RecordType", "Record Type", "TextDecoder", "HEADER", ValidationResultType.Error),
                    CreateFieldDefinition("CreationDate", "Creation Date", "DateDecoder", "MMddyyyy", ValidationResultType.Error),
                    CreateFieldDefinition("LocationID", "Location ID", "TextDecoder", "[a-zA-Z]{12}", ValidationResultType.Warning),
                    sequenceNumberFieldDefinition
                }
            };

            target.Data = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("RecordType", "Record Type", "TextDecoder", "PAYMENT", ValidationResultType.Error),
                    CreateFieldDefinition("PaymentType", "Payment Type", "TextDecoder", "(FXW|MBW)", ValidationResultType.Error),
                    CreateFieldDefinition("SendersReferenceNumber", "Senders Reference Number", "TextDecoder", "[a-zA-Z0-9]{1,16}", ValidationResultType.Error),
                    CreateFieldDefinition("RelatedReferenceNumber", "Related Reference Number", "TextDecoder", "[a-zA-Z0-9]{1,16}", ValidationResultType.Error),
                    CreateFieldDefinition("ValueDate", "Value Date", "DateDecoder", "MMddyyyy", ValidationResultType.Error),
                    CreateFieldDefinition("PaymentType", "Payment Type", "TextDecoder", "(DEBIT|CREDIT)", ValidationResultType.Error),
                    CreateFieldDefinition("Amount", "Amount", "DecimalDecoder", @"(?!0+)([0-9]{1,2},)?([0-9]{1,3},)?([0-9]{1,3},)?[0-9]{1,3}\.[0-9]{2}", ValidationResultType.Error),
                    CreateFieldDefinition("CreditCurrency", "Credit Currency", "TextDecoder", "[A-Z]{3}", ValidationResultType.Error),
                    originatorName
                }
            };

            target.Trailer = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("FileType", "File Type", "TextDecoder", "PAYMENT", ValidationResultType.Error),
                    CreateFieldDefinition("RecordType", "Record Type", "TextDecoder", "TRAILER", ValidationResultType.Error),
                    CreateFieldDefinition("HashTotal", "Hash Total", "DecimalDecoder", @"(?!0+)([0-9]{1,2},)?([0-9]{1,3},)?([0-9]{1,3},)?[0-9]{1,3}\.[0-9]{2}", ValidationResultType.Error),
                    CreateFieldDefinition("RecordCount", "Record Count", "IntegerDecoder", @"\d{1,5}", ValidationResultType.Error)
                }
            };

            var xml = HelperXmlSerializer.Serialize(target);

            TestContext.WriteLine(xml);
        }