Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BooleanValueSetComparerAdditionalTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2025 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
//
// This file is part of COMET-SDK Community Edition
//
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.NetCore.Tests.Comparers
{
using CDP4Common.Comparers;
using CDP4Common.Types;
using NUnit.Framework;

/// <summary>
/// Additional coverage tests for <see cref="BooleanValueSetComparer"/>.
/// </summary>
[TestFixture]
public class BooleanValueSetComparerAdditionalTestFixture
{
[Test]
public void VerifyThatStringComparisonIsUsedWhenConversionFails()
{
var left = new ValueArray<string>(new[] { "maybe" });
var right = new ValueArray<string>(new[] { "certain" });
var comparer = new BooleanValueSetComparer();

var result = comparer.Compare(left, right);

var expected = string.CompareOrdinal(left.ToString().ToLower(), right.ToString().ToLower());
Assert.That(result, Is.EqualTo(expected));
}

[Test]
public void VerifyThatFailedConversionResetsBooleanList()
{
var comparer = new BooleanValueSetComparer();
var valueArray = new ValueArray<string>(new[] { "true", "value", "false" });

var success = comparer.TryConvertStringValueArrayToBooleanList(valueArray, out var booleanList);

Assert.Multiple(() =>
{
Assert.That(success, Is.False);
Assert.That(booleanList, Is.Empty);
});
}
}
}
70 changes: 70 additions & 0 deletions CDP4Common.NetCore.Tests/Extensions/GuidExtensionsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GuidExtensionsTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2025 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
//
// This file is part of COMET-SDK Community Edition
//
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.NetCore.Tests.Extensions
{
using System;
using System.Collections.Generic;
using System.Linq;
using CDP4Common.Extensions;
using NUnit.Framework;

/// <summary>
/// Tests for <see cref="GuidExtensions"/>.
/// </summary>
[TestFixture]
public class GuidExtensionsTestFixture
{
[Test]
public void VerifyShortGuidRoundTrip()
{
var guid = Guid.NewGuid();

var shortGuid = guid.ToShortGuid();
var roundTrip = shortGuid.FromShortGuid();

Assert.Multiple(() =>
{
Assert.That(shortGuid, Has.Length.EqualTo(22));
Assert.That(shortGuid, Does.Not.Contain("/").And.Not.Contain("+"));
Assert.That(roundTrip, Is.EqualTo(guid));
});
}

[Test]
public void VerifyShortGuidArrayRoundTrip()
{
var guids = new List<Guid> { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };

var shortGuidArray = guids.ToShortGuidArray();
var roundTrip = shortGuidArray.FromShortGuidArray().ToList();

Assert.Multiple(() =>
{
Assert.That(shortGuidArray.StartsWith("[") && shortGuidArray.EndsWith("]"), Is.True);
Assert.That(roundTrip, Is.EqualTo(guids));
});
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterValueValidatorTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2025 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
//
// This file is part of COMET-SDK Community Edition
//
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.NetCore.Tests.Helpers
{
using CDP4Common.Helpers;
using CDP4Common.SiteDirectoryData;
using NUnit.Framework;

/// <summary>
/// Tests for <see cref="ParameterValueValidator"/>.
/// </summary>
[TestFixture]
public class ParameterValueValidatorTestFixture
{
[Test]
public void VerifyThatNullParameterTypeReturnsError()
{
var error = ParameterValueValidator.Validate("value", null);

Assert.That(error, Is.EqualTo("Error: The parameter type is null."));
}

[Test]
public void VerifyThatValidBooleanValueReturnsNull()
{
var parameterType = new BooleanParameterType();

var error = ParameterValueValidator.Validate(true, parameterType);

Assert.That(error, Is.Null);
}

[Test]
public void VerifyThatInvalidBooleanValueReturnsValidationMessage()
{
var parameterType = new BooleanParameterType();

var error = ParameterValueValidator.Validate("not-a-boolean", parameterType);

Assert.That(error, Does.Contain("not-a-boolean"));
}
}
}
67 changes: 67 additions & 0 deletions CDP4Dal.NetCore.Tests/DAL/AuthenticationInformationTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AuthenticationInformationTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2025 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
//
// This file is part of COMET-SDK Community Edition
//
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Dal.NetCore.Tests.DAL
{
using CDP4Dal.DAL;
using CDP4DalCommon.Authentication;
using NUnit.Framework;

/// <summary>
/// Tests for <see cref="AuthenticationInformation"/>.
/// </summary>
[TestFixture]
public class AuthenticationInformationTestFixture
{
[Test]
public void VerifyConstructorWithUserNameAndPassword()
{
const string expectedUserName = "user";
const string expectedPassword = "pass";

var information = new AuthenticationInformation(expectedUserName, expectedPassword);

Assert.Multiple(() =>
{
Assert.That(information.UserName, Is.EqualTo(expectedUserName));
Assert.That(information.Password, Is.EqualTo(expectedPassword));
Assert.That(information.Token, Is.Null);
});
}

[Test]
public void VerifyConstructorWithAuthenticationToken()
{
var expectedToken = new AuthenticationToken("access", "refresh");

var information = new AuthenticationInformation(expectedToken);

Assert.Multiple(() =>
{
Assert.That(information.Token, Is.SameAs(expectedToken));
Assert.That(information.UserName, Is.Null);
Assert.That(information.Password, Is.Null);
});
}
}
}
76 changes: 76 additions & 0 deletions CDP4Dal.NetCore.Tests/DAL/AvailableDalsTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AvailableDalsTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2025 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
//
// This file is part of COMET-SDK Community Edition
//
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Dal.NetCore.Tests.DAL
{
using System;
using System.Collections.Generic;
using CDP4Dal;
using CDP4Dal.Composition;
using CDP4Dal.DAL;
using Moq;
using NUnit.Framework;

/// <summary>
/// Tests for <see cref="AvailableDals"/>.
/// </summary>
[TestFixture]
public class AvailableDalsTestFixture
{
[Test]
public void VerifyThatConstructorCopiesProvidedDalKinds()
{
var firstDal = new Lazy<IDal, IDalMetaData>(() => Mock.Of<IDal>(), new TestDalMetaData("first"));
var secondDal = new Lazy<IDal, IDalMetaData>(() => Mock.Of<IDal>(), new TestDalMetaData("second"));
var provided = new List<Lazy<IDal, IDalMetaData>> { firstDal, secondDal };

var availableDals = new AvailableDals(provided);

Assert.Multiple(() =>
{
Assert.That(availableDals.DataAccessLayerKinds, Is.Not.SameAs(provided));
Assert.That(availableDals.DataAccessLayerKinds, Is.EquivalentTo(provided));
});

provided.Add(new Lazy<IDal, IDalMetaData>(() => Mock.Of<IDal>(), new TestDalMetaData("third")));

Assert.That(availableDals.DataAccessLayerKinds, Has.Count.EqualTo(2));
}

private sealed class TestDalMetaData : IDalMetaData
{
public TestDalMetaData(string name)
{
this.Name = name;
}

public DalType DalType => DalType.Web;

public string CDPVersion => "1";

public string Name { get; }

public string Description => this.Name;
}
}
}
Loading
Loading