Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Jan 24, 2024
1 parent e55d30a commit e95fdaa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Changed

- Add ability to log to file instead of database
- Add ability to use Extraction Category with Project Specific Catalogues

## [8.1.3] - 2024-01-15

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) The University of Dundee 2024-2024
// This file is part of the Research Data Management Platform (RDMP).
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// RDMP 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 General Public License for more details.
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.

using NUnit.Framework;
using Rdmp.Core.CommandExecution;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Repositories;
using System.Linq;
using Tests.Common;
using NSubstitute;
using NSubstitute.Extensions;
using Rdmp.Core.DataExport.Data;
using Rdmp.Core.Curation.Data.Aggregation;
using static Org.BouncyCastle.Math.EC.ECCurve;
namespace Rdmp.Core.Tests.CommandExecution;

public class ExecuteCommandChangeExtractionCategoryTests : DatabaseTests
{
private Catalogue _cata1;
private Catalogue _cata2;
private TableInfo _t1;
private TableInfo _t2;
private ColumnInfo _c1;
private ColumnInfo _c2;
private CatalogueItem _ci1;
private CatalogueItem _ci2;
private Project _project;

private ExtractionInformation _extractionInfo1;
private ExtractionInformation _extractionInfo2;

[Test]
public void TestProjectSpecificCatalogueChangeToSuplemental()
{
//change project specific to supplemental
_cata1 =new Catalogue(CatalogueRepository, "Dataset1");
_t1 = new TableInfo(CatalogueRepository, "T1");

_c1 = new ColumnInfo(CatalogueRepository, "PrivateIdentifierA", "varchar(10)", _t1);

_ci1 = new CatalogueItem(CatalogueRepository, _cata1, "PrivateIdentifierA");

_extractionInfo1 = new ExtractionInformation(CatalogueRepository, _ci1, _c1, _c1.ToString())
{
Order = 123,
ExtractionCategory = ExtractionCategory.ProjectSpecific,
IsExtractionIdentifier = true
};
_extractionInfo1.CatalogueItem.Catalogue.InjectKnown(new CatalogueExtractabilityStatus(true, true));

ExtractionInformation[] eid = { _extractionInfo1 };
var cmd = new ExecuteCommandChangeExtractionCategory(new ThrowImmediatelyActivator(RepositoryLocator), eid, ExtractionCategory.Supplemental);
Assert.DoesNotThrow(() => cmd.Execute());
Assert.That(_extractionInfo1.ExtractionCategory, Is.EqualTo(ExtractionCategory.Supplemental));
}

[Test]
public void TestExtractionCategoryCatalogueChangeFromSupplementalToCore()
{
//change a project specific column to core
_cata1 = new Catalogue(CatalogueRepository, "Dataset1");
_t1 = new TableInfo(CatalogueRepository, "T1");

_c1 = new ColumnInfo(CatalogueRepository, "PrivateIdentifierA", "varchar(10)", _t1);

_ci1 = new CatalogueItem(CatalogueRepository, _cata1, "PrivateIdentifierA");


_extractionInfo1 = new ExtractionInformation(CatalogueRepository, _ci1, _c1, _c1.ToString())
{
Order = 123,
ExtractionCategory = ExtractionCategory.Supplemental,
IsExtractionIdentifier = true
};
_extractionInfo1.CatalogueItem.Catalogue.InjectKnown(new CatalogueExtractabilityStatus(true, true));

ExtractionInformation[] eid = { _extractionInfo1 };
var cmd = new ExecuteCommandChangeExtractionCategory(new ThrowImmediatelyActivator(RepositoryLocator), eid, ExtractionCategory.Core);
Assert.DoesNotThrow(() => cmd.Execute());
var x = CatalogueRepository.GetAllObjects<ExtractionInformation>();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to
x
is useless, since its value is never read.
Assert.That(_extractionInfo1.ExtractionCategory, Is.EqualTo(ExtractionCategory.ProjectSpecific));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ public override void Execute()
base.Execute();

var c = _category;

if (c == null && BasicActivator.SelectValueType("New Extraction Category", typeof(ExtractionCategory),
ExtractionCategory.Core, out var category))
{
c = (ExtractionCategory)category;
}

if (c == null)
return;

if (_isProjectSpecific && c == ExtractionCategory.Core)
{
// Don't allow project specific catalogue items to become core
c = ExtractionCategory.ProjectSpecific;
Show("Cannot set the Extraction Category to 'Core' for a Project Specific Catalogue item. It will be saved as 'Project Specific'.");
}
if(c == _category) return;//no commit needed
//if (c == _category) return;//no commit needed

if (ExecuteWithCommit(() => ExecuteImpl(c.Value), $"Set ExtractionCategory to '{c}'", _extractionInformations))
//publish the root Catalogue
Expand Down

0 comments on commit e95fdaa

Please sign in to comment.