-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "Revert "Semantic domain model/type update (#1718)" (#1732)" This reverts commit 65b8c4d. * Fully implement backend API for retrieving Semantic Domain tree information to support navigation for Data Entry. - Regenerate Open API * Refactor front-end to use the new API instead of asynchronously loading the Semantic Domains from .json files - Use a TreeNode version of the domain info during navigation - Fetch full semantic domains on completed tree navigation - Fix issue #1684 * Modify lift import to support new backend model - Import: Add MongoID on each SemanticDomain - Import test: Add check for empty MongoId and Clone MongoId when cloning SemanticDomain Co-authored-by: D. Ror <imnasnainaec@gmail.com>
- Loading branch information
1 parent
bcd3464
commit fcd5456
Showing
71 changed files
with
1,726 additions
and
66,038 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
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
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
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
90 changes: 90 additions & 0 deletions
90
Backend.Tests/Controllers/SemanticDomainControllerTests.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,90 @@ | ||
using Backend.Tests.Mocks; | ||
using BackendFramework.Controllers; | ||
using BackendFramework.Interfaces; | ||
using BackendFramework.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NUnit.Framework; | ||
|
||
namespace Backend.Tests.Controllers | ||
{ | ||
public class SemanticDomainControllerTests | ||
{ | ||
private ISemanticDomainRepository _semDomRepository = null!; | ||
private SemanticDomainController _semDomController = null!; | ||
|
||
private const string Id = "1"; | ||
private const string Lang = "en"; | ||
private const string Name = "Universe"; | ||
|
||
private readonly SemanticDomainFull _semDom = new() { Id = Id, Lang = Lang, Name = Name }; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_semDomRepository = new SemanticDomainRepositoryMock(); | ||
_semDomController = new SemanticDomainController(_semDomRepository); | ||
} | ||
|
||
[Test] | ||
public void SemanticDomainController_GetSemanticDomainFull_DomainFound() | ||
{ | ||
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(_semDom); | ||
var domain = (SemanticDomainFull?)( | ||
(ObjectResult)_semDomController.GetSemanticDomainFull(Id, Lang).Result).Value; | ||
Assert.That(domain?.Id, Is.EqualTo(Id)); | ||
Assert.That(domain?.Lang, Is.EqualTo(Lang)); | ||
Assert.That(domain?.Name, Is.EqualTo(Name)); | ||
} | ||
|
||
[Test] | ||
public void SemanticDomainController_GetSemanticDomainFull_DomainNotFound() | ||
{ | ||
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(null); | ||
var domain = (SemanticDomainFull?)( | ||
(ObjectResult)_semDomController.GetSemanticDomainFull(Id, Lang).Result).Value; | ||
Assert.That(domain, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void SemanticDomainController_GetSemanticDomainTreeNode_DomainFound() | ||
{ | ||
var treeNode = new SemanticDomainTreeNode(_semDom); | ||
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(treeNode); | ||
var domain = (SemanticDomainTreeNode?)( | ||
(ObjectResult)_semDomController.GetSemanticDomainTreeNode(Id, Lang).Result).Value; | ||
Assert.That(domain?.Id, Is.EqualTo(Id)); | ||
Assert.That(domain?.Lang, Is.EqualTo(Lang)); | ||
Assert.That(domain?.Name, Is.EqualTo(Name)); | ||
} | ||
|
||
[Test] | ||
public void SemanticDomainController_GetSemanticDomainTreeNode_DomainNotFound() | ||
{ | ||
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(null); | ||
var domain = (SemanticDomainTreeNode?)( | ||
(ObjectResult)_semDomController.GetSemanticDomainTreeNode(Id, Lang).Result).Value; | ||
Assert.That(domain, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void SemanticDomainController_GetSemanticDomainTreeNodeByName_DomainFound() | ||
{ | ||
var treeNode = new SemanticDomainTreeNode(_semDom); | ||
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(treeNode); | ||
var domain = (SemanticDomainTreeNode?)( | ||
(ObjectResult)_semDomController.GetSemanticDomainTreeNodeByName(Name, Lang).Result).Value; | ||
Assert.That(domain?.Id, Is.EqualTo(Id)); | ||
Assert.That(domain?.Lang, Is.EqualTo(Lang)); | ||
Assert.That(domain?.Name, Is.EqualTo(Name)); | ||
} | ||
|
||
[Test] | ||
public void SemanticDomainController_GetSemanticDomainTreeNodeByName_DomainNotFound() | ||
{ | ||
((SemanticDomainRepositoryMock)_semDomRepository).SetNextResponse(null); | ||
var domain = (SemanticDomainTreeNode?)( | ||
(ObjectResult)_semDomController.GetSemanticDomainTreeNodeByName(Name, Lang).Result).Value; | ||
Assert.That(domain, Is.Null); | ||
} | ||
} | ||
} |
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,31 @@ | ||
using System.Threading.Tasks; | ||
using BackendFramework.Interfaces; | ||
using BackendFramework.Models; | ||
|
||
namespace Backend.Tests.Mocks | ||
{ | ||
public class SemanticDomainRepositoryMock : ISemanticDomainRepository | ||
{ | ||
private object? _responseObj; | ||
|
||
public Task<SemanticDomainFull?> GetSemanticDomainFull(string id, string lang) | ||
{ | ||
return Task.FromResult((SemanticDomainFull?)_responseObj); | ||
} | ||
|
||
public Task<SemanticDomainTreeNode?> GetSemanticDomainTreeNode(string id, string lang) | ||
{ | ||
return Task.FromResult((SemanticDomainTreeNode?)_responseObj); | ||
} | ||
|
||
public Task<SemanticDomainTreeNode?> GetSemanticDomainTreeNodeByName(string name, string lang) | ||
{ | ||
return Task.FromResult((SemanticDomainTreeNode?)_responseObj); | ||
} | ||
|
||
internal void SetNextResponse(object? response) | ||
{ | ||
_responseObj = response; | ||
} | ||
} | ||
} |
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
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,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BackendFramework.Models; | ||
using NUnit.Framework; | ||
|
||
namespace Backend.Tests.Models | ||
{ | ||
public class SemanticDomainTests | ||
{ | ||
private const string Name = "Home"; | ||
|
||
[Test] | ||
public void TestEquals() | ||
{ | ||
var domain = new SemanticDomain { Name = Name }; | ||
Assert.That(domain.Equals(new SemanticDomain { Name = Name })); | ||
} | ||
|
||
[Test] | ||
public void TestEqualsNull() | ||
{ | ||
var domain = new SemanticDomain { Name = Name }; | ||
Assert.IsFalse(domain.Equals(null)); | ||
} | ||
|
||
[Test] | ||
public void TestHashCode() | ||
{ | ||
Assert.AreNotEqual( | ||
new SemanticDomain { Id = "1" }.GetHashCode(), | ||
new SemanticDomain { Id = "2" }.GetHashCode() | ||
); | ||
|
||
Assert.AreNotEqual( | ||
new SemanticDomain { Name = "1" }.GetHashCode(), | ||
new SemanticDomain { Name = "2" }.GetHashCode() | ||
); | ||
|
||
Assert.AreNotEqual( | ||
new SemanticDomain { Guid = Guid.NewGuid().ToString() }.GetHashCode(), | ||
new SemanticDomain { Name = Guid.NewGuid().ToString() }.GetHashCode() | ||
); | ||
} | ||
} | ||
|
||
public class SemanticDomainFullTests | ||
{ | ||
private const string Name = "Home"; | ||
|
||
[Test] | ||
public void TestEquals() | ||
{ | ||
var domain = new SemanticDomainFull { Name = Name }; | ||
Assert.That(domain.Equals(new SemanticDomainFull { Name = Name })); | ||
} | ||
|
||
[Test] | ||
public void TestEqualsNull() | ||
{ | ||
var domain = new SemanticDomainFull { Name = Name }; | ||
Assert.IsFalse(domain.Equals(null)); | ||
} | ||
|
||
[Test] | ||
public void TestHashCode() | ||
{ | ||
Assert.AreNotEqual( | ||
new SemanticDomainFull { Id = "1" }.GetHashCode(), | ||
new SemanticDomainFull { Id = "2" }.GetHashCode() | ||
); | ||
|
||
Assert.AreNotEqual( | ||
new SemanticDomainFull { Name = "1" }.GetHashCode(), | ||
new SemanticDomainFull { Name = "2" }.GetHashCode() | ||
); | ||
|
||
Assert.AreNotEqual( | ||
new SemanticDomainFull { Description = "1" }.GetHashCode(), | ||
new SemanticDomainFull { Description = "2" }.GetHashCode() | ||
); | ||
|
||
Assert.AreNotEqual( | ||
new SemanticDomainFull { Questions = new List<string> { "1" } }.GetHashCode(), | ||
new SemanticDomainFull { Questions = new List<string> { "2" } }.GetHashCode() | ||
); | ||
} | ||
} | ||
} |
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
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
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,23 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using BackendFramework.Interfaces; | ||
using BackendFramework.Models; | ||
using Microsoft.Extensions.Options; | ||
using MongoDB.Driver; | ||
|
||
namespace BackendFramework.Contexts | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class SemanticDomainContext : ISemanticDomainContext | ||
{ | ||
private readonly IMongoDatabase _db; | ||
|
||
public SemanticDomainContext(IOptions<Startup.Settings> options) | ||
{ | ||
var client = new MongoClient(options.Value.ConnectionString); | ||
_db = client.GetDatabase(options.Value.CombineDatabase); | ||
} | ||
|
||
public IMongoCollection<SemanticDomainTreeNode> SemanticDomains => _db.GetCollection<SemanticDomainTreeNode>("SemanticDomainTree"); | ||
public IMongoCollection<SemanticDomainFull> FullSemanticDomains => _db.GetCollection<SemanticDomainFull>("SemanticDomains"); | ||
} | ||
} |
Oops, something went wrong.