Skip to content

Commit 85fe437

Browse files
Add unit tests covering authentication and reporting utilities
1 parent 16c8d3e commit 85fe437

File tree

11 files changed

+886
-0
lines changed

11 files changed

+886
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="BooleanValueSetComparerAdditionalTestFixture.cs" company="Starion Group S.A.">
3+
// Copyright (c) 2015-2025 Starion Group S.A.
4+
//
5+
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
6+
//
7+
// This file is part of COMET-SDK Community Edition
8+
//
9+
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// --------------------------------------------------------------------------------------------------------------------
23+
24+
namespace CDP4Common.NetCore.Tests.Comparers
25+
{
26+
using CDP4Common.Comparers;
27+
using CDP4Common.Types;
28+
using NUnit.Framework;
29+
30+
/// <summary>
31+
/// Additional coverage tests for <see cref="BooleanValueSetComparer"/>.
32+
/// </summary>
33+
[TestFixture]
34+
public class BooleanValueSetComparerAdditionalTestFixture
35+
{
36+
[Test]
37+
public void VerifyThatStringComparisonIsUsedWhenConversionFails()
38+
{
39+
var left = new ValueArray<string>(new[] { "maybe" });
40+
var right = new ValueArray<string>(new[] { "certain" });
41+
var comparer = new BooleanValueSetComparer();
42+
43+
var result = comparer.Compare(left, right);
44+
45+
var expected = string.CompareOrdinal(left.ToString().ToLower(), right.ToString().ToLower());
46+
Assert.That(result, Is.EqualTo(expected));
47+
}
48+
49+
[Test]
50+
public void VerifyThatFailedConversionResetsBooleanList()
51+
{
52+
var comparer = new BooleanValueSetComparer();
53+
var valueArray = new ValueArray<string>(new[] { "true", "value", "false" });
54+
55+
var success = comparer.TryConvertStringValueArrayToBooleanList(valueArray, out var booleanList);
56+
57+
Assert.Multiple(() =>
58+
{
59+
Assert.That(success, Is.False);
60+
Assert.That(booleanList, Is.Empty);
61+
});
62+
}
63+
}
64+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="GuidExtensionsTestFixture.cs" company="Starion Group S.A.">
3+
// Copyright (c) 2015-2025 Starion Group S.A.
4+
//
5+
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
6+
//
7+
// This file is part of COMET-SDK Community Edition
8+
//
9+
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// --------------------------------------------------------------------------------------------------------------------
23+
24+
namespace CDP4Common.NetCore.Tests.Extensions
25+
{
26+
using System;
27+
using System.Collections.Generic;
28+
using System.Linq;
29+
using CDP4Common.Extensions;
30+
using NUnit.Framework;
31+
32+
/// <summary>
33+
/// Tests for <see cref="GuidExtensions"/>.
34+
/// </summary>
35+
[TestFixture]
36+
public class GuidExtensionsTestFixture
37+
{
38+
[Test]
39+
public void VerifyShortGuidRoundTrip()
40+
{
41+
var guid = Guid.NewGuid();
42+
43+
var shortGuid = guid.ToShortGuid();
44+
var roundTrip = shortGuid.FromShortGuid();
45+
46+
Assert.Multiple(() =>
47+
{
48+
Assert.That(shortGuid, Has.Length.EqualTo(22));
49+
Assert.That(shortGuid, Does.Not.Contain("/").And.Not.Contain("+"));
50+
Assert.That(roundTrip, Is.EqualTo(guid));
51+
});
52+
}
53+
54+
[Test]
55+
public void VerifyShortGuidArrayRoundTrip()
56+
{
57+
var guids = new List<Guid> { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
58+
59+
var shortGuidArray = guids.ToShortGuidArray();
60+
var roundTrip = shortGuidArray.FromShortGuidArray().ToList();
61+
62+
Assert.Multiple(() =>
63+
{
64+
Assert.That(shortGuidArray.StartsWith("[") && shortGuidArray.EndsWith("]"), Is.True);
65+
Assert.That(roundTrip, Is.EqualTo(guids));
66+
});
67+
}
68+
69+
}
70+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="ParameterValueValidatorTestFixture.cs" company="Starion Group S.A.">
3+
// Copyright (c) 2015-2025 Starion Group S.A.
4+
//
5+
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
6+
//
7+
// This file is part of COMET-SDK Community Edition
8+
//
9+
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// --------------------------------------------------------------------------------------------------------------------
23+
24+
namespace CDP4Common.NetCore.Tests.Helpers
25+
{
26+
using CDP4Common.Helpers;
27+
using CDP4Common.SiteDirectoryData;
28+
using NUnit.Framework;
29+
30+
/// <summary>
31+
/// Tests for <see cref="ParameterValueValidator"/>.
32+
/// </summary>
33+
[TestFixture]
34+
public class ParameterValueValidatorTestFixture
35+
{
36+
[Test]
37+
public void VerifyThatNullParameterTypeReturnsError()
38+
{
39+
var error = ParameterValueValidator.Validate("value", null);
40+
41+
Assert.That(error, Is.EqualTo("Error: The parameter type is null."));
42+
}
43+
44+
[Test]
45+
public void VerifyThatValidBooleanValueReturnsNull()
46+
{
47+
var parameterType = new BooleanParameterType();
48+
49+
var error = ParameterValueValidator.Validate(true, parameterType);
50+
51+
Assert.That(error, Is.Null);
52+
}
53+
54+
[Test]
55+
public void VerifyThatInvalidBooleanValueReturnsValidationMessage()
56+
{
57+
var parameterType = new BooleanParameterType();
58+
59+
var error = ParameterValueValidator.Validate("not-a-boolean", parameterType);
60+
61+
Assert.That(error, Does.Contain("not-a-boolean"));
62+
}
63+
}
64+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AuthenticationInformationTestFixture.cs" company="Starion Group S.A.">
3+
// Copyright (c) 2015-2025 Starion Group S.A.
4+
//
5+
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
6+
//
7+
// This file is part of COMET-SDK Community Edition
8+
//
9+
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// --------------------------------------------------------------------------------------------------------------------
23+
24+
namespace CDP4Dal.NetCore.Tests.DAL
25+
{
26+
using CDP4Dal.DAL;
27+
using CDP4DalCommon.Authentication;
28+
using NUnit.Framework;
29+
30+
/// <summary>
31+
/// Tests for <see cref="AuthenticationInformation"/>.
32+
/// </summary>
33+
[TestFixture]
34+
public class AuthenticationInformationTestFixture
35+
{
36+
[Test]
37+
public void VerifyConstructorWithUserNameAndPassword()
38+
{
39+
const string expectedUserName = "user";
40+
const string expectedPassword = "pass";
41+
42+
var information = new AuthenticationInformation(expectedUserName, expectedPassword);
43+
44+
Assert.Multiple(() =>
45+
{
46+
Assert.That(information.UserName, Is.EqualTo(expectedUserName));
47+
Assert.That(information.Password, Is.EqualTo(expectedPassword));
48+
Assert.That(information.Token, Is.Null);
49+
});
50+
}
51+
52+
[Test]
53+
public void VerifyConstructorWithAuthenticationToken()
54+
{
55+
var expectedToken = new AuthenticationToken("access", "refresh");
56+
57+
var information = new AuthenticationInformation(expectedToken);
58+
59+
Assert.Multiple(() =>
60+
{
61+
Assert.That(information.Token, Is.SameAs(expectedToken));
62+
Assert.That(information.UserName, Is.Null);
63+
Assert.That(information.Password, Is.Null);
64+
});
65+
}
66+
}
67+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AvailableDalsTestFixture.cs" company="Starion Group S.A.">
3+
// Copyright (c) 2015-2025 Starion Group S.A.
4+
//
5+
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
6+
//
7+
// This file is part of COMET-SDK Community Edition
8+
//
9+
// The COMET-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The COMET-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// --------------------------------------------------------------------------------------------------------------------
23+
24+
namespace CDP4Dal.NetCore.Tests.DAL
25+
{
26+
using System;
27+
using System.Collections.Generic;
28+
using CDP4Dal;
29+
using CDP4Dal.Composition;
30+
using CDP4Dal.DAL;
31+
using Moq;
32+
using NUnit.Framework;
33+
34+
/// <summary>
35+
/// Tests for <see cref="AvailableDals"/>.
36+
/// </summary>
37+
[TestFixture]
38+
public class AvailableDalsTestFixture
39+
{
40+
[Test]
41+
public void VerifyThatConstructorCopiesProvidedDalKinds()
42+
{
43+
var firstDal = new Lazy<IDal, IDalMetaData>(() => Mock.Of<IDal>(), new TestDalMetaData("first"));
44+
var secondDal = new Lazy<IDal, IDalMetaData>(() => Mock.Of<IDal>(), new TestDalMetaData("second"));
45+
var provided = new List<Lazy<IDal, IDalMetaData>> { firstDal, secondDal };
46+
47+
var availableDals = new AvailableDals(provided);
48+
49+
Assert.Multiple(() =>
50+
{
51+
Assert.That(availableDals.DataAccessLayerKinds, Is.Not.SameAs(provided));
52+
Assert.That(availableDals.DataAccessLayerKinds, Is.EquivalentTo(provided));
53+
});
54+
55+
provided.Add(new Lazy<IDal, IDalMetaData>(() => Mock.Of<IDal>(), new TestDalMetaData("third")));
56+
57+
Assert.That(availableDals.DataAccessLayerKinds, Has.Count.EqualTo(2));
58+
}
59+
60+
private sealed class TestDalMetaData : IDalMetaData
61+
{
62+
public TestDalMetaData(string name)
63+
{
64+
this.Name = name;
65+
}
66+
67+
public DalType DalType => DalType.Web;
68+
69+
public string CDPVersion => "1";
70+
71+
public string Name { get; }
72+
73+
public string Description => this.Name;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)