-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExecuteCommandLinkCatalogueToDatasetTests.cs
More file actions
101 lines (91 loc) · 5.36 KB
/
ExecuteCommandLinkCatalogueToDatasetTests.cs
File metadata and controls
101 lines (91 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Linq;
using NUnit.Framework;
using Rdmp.Core.CommandExecution;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Curation.Data;
namespace Rdmp.Core.Tests.CommandExecution;
internal class ExecuteCommandLinkCatalogueToDatasetTests : CommandCliTests
{
[Test]
public void TestLinkCatalogueToDataset()
{
var _cata1 = new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository, "Dataset1");
var _cata2 = new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository, "Dataset2");
_cata1.SaveToDatabase();
_cata2.SaveToDatabase();
var _t1 = new TableInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "T1");
var _t2 = new TableInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "T2");
_t1.SaveToDatabase();
_t2.SaveToDatabase();
var _c1 = new ColumnInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "test.db", "varchar(10)", _t1);
var _c2 = new ColumnInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "test.db", "int", _t2);
_c1.SaveToDatabase();
_c2.SaveToDatabase();
var _ci1 = new CatalogueItem(GetMockActivator().RepositoryLocator.CatalogueRepository, _cata1, "PrivateIdentifierA");
_ci1.SetColumnInfo(_c1);
var _ci2 = new CatalogueItem(GetMockActivator().RepositoryLocator.CatalogueRepository, _cata2, "PrivateIdentifierB");
_ci2.SetColumnInfo(_c2);
_ci1.SaveToDatabase();
_ci2.SaveToDatabase();
var cmd = new ExecuteCommandCreateDataset(GetMockActivator(), "dataset");
Assert.DoesNotThrow(cmd.Execute);
var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Datasets.Dataset>().First();
var foundCatalogue = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>().First(static c => c.Name == "Dataset1");
var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), foundCatalogue, founddataset);
Assert.DoesNotThrow(linkCmd.Execute);
founddataset.DeleteInDatabase();
foundCatalogue.DeleteInDatabase();
}
[Test]
public void TestLinkCatalogueToDatasetNotAll()
{
var _cata1 = new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository, "Dataset1");
var _cata2 = new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository, "Dataset2");
_cata1.SaveToDatabase();
_cata2.SaveToDatabase();
var _t1 = new TableInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "T1");
var _t2 = new TableInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "T2");
_t1.SaveToDatabase();
_t2.SaveToDatabase();
var _c1 = new ColumnInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "test.db", "varchar(10)", _t1);
var _c2 = new ColumnInfo(GetMockActivator().RepositoryLocator.CatalogueRepository, "test.db", "int", _t2);
_c1.SaveToDatabase();
_c2.SaveToDatabase();
var _ci1 = new CatalogueItem(GetMockActivator().RepositoryLocator.CatalogueRepository, _cata1, "PrivateIdentifierA");
_ci1.SetColumnInfo(_c1);
var _ci2 = new CatalogueItem(GetMockActivator().RepositoryLocator.CatalogueRepository, _cata2, "PrivateIdentifierB");
_ci2.SetColumnInfo(_c2);
_ci1.SaveToDatabase();
_ci2.SaveToDatabase();
var cmd = new ExecuteCommandCreateDataset(GetMockActivator(), "dataset");
Assert.DoesNotThrow(cmd.Execute);
var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Datasets.Dataset>().First();
var foundCatalogue = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Catalogue>().First(c => c.Name == "Dataset1");
var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), foundCatalogue, founddataset, false);
Assert.DoesNotThrow(linkCmd.Execute);
}
[Test]
public void TestLinkCatalogueToDatasetBadCatalogue()
{
var cmd = new ExecuteCommandCreateDataset(GetMockActivator(), "dataset");
Assert.DoesNotThrow(cmd.Execute);
var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Datasets.Dataset>().First();
var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), null, founddataset, false);
Assert.Throws<ImpossibleCommandException>(linkCmd.Execute);
}
[Test]
public void TestLinkCatalogueToDatasetBadDataset()
{
var cmd = new ExecuteCommandCreateDataset(GetMockActivator(), "dataset");
Assert.DoesNotThrow(cmd.Execute);
var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Datasets.Dataset>().First();
var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository, "catalogue"), null, false);
Assert.Throws<ImpossibleCommandException>(linkCmd.Execute);
}
[Test]
public void TestLinkCatalogueToDatasetBadEverything()
{
var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), null, null, false);
Assert.Throws<ImpossibleCommandException>(linkCmd.Execute);
}
}