From 8bc36eaadde1da162e6d1f4a572a033970f52376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sam=20Geren=C3=A9?= Date: Sat, 28 Feb 2026 18:22:40 +0100 Subject: [PATCH] Add model element tests to increase core coverage --- .../OperationAndFactoryTestFixture.cs | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 ECoreNetto.Tests/ModelElement/OperationAndFactoryTestFixture.cs diff --git a/ECoreNetto.Tests/ModelElement/OperationAndFactoryTestFixture.cs b/ECoreNetto.Tests/ModelElement/OperationAndFactoryTestFixture.cs new file mode 100644 index 0000000..892374d --- /dev/null +++ b/ECoreNetto.Tests/ModelElement/OperationAndFactoryTestFixture.cs @@ -0,0 +1,145 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2017-2025 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace ECoreNetto.Tests.ModelElement +{ + using System; + using System.Xml; + + using ECoreNetto.Resource; + + using NUnit.Framework; + + [TestFixture] + public class OperationAndFactoryTestFixture + { + [Test] + public void Verify_that_diagnostic_properties_are_set_by_constructor() + { + var diagnostic = new Diagnostic(8, 12, "test-location", "test message"); + + Assert.Multiple(() => + { + Assert.That(diagnostic.Column, Is.EqualTo(8)); + Assert.That(diagnostic.Line, Is.EqualTo(12)); + Assert.That(diagnostic.Location, Is.EqualTo("test-location")); + Assert.That(diagnostic.Message, Is.EqualTo("test message")); + }); + } + + [Test] + public void Verify_that_efactory_can_be_constructed() + { + var resource = new Resource(); + + var eFactory = new EFactory(resource); + + Assert.Multiple(() => + { + Assert.That(eFactory.EResource, Is.EqualTo(resource)); + Assert.That(eFactory.EPackage, Is.Null); + }); + } + + [Test] + public void Verify_that_eoperation_DeserializeChildNode_throws_for_null_reader() + { + var resource = new Resource(); + var operation = new TestableEOperation(resource); + + Assert.That(() => operation.ExposeDeserializeChildNode(null), Throws.ArgumentNullException); + } + + [Test] + public void Verify_that_eoperation_DeserializeChildNode_adds_parameter() + { + var resource = new Resource(); + var package = new EPackage(resource) + { + Name = "Pkg" + }; + + var eClass = new EClass(resource) + { + Name = "SampleClass" + }; + + package.EClassifiers.Add(eClass); + + var operation = new TestableEOperation(resource) + { + Name = "DoWork" + }; + + eClass.EOperations.Add(operation); + + var xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(""); + + operation.ExposeDeserializeChildNode(xmlDocument.DocumentElement); + + Assert.Multiple(() => + { + Assert.That(operation.EParameters.Count, Is.EqualTo(1)); + Assert.That(operation.EParameters[0].Name, Is.EqualTo("parameterOne")); + Assert.That(operation.EParameters[0].EOperation, Is.SameAs(operation)); + }); + } + + [Test] + public void Verify_that_eoperation_identifier_contains_containing_class_identifier_and_name() + { + var resource = new Resource(); + var package = new EPackage(resource) + { + Name = "Pkg" + }; + + var eClass = new EClass(resource) + { + Name = "SampleClass" + }; + + package.EClassifiers.Add(eClass); + + var operation = new TestableEOperation(resource) + { + Name = "DoWork" + }; + + eClass.EOperations.Add(operation); + + Assert.That(operation.Identifier, Is.EqualTo($"EOperation::{eClass.Identifier}/DoWork")); + } + + private class TestableEOperation : EOperation + { + public TestableEOperation(Resource resource) + : base(resource) + { + } + + public void ExposeDeserializeChildNode(XmlNode node) + { + this.DeserializeChildNode(node); + } + } + } +}