Ejemplo n.º 1
0
        internal static void ValidateFile(FileInfo _fileToRead)
        {
            IAddressSpaceContext _as = new AddressSpaceContext(z => Console.WriteLine(z.ToString()));

            _as.ImportUANodeSet(_fileToRead);
            _as.ValidateAndExportModel();
        }
        public void AddressSpaceContextImportUANodeSetNullTestMethod1()
        {
            IAddressSpaceContext _as = new AddressSpaceContext(x => { });
            UANodeSet            _ns = null;

            _as.ImportUANodeSet(_ns);
        }
        public void AddressSpaceContextImportUANodeSetNullTestMethod2()
        {
            IAddressSpaceContext _as = new AddressSpaceContext(x => { });
            FileInfo             _fi = null;

            _as.ImportUANodeSet(_fi);
        }
 public void AddressSpaceContextNotExistingFileNameTestMethod()
 {
     IAddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       FileInfo _fi = new FileInfo("NotExistingFileName.xml");
       _as.ImportUANodeSet(_fi);
 }
 public void AddressSpaceContextImportUANodeSetNullTestMethod2()
 {
     IAddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       FileInfo _fi = null;
       _as.ImportUANodeSet(_fi);
 }
 public void AddressSpaceContextImportUANodeSetNullTestMethod1()
 {
     IAddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       UANodeSet _ns = null;
       _as.ImportUANodeSet(_ns);
 }
        public void AddressSpaceContextNotExistingFileNameTestMethod()
        {
            IAddressSpaceContext _as = new AddressSpaceContext(x => { });
            FileInfo             _fi = new FileInfo("NotExistingFileName.xml");

            Assert.IsFalse(_fi.Exists);
            _as.ImportUANodeSet(_fi);
        }
Ejemplo n.º 8
0
        public void WrongFileNFormatTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"XMLModels\CorrectModels\ReferenceTest\ReferenceTest.NodeSet.xml"); //File not compliant with the schema.

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage>  _trace = new List <TraceMessage>();
            IAddressSpaceContext _as    = new AddressSpaceContext(z => TraceDiagnostic(z, _trace));

            Assert.IsNotNull(_as);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ImportUANodeSet(_testDataFileInfo);
        }
Ejemplo n.º 9
0
        //Helpers
        private static void ValidateAndExportModelPreparation(out UANodeSet _ns, out IAddressSpaceContext _as)
        {
            _ns = TestData.CreateNodeSetModel();
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;

            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.IsTrue(_ns.NamespaceUris.Length >= 1, "Wrong test data - NamespaceUris must contain more then 2 items");
            _as = new AddressSpaceContext(x => { Helpers.TraceHelper.TraceDiagnostic(x, _trace, ref _diagnosticCounter); });
            Assert.IsNotNull(_as);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ImportUANodeSet(_ns);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
        }
        public void WrongValueRankTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\WrongValueRank.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ValidateAndExportModel(m_NameSpace);
            Assert.AreEqual <int>(2, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
        }
        /// <summary>
        /// Creates new instance of the <see cref="ModelDesign.ModelDesign" />.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="traceEvent">The trace event.</param>
        /// <returns>An object of <see cref="ModelDesign.ModelDesign"/>.</returns>
        /// <exception cref="System.IO.FileNotFoundException">The imported file does not exist</exception>
        public static ModelDesign CreateInstance(FileInfo filePath, Action <TraceMessage> traceEvent)
        {
            if (!filePath.Exists)
            {
                throw new FileNotFoundException("The imported file does not exist", filePath.FullName);
            }
            traceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.CreateInstance"));
            IAddressSpaceContext _as      = new AddressSpaceContext(traceEvent);
            ModelFactory         _factory = new ModelFactory(traceEvent);

            _as.InformationModelFactory = _factory;
            _as.ImportUANodeSet(filePath);
            _as.ValidateAndExportModel();
            return(_factory.Export());
        }
        public void NotSupportedFeature()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\NotSupportedFeature.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ValidateAndExportModel(m_NameSpace);
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P0-0001010000").Count <TraceMessage>());
        }
        public void UndefinedHasComponentTargetTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasChildren.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ValidateAndExportModel(m_NameSpace);
            Assert.AreEqual <int>(2, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0707000002").Count <TraceMessage>());
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0708000000").Count <TraceMessage>());
        }
        private List <UANodeContext> ValidationUnitTest(FileInfo _testDataFileInfo, int nodes)
        {
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            List <UANodeContext> _nodes = ((AddressSpaceContext)_as).UTValidateAndExportModel(1);

            Assert.AreEqual <int>(nodes, ((AddressSpaceContext)_as).UTValidateAndExportModel(1).Count);
            _as.ValidateAndExportModel();
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            return(_nodes);
        }
        public void UndefinedHasTypeDefinitionTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasTypeDefinition.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ValidateAndExportModel(m_NameSpace);
            //TODO Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
            Assert.Inconclusive("Instances are not imported - the error is not recognized.");
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0713000000").Count <TraceMessage>());
        }
