Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions ECoreNetto.Tests/ModelElement/OperationAndFactoryTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="OperationAndFactoryTestFixture.cs" company="Starion Group S.A.">
//
// 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.
//
// </copyright>
// ------------------------------------------------------------------------------------------------

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("<eParameters name=\"parameterOne\" />");

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);
}
}
}
}
Loading