Example #1
0
        public void TestWithMetaClass()
        {
            var kernel = new ContainerBuilder();
            var builder = kernel.UseDatenMeisterDotNet(new IntegrationSettings { PathToXmiFiles = "Xmi" });
            using (var scope = builder.BeginLifetimeScope())
            {
                var dataLayerLogic = scope.Resolve<IDataLayerLogic>();
                var dataLayers = scope.Resolve<DataLayers>();
                var umlDataLayer = dataLayers.Uml;
                var uml = dataLayerLogic.Get<_UML>(umlDataLayer);
                Assert.That(uml, Is.Not.Null);

                var extent = new XmlUriExtent("dm:///test");
                extent.Workspaces = scope.Resolve<IWorkspaceCollection>();
                dataLayerLogic.AssignToDataLayer(extent, dataLayers.Types);

                var factory = scope.Resolve<IFactoryMapper>().FindFactoryFor(scope, extent);

                var interfaceClass = uml.SimpleClassifiers.__Interface;
                var element = factory.create(interfaceClass);
                Assert.That(element, Is.Not.Null);

                extent.elements().add(element);
                Assert.That(extent.elements().size(), Is.EqualTo(1));

                var retrievedElement = extent.elements().ElementAt(0) as IElement;
                Assert.That(retrievedElement, Is.Not.Null);
                Assert.That(retrievedElement.getMetaClass(), Is.Not.Null);
                Assert.That(retrievedElement.metaclass, Is.Not.Null);
                var foundMetaClass = retrievedElement.metaclass;
                Assert.That(foundMetaClass.Equals(interfaceClass), Is.True);
            }
        }
Example #2
0
        public void TestXmlStorage()
        {
            var factory = new XmlFactory();
            var mofObject1 = factory.create(null);
            var mofObject2 = factory.create(null);
            var mofObject3 = factory.create(null);
            mofObject1.set("name", "Martin");
            mofObject2.set("name", "Martina");
            mofObject3.set("name", "Martini");

            var extent = new XmlUriExtent("dm:///test/");
            Assert.That(extent.contextURI(), Is.EqualTo("dm:///test/"));

            extent.elements().add(mofObject1);
            extent.elements().add(mofObject2);
            extent.elements().add(mofObject3);

            var xmiStorageConfiguration = new XmiStorageConfiguration
            {
                ExtentUri = "dm:///test/",
                Path = "data.xml"
            };

            var xmiStorage = new XmiStorage();
            xmiStorage.StoreExtent(extent, xmiStorageConfiguration);

            var otherExtent = xmiStorage.LoadExtent(xmiStorageConfiguration);
            Assert.That(otherExtent.elements().size(), Is.EqualTo(3));
            Assert.That(otherExtent.contextURI(), Is.EqualTo("dm:///test/"));
            Assert.That((otherExtent.elements().ElementAt(0) as IObject)?.get("name"), Is.EqualTo("Martin"));
            Assert.That((otherExtent.elements().ElementAt(1) as IObject)?.get("name"), Is.EqualTo("Martina"));
            Assert.That((otherExtent.elements().ElementAt(2) as IObject)?.get("name"), Is.EqualTo("Martini"));

            File.Delete("data.xml");
        }
Example #3
0
        public IUriExtent LoadExtent(ExtentStorageConfiguration configuration, bool createAlsoEmpty = false)
        {
            var xmiConfiguration = (XmiStorageConfiguration) configuration;

            XDocument xmlDocument;
            if (!File.Exists(xmiConfiguration.Path))
            {
                if (createAlsoEmpty)
                {
                    // We need to create an empty Xmi file... Not the best thing at the moment, but we try it.
                    xmlDocument = new XDocument(
                        new XElement(XmlUriExtent.DefaultRootNodeName));
                }
                else
                {
                    throw new InvalidOperationException(
                        $"File not found: {xmiConfiguration.Path}");
                }
            }
            else
            {
                xmlDocument = XDocument.Load(xmiConfiguration.Path);
            }

            var result = new XmlUriExtent(xmlDocument, xmiConfiguration.ExtentUri)
            {
                Workspaces = _workspaceCollection
            };

            return result;
        }
 public XmlReflectiveSequence(XmlUriExtent extent, XElement node)
 {
     _extent = extent;
     _node = node;
 }
Example #5
0
        public void TestXmlExtent()
        {
            var mofObject1 = new XmlElement(new XElement("item"));
            var mofObject2 = new XmlElement(new XElement("item"));
            var mofObject3 = new XmlElement(new XElement("item"));

            var extent = new XmlUriExtent("dm:///test/");
            Assert.That(extent.contextURI(), Is.EqualTo("dm:///test/"));

            // At the moment, it is not defined whether to contain or not contain. Just to increase coverage
            Assert.That(extent.useContainment(), Is.True.Or.False);

            Assert.That(extent.elements(), Is.Not.Null);
            Assert.That(extent.elements().size(), Is.EqualTo(0));

            extent.elements().add(mofObject1);
            extent.elements().add(mofObject2);
            Assert.That(extent.elements().size(), Is.EqualTo(2));

            mofObject1.set("name", "Martin");
            mofObject1.set("lastname", "Brenn");

            mofObject2.set("name", "Another");
            mofObject2.set("lastname", "Brenner");

            Assert.That(mofObject1.get("name").ToString(), Is.EqualTo("Martin"));
            Assert.That(mofObject2.get("name").ToString(), Is.EqualTo("Another"));

            var uri1 = extent.uri(mofObject1);
            var uri2 = extent.uri(mofObject2);
            var id1 = ((IHasId) mofObject1).Id.ToString();
            var id2 = ((IHasId) mofObject2).Id.ToString();

            Assert.That(id1, Is.Not.Null.Or.Empty);
            Assert.That(id2, Is.Not.Null.Or.Empty);
            Assert.That(id1 != id2, Is.True);

            Assert.That(uri1 != uri2, Is.True);
            Assert.That(uri1.StartsWith("dm:///test/"), Is.True);
            Assert.That(uri2.StartsWith("dm:///test/"), Is.True);

            Assert.That(uri1.EndsWith(id1), Is.True);
            Assert.That(uri2.EndsWith(id2), Is.True);

            var found = extent.element(uri1);
            Assert.That(found, Is.Not.Null);
            Assert.That(found, Is.EqualTo(mofObject1));

            var uri3 = "dm:///test/#abc";
            Assert.That(extent.element(uri3), Is.Null);

            var uri4 = "dm:///test/";
            Assert.That(extent.element(uri4), Is.Null);

            var uri5 = "#abc";
            Assert.That(extent.element(uri5), Is.Null);

            var uri6 = "dm:///anothertest/#" + id1;
            Assert.That(extent.element(uri6), Is.Null);

            extent.elements().remove(mofObject1);
            Assert.That(extent.elements().size(), Is.EqualTo(1));

            extent.elements().remove(mofObject3);
            Assert.That(extent.elements().size(), Is.EqualTo(1));

            var mofElement = new MofElement();
            Assert.Throws<ArgumentNullException>(() => extent.uri(mofElement));

            Assert.Throws<InvalidOperationException>(() => extent.elements().add(mofElement));
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the XmlElement class.
 /// </summary>
 /// <param name="node">Node to be used</param>
 /// <param name="extent">Extent to be set</param>
 public XmlElement(XElement node, XmlUriExtent extent)
     : this(node)
 {
     _owningExtent = extent;
 }