public void Parse_ShouldReturnCimEntities_OnValidXElementInput() { var expectedPowerTransformer = TestDataHelper.LoadTestData <CimEntity>("TestData/power-transformer.json"); var expectedPowerTransformerEnd = TestDataHelper.LoadTestData <CimEntity>("TestData/power-transformer-end.json"); var xmlFilePath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); var xmiExtractorLogger = A.Fake <ILogger <XmiExtractor> >(); var cimParserLogger = A.Fake <ILogger <CimParser> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var reader = new StreamReader(xmlFilePath, encoding, true); A.CallTo(() => xmlTextReaderFactory.Create(xmlFilePath, encoding)).Returns(new XmlTextReader(reader)); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, xmiExtractorLogger); var cimParser = new Parser.Cim.CimParser(xmiExtractor, cimParserLogger); var cimEntities = cimParser.Parse(xmlFilePath, encoding); var actualPowerTransformer = cimEntities.FirstOrDefault(x => x.XmiId == expectedPowerTransformer.XmiId); var actualPowerTransformerEnd = cimEntities.FirstOrDefault(x => x.XmiId == expectedPowerTransformerEnd.XmiId); actualPowerTransformer.Should().BeEquivalentTo(expectedPowerTransformer); actualPowerTransformerEnd.Should().BeEquivalentTo(expectedPowerTransformerEnd); }
public void GetGeneralizations_ShouldReturnXElementOfTypeClasses_OnValidXElement(string subType, string superType) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var xmlPath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var logger = A.Fake <ILogger <XmiExtractor> >(); var reader = new StreamReader(xmlPath, encoding, true); var xmlTextReader = new XmlTextReader(reader); var xElement = XElement.Load(xmlTextReader); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, logger); var classes = xmiExtractor.GetGeneralizations(xElement); xElement.Should().NotBeNull(); xElement.Should().BeOfType <XElement>(); xElement.Descendants().Count().Should().BeGreaterThan(0); xElement.Descendants() .FirstOrDefault(x => x.Attribute("subtype")?.Value?.ToString() == subType && x.Attribute("supertype")?.Value?.ToString() == superType) .Should() .NotBeNull(); }
public void GetXElementClasses_ShouldThrowNullArgumentException_OnNullXElement() { XElement xElement = null; var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var logger = A.Fake <ILogger <XmiExtractor> >(); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, logger); xmiExtractor.Invoking(x => x.GetXElementClasses(xElement)).Should().Throw <ArgumentNullException>(); }
public void LoadXElement_ShouldThrowArgumentException_OnNullOrEmptyXmlPath() { var encoding = Encoding.GetEncoding("windows-1252"); var logger = A.Fake <ILogger <XmiExtractor> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, logger); xmiExtractor.Invoking(x => x.LoadXElement(null, encoding)).Should().Throw <ArgumentException>(); xmiExtractor.Invoking(x => x.LoadXElement("", encoding)).Should().Throw <ArgumentException>(); }
public void LoadXElement_ShouldReturnXElement_OnValidPath() { var xmlPath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); var logger = A.Fake <ILogger <XmiExtractor> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var reader = new StreamReader(xmlPath, encoding, true); A.CallTo(() => xmlTextReaderFactory.Create(xmlPath, encoding)).Returns(new XmlTextReader(reader)); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, logger); var xElement = xmiExtractor.LoadXElement(xmlPath, encoding); xElement.Should().NotBeNull(); xElement.Should().BeOfType <XElement>(); xElement.Descendants().Count().Should().BeGreaterThan(0); }
public void GetXElementClasses_ShouldReturnXElementsOfTypeClasses_OnValidXElement(string className) { var xmlPath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); var logger = A.Fake <ILogger <XmiExtractor> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var reader = new StreamReader(xmlPath, encoding, true); var xmlTextReader = new XmlTextReader(reader); var xElement = XElement.Load(xmlTextReader); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, logger); var classes = xmiExtractor.GetXElementClasses(xElement); xElement.Should().NotBeNull(); xElement.Should().BeOfType <XElement>(); xElement.Descendants().Count().Should().BeGreaterThan(0); xElement.Descendants().FirstOrDefault(x => x.Attribute("name")?.Value?.ToString() == className).Should().NotBeNull(); }
public void Parse_ShouldHaveExtactCimEntityCount_OnValidXElementInput() { var expectedEntityCount = 1929; var xmlFilePath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); var xmiExtractorLogger = A.Fake <ILogger <XmiExtractor> >(); var cimParserLogger = A.Fake <ILogger <CimParser> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var reader = new StreamReader(xmlFilePath, encoding, true); A.CallTo(() => xmlTextReaderFactory.Create(xmlFilePath, encoding)).Returns(new XmlTextReader(reader)); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, xmiExtractorLogger); var cimParser = new Parser.Cim.CimParser(xmiExtractor, cimParserLogger); var cimEntities = cimParser.Parse(xmlFilePath, encoding); cimEntities.Count().Should().Be(expectedEntityCount); }
public void Parse_ShouldReturnMagneticFieldWithStereoTypeFilled_OnValidXElementInput() { var xmlFilePath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var xmiExtractorLogger = A.Fake <ILogger <XmiExtractor> >(); var cimParserLogger = A.Fake <ILogger <CimParser> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var reader = new StreamReader(xmlFilePath, encoding, true); A.CallTo(() => xmlTextReaderFactory.Create(xmlFilePath, encoding)).Returns(new XmlTextReader(reader)); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, xmiExtractorLogger); var cimParser = new Parser.Cim.CimParser(xmiExtractor, cimParserLogger); var cimEntities = cimParser.Parse(xmlFilePath, encoding); cimEntities.FirstOrDefault(x => x.Name == "MagneticField").StereoType.Should().Be("CIMDatatype"); }
public void Parse_ShouldHaveExtractTotalAttributeCount_OnValidXElementInput() { var xmlFilePath = "TestData/cim.xml"; var encoding = Encoding.GetEncoding("windows-1252"); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var xmiExtractorLogger = A.Fake <ILogger <XmiExtractor> >(); var cimParserLogger = A.Fake <ILogger <CimParser> >(); var xmlTextReaderFactory = A.Fake <IXmlTextReaderFactory>(); var reader = new StreamReader(xmlFilePath, encoding, true); A.CallTo(() => xmlTextReaderFactory.Create(xmlFilePath, encoding)).Returns(new XmlTextReader(reader)); var xmiExtractor = new XmiExtractor(xmlTextReaderFactory, xmiExtractorLogger); var cimParser = new Parser.Cim.CimParser(xmiExtractor, cimParserLogger); var cimEntities = cimParser.Parse(xmlFilePath, encoding); var count = 0; cimEntities.ToList().ForEach(x => { count += x.Attributes.Count(); }); count.Should().Be(9365); }