Ejemplo n.º 16
0
        private List <IUANodeContext> ValidateAndExportModelUnitTest(FileInfo testDataFileInfo, int numberOfNodes)
        {
            List <TraceMessage>  _trace = new List <TraceMessage>();
            IAddressSpaceContext _as    = new AddressSpaceContext(z => TraceDiagnostic(z, _trace));

            Assert.AreEqual <int>(0, _trace.Count);
            _as.ImportUANodeSet(testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Count);
            ((AddressSpaceContext)_as).UTAddressSpaceCheckConsistency(x => { Assert.Fail(); });
            ((AddressSpaceContext)_as).UTReferencesCheckConsistency((x, y, z, v) => Assert.Fail());
            IEnumerable <IUANodeContext> _nodes = null;

            ((AddressSpaceContext)_as).UTValidateAndExportModel(1, x => _nodes = x);
            Assert.AreEqual <int>(numberOfNodes, _nodes.Count <IUANodeContext>());
            _as.ValidateAndExportModel();
            Assert.AreEqual <int>(0, _trace.Count);
            return(_nodes.ToList <IUANodeContext>());
        }
Ejemplo n.º 17
0
        private static void Do(Options options)
        {
            PrintLogo(options);
            Action <TraceMessage> _tracingMethod = z => Console.WriteLine(z.ToString());
            IAddressSpaceContext  _as            = new AddressSpaceContext(_tracingMethod);
            ModelDesignExport     _exporter      = new ModelDesignExport();
            bool _exportModel = false;

            if (!string.IsNullOrEmpty(options.ModelDesignFileName))
            {
                _as.InformationModelFactory = _exporter.GetFactory(options.ModelDesignFileName, _tracingMethod);
                _exportModel = true;
            }
            if (options.Filenames == null)
            {
                throw new ArgumentOutOfRangeException($"{nameof(options.Filenames)}", "List of input files to convert i incorrect. At least one file UANodeSet must be entered.");
            }
            foreach (string _path in options.Filenames)
            {
                FileInfo _fileToRead = new FileInfo(_path);
                if (!_fileToRead.Exists)
                {
                    throw new FileNotFoundException(string.Format($"FileNotFoundException - the file {_path} doesn't exist.", _fileToRead.FullName));
                }
                _as.ImportUANodeSet(_fileToRead);
            }
            if (string.IsNullOrEmpty(options.IMNamespace))
            {
                _as.ValidateAndExportModel();
            }
            else
            {
                _as.ValidateAndExportModel(options.IMNamespace);
            }
            if (_exportModel)
            {
                _exporter.ExportToXMLFile(options.Stylesheet);
            }
        }
 //Helpers
 private static void ValidateAndExportModelPreparation(out UANodeSet _ns, out IAddressSpaceContext _as)
 {
     _ns = TestData.CreateNodeSetModel();
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       Assert.IsTrue(_ns.NamespaceUris.Length >= 1, "Wrong test data - NamespaceUris must contain more then 2 items");
       _as = new AddressSpaceContext(x => { Helpers.TraceHelper.TraceDiagnostic(x, _trace, ref _diagnosticCounter); });
       Assert.IsNotNull(_as);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ImportUANodeSet(_ns);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
 }