Ejemplo n.º 1
0
        /// <inheritdoc />
        public IEnumerable <IRelatedEntity> GetRelatedEntities(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(Enumerable.Empty <IRelatedEntity>());
            }

            var relatedEntities = new List <IRelatedEntity>();

            foreach (var documentUdi in ParserUtilities.GetDocumentUdiFromText(value).ToList())
            {
                relatedEntities.Add(new RelatedDocumentEntity
                {
                    RelatedEntityUdi = documentUdi
                });
            }

            foreach (var mediaUdi in ParserUtilities.GetMediaUdiFromText(value).ToList())
            {
                relatedEntities.Add(new RelatedMediaEntity()
                {
                    RelatedEntityUdi = mediaUdi
                });
            }

            return(relatedEntities);
        }
Ejemplo n.º 2
0
        public void ParseSingleLine_ParsesTestData()
        {
            // ASSERT:
            // Processor can parse individual line.

            Assert.IsNotNull(sourceBytes);
            Assert.IsTrue(sourceBytes.Any());

            processor = new EbcdicParser();

            int count    = 0;
            int position = 0;

            while (position < sourceBytes.Length)
            {
                byte[] lineBytes = ParserUtilities.ReadBytesRange(
                    sourceBytes,
                    length: lineTemplate.LineSize,
                    startPosition: position);

                position += lineTemplate.LineSize;

                var parsedLine = processor.ParseSingleLine(lineTemplate, lineBytes);

                if (count == 0)
                {
                    AssertDataForTheFirstRecord(parsedLine);
                }

                Debug.WriteLine(parsedLine.ToXmlString());
                count++;
            }

            Assert.IsTrue(count > 1);
        }
Ejemplo n.º 3
0
        internal virtual IReadOnlyList <Document> GetDocuments()
        {
            var list = new List <Document>();

            if (SearchStrings.All(IsInvalidSearchString))
            {
                return(list);
            }

            using var luceneDirectory       = FSDirectory.Open(LuceneIndexPath);
            using var luceneDirectoryReader = DirectoryReader.Open(luceneDirectory);
            var searcher = new IndexSearcher(luceneDirectoryReader);

            foreach (var searchString in SearchStrings)
            {
                if (IsInvalidSearchString(searchString))
                {
                    continue;
                }
                var preparedSearchTerm = PrepareSearchTerm(searchString);

                var query = ParserUtilities.ParseQuery(preparedSearchTerm, queryParser);
                var hits  = searcher.Search(query, Filter, ResultsLimit).ScoreDocs;
                list.AddRange(hits.Select(hit => searcher.Doc(hit.Doc)));
            }

            return(list);
        }
        public void GivenType_WhenGetPropertyNames_ThenReturnAllNames()
        {
            var parserUtilities = new ParserUtilities();
            var properties      = parserUtilities.GetPublicGetSetPropertyNames(typeof(SampleData));

            ArePropertiesEqual(properties[0], "Id", "Given Id", 1);
            ArePropertiesEqual(properties[1], "Name", "Name Property", 2);
            ArePropertiesEqual(properties[2], "Description", "Description Property", 12);
        }
Ejemplo n.º 5
0
        public void ParseSingleLine_ParsesTestData()
        {
            // ASSERT:
            // Processor can parse individual line.

            var sourceBytes  = TestData.GetSampleEbcidicDataWithFixedRecordLength();
            var lineTemplate = TestData.GetLineTemplateToParseEbcidicDataWithFixedRecordLength();

            Assert.IsNotNull(sourceBytes);
            Assert.IsTrue(sourceBytes.Any());

            var processor = new EbcdicParser();

            int count    = 0;
            int position = 0;

            while (position < sourceBytes.Length)
            {
                byte[] lineBytes = ParserUtilities.ReadBytesRange(
                    sourceBytes,
                    length: lineTemplate.LineSize,
                    startPosition: position);

                position += lineTemplate.LineSize;

                var parsedLine = processor.ParseSingleLine(lineTemplate, lineBytes);

                if (count == 0)
                {
                    Assert.IsTrue(parsedLine[TestData.FieldReservationNumber].Equals("04416365US2"));
                    Assert.IsTrue(parsedLine[TestData.FieldCheckInDate].Equals("2015-01-23"));
                    Assert.IsTrue(parsedLine[TestData.FieldCalcNetAmount].Equals("437.39"));
                    Assert.IsTrue(parsedLine[TestData.FieldCustomerName].Equals("KAY KENG,LOW"));
                    Assert.IsTrue(parsedLine[TestData.FieldRunDate].Equals("2015-01-28"));
                    Assert.IsTrue(parsedLine[TestData.FieldCurrencyConvRate].Equals("0.762728"));
                    Assert.IsTrue(parsedLine[TestData.FieldUsDollarAmountDue].Equals("220.26"));
                    Assert.IsTrue(parsedLine[TestData.FieldDateOfBirth].Equals("1972-08-09"));
                }

                Debug.WriteLine(parsedLine.ToXmlString());
                count++;
            }

            Assert.IsTrue(count > 1);
        }
