Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 26 additions & 5 deletions SysML2.NET.Tests/Extend/BooleanExpressionExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="BooleanExpressionExtensionsTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2022-2026 Starion Group S.A.
// Copyright (C) 2022-2026 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.
Expand All @@ -21,18 +21,39 @@
namespace SysML2.NET.Tests.Extend
{
using System;

using NUnit.Framework;

using SysML2.NET.Core.POCO.Kernel.Functions ;
using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Kernel.Functions;
using SysML2.NET.Extensions;

[TestFixture]
public class BooleanExpressionExtensionsTestFixture
{
[Test]
public void ComputePredicate_ThrowsNotSupportedException()
public void VerifyComputePredicate()
{
Assert.That(() => ((IBooleanExpression)null).ComputePredicate(), Throws.TypeOf<NotSupportedException>());
// Null subject:
Assert.That(() => ((IBooleanExpression)null).ComputePredicate(), Throws.TypeOf<ArgumentNullException>());

// Empty BooleanExpression:
var emptyBooleanExpression = new BooleanExpression();
Assert.That(emptyBooleanExpression.ComputePredicate(), Is.Null);

// Typed by Function, but not Predicate (predicate is a specialization of function):
var nonPredicateBooleanExpression = new BooleanExpression();
var function = new Function();
var functionTyping = new FeatureTyping { Type = function };
nonPredicateBooleanExpression.AssignOwnership(functionTyping);
Assert.That(nonPredicateBooleanExpression.ComputePredicate(), Is.Null);

// Typed by Predicate:
var predicateBooleanExpression = new BooleanExpression();
var predicate = new Predicate();
var predicateTyping = new FeatureTyping { Type = predicate };
predicateBooleanExpression.AssignOwnership(predicateTyping);
Assert.That(predicateBooleanExpression.ComputePredicate(), Is.SameAs(predicate));
}
}
}
43 changes: 18 additions & 25 deletions SysML2.NET/Extend/BooleanExpressionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,50 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="BooleanExpressionExtensions.cs" company="Starion Group S.A.">
//
// Copyright (C) 2022-2026 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
//
//
// Copyright (C) 2022-2026 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 SysML2.NET.Core.POCO.Kernel.Functions
{
using System;
using System.Collections.Generic;

using SysML2.NET.Core.Core.Types;
using SysML2.NET.Core.Root.Namespaces;
using SysML2.NET.Core.POCO.Core.Features;
using SysML2.NET.Core.POCO.Core.Types;
using SysML2.NET.Core.POCO.Kernel.Behaviors;
using SysML2.NET.Core.POCO.Root.Annotations;
using SysML2.NET.Core.POCO.Root.Elements;
using SysML2.NET.Core.POCO.Root.Namespaces;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

/// <summary>
/// The <see cref="BooleanExpressionExtensions"/> class provides extensions methods for
/// the <see cref="IBooleanExpression"/> interface
/// The <see cref="BooleanExpressionExtensions" /> class provides extensions methods for
/// the <see cref="IBooleanExpression" /> interface
/// </summary>
internal static class BooleanExpressionExtensions
{
/// <summary>
/// Computes the derived property.
/// </summary>
/// <param name="booleanExpressionSubject">
/// The subject <see cref="IBooleanExpression"/>
/// The subject <see cref="IBooleanExpression" />
/// </param>
/// <returns>
/// the computed result
/// </returns>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[ExcludeFromCodeCoverage]
internal static IPredicate ComputePredicate(this IBooleanExpression booleanExpressionSubject)
{
throw new NotSupportedException("Create a GitHub issue when this method is required");
return booleanExpressionSubject == null
? throw new ArgumentNullException(nameof(booleanExpressionSubject))
: booleanExpressionSubject.type.OfType<IPredicate>().FirstOrDefault();
}

}
}
Loading