-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add sonarcloud support (#140) * Autogen excludes * Update appveyor.yml * Update appveyor.yml * Fixes #143 required rdl lookup (#144) * Fix required rdl lookup * Fix docs * Added unit tests Co-authored-by: Mike Unitskyi <[email protected]> Co-authored-by: Alexander van Delft <[email protected]>
- Loading branch information
1 parent
8fa9207
commit 2e9727e
Showing
6 changed files
with
329 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,5 +70,6 @@ packages/ | |
#Test files | ||
|
||
CDP4.v12.suo | ||
|
||
/CodeGenerator/* | ||
|
||
/CodeGenerator/* | ||
.idea |
218 changes: 218 additions & 0 deletions
218
...ebServices.API.Tests/Services/Supplemental/ModelReferenceDataLibraryServiceTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="ModelReferenceDataLibraryServiceTestFixture.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2015-2020 RHEA System S.A. | ||
// | ||
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Kamil Wojnowski, Nathanael Smiechowski | ||
// | ||
// This file is part of CDP4 Web Services Community Edition. | ||
// The CDP4 Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C. | ||
// This is an auto-generated class. Any manual changes to this file will be overwritten! | ||
// | ||
// The CDP4 Web Services Community Edition is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Affero General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 3 of the License, or (at your option) any later version. | ||
// | ||
// The CDP4 Web Services 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 Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace CDP4WebServices.API.Tests.Services.Supplemental | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using CDP4Common.DTO; | ||
|
||
using CDP4Orm.Dao; | ||
|
||
using CDP4WebServices.API.Helpers; | ||
using CDP4WebServices.API.Services; | ||
|
||
using Moq; | ||
|
||
using Npgsql; | ||
|
||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class ModelReferenceDataLibraryServiceTestFixture | ||
{ | ||
private Mock<ISiteReferenceDataLibraryDao> siteReferenceDataLibraryDao; | ||
private Mock<IEngineeringModelSetupDao> engineeringModelSetupDao; | ||
private Mock<IModelReferenceDataLibraryDao> modelReferenceDataLibraryDao; | ||
|
||
private Mock<ICdp4TransactionManager> transactionManager; | ||
private ModelReferenceDataLibrary modelReferenceDataLibrary; | ||
private SiteReferenceDataLibrary siteReferenceDataLibrary1; | ||
private SiteReferenceDataLibrary siteReferenceDataLibrary2; | ||
private Iteration iteration; | ||
private IterationSetup iterationSetup; | ||
private EngineeringModelSetup engineeringModelSetup; | ||
|
||
private ModelReferenceDataLibraryService modelReferenceDataLibraryService; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.siteReferenceDataLibraryDao = new Mock<ISiteReferenceDataLibraryDao>(); | ||
this.engineeringModelSetupDao = new Mock<IEngineeringModelSetupDao>(); | ||
this.modelReferenceDataLibraryDao = new Mock<IModelReferenceDataLibraryDao>(); | ||
this.transactionManager = new Mock<ICdp4TransactionManager>(); | ||
|
||
this.transactionManager.Setup(x => x.IsFullAccessEnabled()).Returns(true); | ||
|
||
this.modelReferenceDataLibraryService = new ModelReferenceDataLibraryService | ||
{ | ||
EngineeringModelSetupDao = this.engineeringModelSetupDao.Object, | ||
SiteReferenceDataLibraryDato = this.siteReferenceDataLibraryDao.Object, | ||
ModelReferenceDataLibraryDao = this.modelReferenceDataLibraryDao.Object, | ||
TransactionManager = this.transactionManager.Object | ||
}; | ||
|
||
this.siteReferenceDataLibrary1 = new SiteReferenceDataLibrary(Guid.NewGuid(), 0); | ||
this.siteReferenceDataLibrary2 = new SiteReferenceDataLibrary(Guid.NewGuid(), 0); | ||
this.modelReferenceDataLibrary = new ModelReferenceDataLibrary(Guid.NewGuid(), 0); | ||
|
||
this.iteration = new Iteration(Guid.NewGuid(), 0); | ||
this.iterationSetup = new IterationSetup(Guid.NewGuid(), 0); | ||
this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), 0); | ||
|
||
this.iteration.IterationSetup = this.iterationSetup.Iid; | ||
|
||
this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup.Iid); | ||
} | ||
|
||
[Test] | ||
public void VerifyQueryReferenceDataLibraryThrowsOnUnknownEngineeringModelSetup() | ||
{ | ||
this.engineeringModelSetupDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
It.IsAny<IEnumerable<Guid>>(), | ||
It.IsAny<bool>())) | ||
.Returns(new List<EngineeringModelSetup>()); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => this.modelReferenceDataLibraryService.QueryReferenceDataLibrary(null, this.iteration) | ||
); | ||
} | ||
|
||
[Test] | ||
public void VerifyQueryReferenceDataLibraryThrowsOnNotHavingModelReferenceDataLibrary() | ||
{ | ||
this.engineeringModelSetupDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
It.IsAny<IEnumerable<Guid>>(), | ||
It.IsAny<bool>())) | ||
.Returns(new List<EngineeringModelSetup> {this.engineeringModelSetup}); | ||
|
||
Assert.Throws<InvalidOperationException>( | ||
() => this.modelReferenceDataLibraryService.QueryReferenceDataLibrary(null, this.iteration) | ||
); | ||
} | ||
|
||
[Test] | ||
public void VerifyQueryReferenceDataLibraryWorksForModelReferenceDataLibrary() | ||
{ | ||
this.engineeringModelSetupDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
It.IsAny<IEnumerable<Guid>>(), | ||
It.IsAny<bool>())) | ||
.Returns(new List<EngineeringModelSetup> { this.engineeringModelSetup }); | ||
|
||
this.modelReferenceDataLibraryDao.Setup( x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
It.IsAny<IEnumerable<Guid>>(), | ||
It.IsAny<bool>())) | ||
.Returns(new List<ModelReferenceDataLibrary> { this.modelReferenceDataLibrary}); | ||
|
||
var result = this.modelReferenceDataLibraryService.QueryReferenceDataLibrary(null, this.iteration); | ||
|
||
CollectionAssert.AreEqual(new List<ReferenceDataLibrary> { this.modelReferenceDataLibrary }, result); | ||
} | ||
|
||
[Test] | ||
public void VerifyQueryReferenceDataLibraryWorksForModelReferenceDataLibraryWithSingleSiteReferenceLibraryInChainOfRDLs() | ||
{ | ||
this.engineeringModelSetupDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
It.IsAny<IEnumerable<Guid>>(), | ||
It.IsAny<bool>())) | ||
.Returns(new List<EngineeringModelSetup> { this.engineeringModelSetup }); | ||
|
||
this.engineeringModelSetup.RequiredRdl.Add(this.modelReferenceDataLibrary.Iid); | ||
|
||
this.modelReferenceDataLibraryDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
new [] { this.modelReferenceDataLibrary.Iid}, | ||
It.IsAny<bool>())) | ||
.Returns(new List<ModelReferenceDataLibrary> { this.modelReferenceDataLibrary }); | ||
|
||
this.siteReferenceDataLibraryDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
new[] { this.siteReferenceDataLibrary1.Iid }, | ||
It.IsAny<bool>())) | ||
.Returns(new List<SiteReferenceDataLibrary> { this.siteReferenceDataLibrary1 }); | ||
|
||
this.modelReferenceDataLibrary.RequiredRdl = this.siteReferenceDataLibrary1.Iid; | ||
|
||
var result = this.modelReferenceDataLibraryService.QueryReferenceDataLibrary(null, this.iteration); | ||
|
||
CollectionAssert.AreEqual(new List<ReferenceDataLibrary> { this.modelReferenceDataLibrary, this.siteReferenceDataLibrary1 }, result); | ||
} | ||
|
||
[Test] | ||
public void VerifyQueryReferenceDataLibraryWorksForModelReferenceDataLibraryWithMultipleSiteReferenceLibrariesInChainOfRDLs() | ||
{ | ||
this.engineeringModelSetupDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
It.IsAny<IEnumerable<Guid>>(), | ||
It.IsAny<bool>())) | ||
.Returns(new List<EngineeringModelSetup> { this.engineeringModelSetup }); | ||
|
||
this.engineeringModelSetup.RequiredRdl.Add(this.modelReferenceDataLibrary.Iid); | ||
|
||
this.modelReferenceDataLibraryDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
new[] { this.modelReferenceDataLibrary.Iid }, | ||
It.IsAny<bool>())) | ||
.Returns(new List<ModelReferenceDataLibrary> { this.modelReferenceDataLibrary }); | ||
|
||
this.siteReferenceDataLibraryDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
new[] { this.siteReferenceDataLibrary1.Iid }, | ||
It.IsAny<bool>())) | ||
.Returns(new List<SiteReferenceDataLibrary> { this.siteReferenceDataLibrary1 }); | ||
|
||
this.siteReferenceDataLibraryDao.Setup(x => x.Read( | ||
It.IsAny<NpgsqlTransaction>(), | ||
It.IsAny<string>(), | ||
new[] { this.siteReferenceDataLibrary2.Iid }, | ||
It.IsAny<bool>())) | ||
.Returns(new List<SiteReferenceDataLibrary> { this.siteReferenceDataLibrary2 }); | ||
|
||
this.modelReferenceDataLibrary.RequiredRdl = this.siteReferenceDataLibrary1.Iid; | ||
this.siteReferenceDataLibrary1.RequiredRdl = this.siteReferenceDataLibrary2.Iid; | ||
|
||
var result = this.modelReferenceDataLibraryService.QueryReferenceDataLibrary(null, this.iteration); | ||
|
||
CollectionAssert.AreEqual(new List<ReferenceDataLibrary> { this.modelReferenceDataLibrary, this.siteReferenceDataLibrary1, this.siteReferenceDataLibrary2 }, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.