Ejemplo n.º 6
0
        public void ParserUtilities_ReadBytesRange_ReturnsSlicedArray()
        {
            // ASSERT:
            // Method returns a slice of the input array

            var input = sourceBytes;

            byte[] result   = ParserUtilities.ReadBytesRange(input, startPosition: 2, length: 5);
            byte[] expected = { 2, 3, 4, 5, 6 };

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
            Assert.IsTrue(result.Length == expected.Length);

            for (int i = 0; i < result.Length; i++)
            {
                Assert.IsTrue(result[i] == expected[i]);
            }
        }
Ejemplo n.º 7
0
        public void Used_For_Manual_Testing()
        {
            var lineBytes    = ParserUtilities.ConvertHexStringToByteArray("F1-F5-F0-F1-F2-F3");
            var lineTemplate = new LineTemplate(lineBytes.Length);
            var fieldName    = "TEST_ITEM";

            lineTemplate.AddFieldTemplate(
                new FieldTemplate(
                    fieldName: fieldName,
                    fieldType: FieldType.DateString,
                    startPosition: 0,
                    fieldSize: lineBytes.Length,
                    decimalPlaces: 0));

            var processor = new EbcdicParser();

            var parsedLine = processor.ParseSingleLine(lineTemplate, lineBytes);

            var testOutput = parsedLine[fieldName];

            Debug.WriteLine(parsedLine.ToXmlString());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sample EBCDIC binary data.
        /// </summary>
        /// <returns></returns>
        public static byte[] GetSampleEbcidicDataWithFixedRecordLength()
        {
            var sb = new StringBuilder();

            //First record
            sb.Append("F0-F4-F4-F1-F6-F3-F6-F5-E4-E2-F2");                                                          //RESERVATION-NUMBER (Type="String"): 04416365US2
            sb.Append("F1-F5-F0-F1-F2-F3");                                                                         //CHECKIN-DATE (Type="DateString"): 2015-01-23
            sb.Append("00-00-AA-DB");                                                                               //CALC-NET-AMOUNT (Type="BinaryNum"): 437.39
            sb.Append("D2-C1-E8-40-D2-C5-D5-C7-6B-D3-D6-E6-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40"); //CUSTOMER-NAME (Type="String"): KAY KENG,LOW
            sb.Append("F0-F1-F2-F8-F1-F5");                                                                         //RUNDATE (Type="DateStringMMDDYY"): 2015-01-28
            sb.Append("00-00-07-62-72-8F");                                                                         //CURRENCY-CONV-RATE (Type="Packed"): 0.762728
            sb.Append("00-00-00-22-02-6C");                                                                         //US-DOLLAR-AMOUNT-DUE (Type="Packed"): 220.26
            sb.Append("07-20-80-9C");                                                                               //DATE-OF-BIRTH (Type="PackedDate"): 1972-08-09

            //Second record
            sb.Append("F0-F4-F4-F8-F2-F9-F3-F3-E2-C7-F0");                                                          //04482933SG0
            sb.Append("F1-F5-F0-F1-F2-F4");                                                                         //2015-01-24
            sb.Append("00-00-42-35");                                                                               //169.49
            sb.Append("C8-D6-6B-D9-D6-E8-E2-E3-D6-D5-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40-40"); //HO,ROYSTON
            sb.Append("F0-F1-F2-F8-F1-F5");                                                                         //2015-01-28
            sb.Append("00-00-07-62-72-8F");                                                                         //0.762728
            sb.Append("00-00-00-12-08-1C");                                                                         //120.81
            sb.Append("07-50-62-3C");                                                                               //1975-06-23

            //Third record
            sb.Append("F0-F4-F4-F2-F8-F3-F2-F6-E2-C7-F0");                                                          //04428326SG0
            sb.Append("F1-F5-F0-F1-F2-F6");                                                                         //2015-01-26
            sb.Append("00-00-D2-A8");                                                                               //539.28
            sb.Append("E5-C1-E9-C8-C1-D7-D7-C1-D3-D3-E8-6B-D4-C1-D5-E4-C5-D3-40-C6-D9-C1-D5-C3-C9-E2-40-40-40-40"); //VAZHAPPALLY,MANUEL FRANCIS
            sb.Append("F0-F1-F2-F8-F1-F5");                                                                         //2015-01-28
            sb.Append("00-00-07-62-72-8F");                                                                         //0.762728
            sb.Append("00-00-00-38-48-9C");                                                                         //384.89
            sb.Append("06-70-50-2C");                                                                               //1967-05-02

            byte[] ebcdicBytes = ParserUtilities.ConvertHexStringToByteArray(sb.ToString().Replace("-", ""));
            return(ebcdicBytes);
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        public IEnumerable <IRelatedEntity> GetRelatedEntities(string value)
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                var entities = new List <IRelatedEntity>();
                var model    = XDocument.Parse(value).Root;
                if (model != null)
                {
                    try
                    {
                        var socialImage = model.Descendants("socialImage").FirstOrDefault();
                        if (socialImage == null)
                        {
                            return(Enumerable.Empty <IRelatedEntity>());
                        }

                        if (string.IsNullOrEmpty(socialImage.Value))
                        {
                            return(Enumerable.Empty <IRelatedEntity>());
                        }

                        foreach (var documentUdi in ParserUtilities.GetMediaUdiFromText(socialImage.Value).ToList())
                        {
                            entities.Add(new RelatedMediaEntity
                            {
                                RelatedEntityUdi = documentUdi,
                            });
                        }

                        return(entities);
                    }
                    catch { }
                }
            }

            return(Enumerable.Empty <IRelatedEntity>());
        }
Ejemplo n.º 10
0
        public void ParserUtilities_ConvertHexStringToByteArray_ReturnsByteArray()
        {
            // ASSERT:
            // Method converts HEX string into byte array

            string[] inputs =
            {
                "01-42-CC-6A",
                "01 42 CC 6A",
                "0142CC6A",
                "0142cc6a"
            };
            byte[] expected = { 1, 66, 204, 106 };

            foreach (var input in inputs)
            {
                byte[] result = ParserUtilities.ConvertHexStringToByteArray(input);

                Assert.IsNotNull(result);
                Assert.IsTrue(result.Any());
                Assert.IsTrue(result.Length == expected.Length);
                Assert.IsTrue(expected.SequenceEqual(result));
            }
        }
Ejemplo n.º 11
0
 public void ParseTags_LessThanRequiredColumns_ThrowException()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.ParseTags("#CHROM\tPOS\tREF", "#CHROM", 4));
 }
Ejemplo n.º 12
0
 public void ParseGenomeAssembly_IncorrectFormat_ThrowException()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.ParseGenomeAssembly("#assembly-GRCh38", _allowedGenomeAssemblies));
 }
Ejemplo n.º 13
0
 public void ParseGenomeAssembly_UnsupportedAssembly_ThrowException()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.ParseGenomeAssembly("#assembly=hg19", _allowedGenomeAssemblies));
 }
Ejemplo n.º 14
0
 public void CheckPrefix_InvalidPrefix_ThrowException()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.CheckPrefix("invalidPrefix=someValue", "expectedPrefix"));
 }
Ejemplo n.º 15
0
 internal override string PrepareSearchTerm(string inputString)
 {
     return(ParserUtilities.PrepareSearchTerm(inputString));
 }
Ejemplo n.º 16
0
 public void ParseCategories_InvalidValue_ThrowException()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.ParseCategories("#categories\tWOW", 1, 1, null));
 }
Ejemplo n.º 17
0
        public void ParseTypes_InvalidType_ThrowException(string type)
        {
            string typeLine = $"#type\t.\t.\t.\t{type}";

            Assert.Throws <UserErrorException>(() => ParserUtilities.ParseTypes(typeLine, 4, 1));
        }
Ejemplo n.º 18
0
 public void ParseTitle_IncorrectFormat()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.ParseTitle("#title:customSA"));
 }
Ejemplo n.º 19
0
        public void ParseTypes_ValidType_Pass(string type)
        {
            string typeLine = $"#type\t.\t.\t.\t{type}";

            ParserUtilities.ParseTypes(typeLine, 4, 1);
        }
Ejemplo n.º 20
0
 public void ParseTitle_Conflict_JsonTag()
 {
     Assert.Throws <UserErrorException>(() => ParserUtilities.ParseTitle("#title=topmed"));
 }