diff --git a/.editorconfig b/.editorconfig
index 788149656b8..66a6ee2814c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -4,8 +4,10 @@
# top-most EditorConfig file
root = true
+# Standardize on CR/LF (Windows) line endings
# Don't use tabs for indentation.
[*]
+end_of_line = crlf
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)
@@ -182,4 +184,4 @@ csharp_space_between_parentheses = false
# Blocks are allowed
csharp_prefer_braces = true:silent
csharp_preserve_single_line_blocks = true
-csharp_preserve_single_line_statements = true
\ No newline at end of file
+csharp_preserve_single_line_statements = true
diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md
index ee90d788591..ccd2e40fce0 100644
--- a/.github/ISSUE_TEMPLATE/bug-report.md
+++ b/.github/ISSUE_TEMPLATE/bug-report.md
@@ -41,8 +41,8 @@ Provide any additional context that may be helpful in understanding and/or resol
Please add X in at least one of the boxes as appropriate. In order for an issue to be accepted, a developer needs to be able to reproduce the issue on a currently supported version. If you are looking for a workaround for an issue with an older version, please visit the forums at https://dnncommunity.org/forums
-->
* [ ] 10.00.00 alpha build
-* [ ] 09.07.00 release candidate
-* [ ] 09.06.02 latest supported release
+* [ ] 09.07.01 release candidate
+* [ ] 09.07.00 latest supported release
## Affected browser
-
\ No newline at end of file
+
diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Content/ScopeTypeControllerTests.cs b/DNN Platform/Tests/DotNetNuke.Tests.Content/ScopeTypeControllerTests.cs
index e7b5f87d385..e81b717b324 100644
--- a/DNN Platform/Tests/DotNetNuke.Tests.Content/ScopeTypeControllerTests.cs
+++ b/DNN Platform/Tests/DotNetNuke.Tests.Content/ScopeTypeControllerTests.cs
@@ -2,229 +2,244 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
-namespace DotNetNuke.Tests.Content
-{
- using System;
- using System.Linq;
-
- using DotNetNuke.Common.Utilities;
- using DotNetNuke.Entities.Content.Data;
- using DotNetNuke.Entities.Content.Taxonomy;
- using DotNetNuke.Services.Cache;
- using DotNetNuke.Tests.Content.Mocks;
- using DotNetNuke.Tests.Utilities;
- using DotNetNuke.Tests.Utilities.Mocks;
- using Moq;
- using NUnit.Framework;
-
- ///
- /// Summary description for ScopeTypeTests.
- ///
- [TestFixture]
- public class ScopeTypeControllerTests
- {
- private Mock mockCache;
-
- [SetUp]
- public void SetUp()
- {
- // Register MockCachingProvider
- this.mockCache = MockComponentProvider.CreateNew();
- MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
- }
-
- [TearDown]
- public void TearDown()
- {
- MockComponentProvider.ResetContainer();
- }
-
- [Test]
- public void ScopeTypeController_AddScopeType_Throws_On_Null_ScopeType()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => scopeTypeController.AddScopeType(null));
- }
-
- [Test]
- public void ScopeTypeController_AddScopeType_Calls_DataService_On_Valid_Arguments()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- var scopeType = ContentTestHelper.CreateValidScopeType();
-
- // Act
- int scopeTypeId = scopeTypeController.AddScopeType(scopeType);
-
- // Assert
- mockDataService.Verify(ds => ds.AddScopeType(scopeType));
- }
-
- [Test]
- public void ScopeTypeController_AddScopeType_Returns_ValidId_On_Valid_ScopeType()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.AddScopeType(It.IsAny())).Returns(Constants.SCOPETYPE_AddScopeTypeId);
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
- ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
-
- // Act
- int scopeTypeId = scopeTypeController.AddScopeType(scopeType);
-
- // Assert
- Assert.AreEqual(Constants.SCOPETYPE_AddScopeTypeId, scopeTypeId);
- }
-
- [Test]
- public void ScopeTypeController_AddScopeType_Sets_ValidId_On_Valid_ScopeType()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.AddScopeType(It.IsAny())).Returns(Constants.SCOPETYPE_AddScopeTypeId);
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
- var scopeType = ContentTestHelper.CreateValidScopeType();
-
- // Act
- scopeTypeController.AddScopeType(scopeType);
-
- // Assert
- Assert.AreEqual(Constants.SCOPETYPE_AddScopeTypeId, scopeType.ScopeTypeId);
- }
-
- [Test]
- public void ScopeTypeController_DeleteScopeType_Throws_On_Null_ScopeType()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => scopeTypeController.DeleteScopeType(null));
- }
-
- [Test]
- public void ScopeTypeController_DeleteScopeType_Throws_On_Negative_ScopeTypeId()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
- scopeType.ScopeTypeId = Null.NullInteger;
-
- Assert.Throws(() => scopeTypeController.DeleteScopeType(scopeType));
- }
-
- [Test]
- public void ScopeTypeController_DeleteScopeType_Calls_DataService_On_Valid_ContentTypeId()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- var scopeType = ContentTestHelper.CreateValidScopeType();
- scopeType.ScopeTypeId = Constants.SCOPETYPE_ValidScopeTypeId;
-
- // Act
- scopeTypeController.DeleteScopeType(scopeType);
-
- // Assert
- mockDataService.Verify(ds => ds.DeleteScopeType(scopeType));
- }
-
- [Test]
- public void ScopeTypeController_GetScopeTypes_Calls_DataService()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetScopeTypes()).Returns(MockHelper.CreateValidScopeTypesReader(Constants.SCOPETYPE_ValidScopeTypeCount));
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- // Act
- IQueryable scopeTypes = scopeTypeController.GetScopeTypes();
-
- // Assert
- mockDataService.Verify(ds => ds.GetScopeTypes());
- }
-
- [Test]
- public void ScopeTypeController_GetScopeTypes_Returns_Empty_List_Of_ScopeTypes_If_No_ScopeTypes()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetScopeTypes()).Returns(MockHelper.CreateEmptyScopeTypeReader());
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- // Act
- var scopeTypes = scopeTypeController.GetScopeTypes();
-
- // Assert
- Assert.IsNotNull(scopeTypes);
- Assert.AreEqual(0, scopeTypes.Count());
- }
-
- [Test]
- public void ScopeTypeController_GetScopeTypes_Returns_List_Of_ScopeTypes()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetScopeTypes()).Returns(MockHelper.CreateValidScopeTypesReader(Constants.SCOPETYPE_ValidScopeTypeCount));
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- // Act
- var scopeTypes = scopeTypeController.GetScopeTypes();
-
- // Assert
- Assert.AreEqual(Constants.SCOPETYPE_ValidScopeTypeCount, scopeTypes.Count());
- }
-
- [Test]
- public void ScopeTypeController_UpdateScopeType_Throws_On_Null_ScopeType()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => scopeTypeController.UpdateScopeType(null));
- }
-
- [Test]
- public void ScopeTypeController_UpdateScopeType_Throws_On_Negative_ScopeTypeId()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
- scopeType.ScopeType = Constants.SCOPETYPE_InValidScopeType;
-
- Assert.Throws(() => scopeTypeController.UpdateScopeType(scopeType));
- }
-
- [Test]
- public void ScopeTypeController_UpdateScopeType_Calls_DataService_On_Valid_ContentType()
- {
- // Arrange
- var mockDataService = new Mock();
- var scopeTypeController = new ScopeTypeController(mockDataService.Object);
-
- ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
- scopeType.ScopeTypeId = Constants.SCOPETYPE_UpdateScopeTypeId;
- scopeType.ScopeType = Constants.SCOPETYPE_UpdateScopeType;
-
- // Act
- scopeTypeController.UpdateScopeType(scopeType);
-
- // Assert
- mockDataService.Verify(ds => ds.UpdateScopeType(scopeType));
- }
- }
-}
+namespace DotNetNuke.Tests.Content
+{
+ using System;
+ using System.Linq;
+
+ using DotNetNuke.Abstractions;
+ using DotNetNuke.Abstractions.Application;
+ using DotNetNuke.Common;
+ using DotNetNuke.Common.Utilities;
+ using DotNetNuke.Entities.Content.Data;
+ using DotNetNuke.Entities.Content.Taxonomy;
+ using DotNetNuke.Entities.Controllers;
+ using DotNetNuke.Services.Cache;
+ using DotNetNuke.Tests.Content.Mocks;
+ using DotNetNuke.Tests.Utilities;
+ using DotNetNuke.Tests.Utilities.Mocks;
+
+ using Microsoft.Extensions.DependencyInjection;
+
+ using Moq;
+
+ using NUnit.Framework;
+
+ ///
+ /// Summary description for ScopeTypeTests.
+ ///
+ [TestFixture]
+ public class ScopeTypeControllerTests
+ {
+ private Mock mockCache;
+
+ [SetUp]
+ public void SetUp()
+ {
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddTransient(container => Mock.Of());
+ serviceCollection.AddTransient(container => new DotNetNuke.Application.ApplicationStatusInfo(Mock.Of()));
+ serviceCollection.AddTransient();
+ Globals.DependencyProvider = serviceCollection.BuildServiceProvider();
+
+ // Register MockCachingProvider
+ this.mockCache = MockComponentProvider.CreateNew();
+ MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Globals.DependencyProvider = null;
+ MockComponentProvider.ResetContainer();
+ }
+
+ [Test]
+ public void ScopeTypeController_AddScopeType_Throws_On_Null_ScopeType()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => scopeTypeController.AddScopeType(null));
+ }
+
+ [Test]
+ public void ScopeTypeController_AddScopeType_Calls_DataService_On_Valid_Arguments()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ var scopeType = ContentTestHelper.CreateValidScopeType();
+
+ // Act
+ int scopeTypeId = scopeTypeController.AddScopeType(scopeType);
+
+ // Assert
+ mockDataService.Verify(ds => ds.AddScopeType(scopeType));
+ }
+
+ [Test]
+ public void ScopeTypeController_AddScopeType_Returns_ValidId_On_Valid_ScopeType()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.AddScopeType(It.IsAny())).Returns(Constants.SCOPETYPE_AddScopeTypeId);
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+ ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
+
+ // Act
+ int scopeTypeId = scopeTypeController.AddScopeType(scopeType);
+
+ // Assert
+ Assert.AreEqual(Constants.SCOPETYPE_AddScopeTypeId, scopeTypeId);
+ }
+
+ [Test]
+ public void ScopeTypeController_AddScopeType_Sets_ValidId_On_Valid_ScopeType()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.AddScopeType(It.IsAny())).Returns(Constants.SCOPETYPE_AddScopeTypeId);
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+ var scopeType = ContentTestHelper.CreateValidScopeType();
+
+ // Act
+ scopeTypeController.AddScopeType(scopeType);
+
+ // Assert
+ Assert.AreEqual(Constants.SCOPETYPE_AddScopeTypeId, scopeType.ScopeTypeId);
+ }
+
+ [Test]
+ public void ScopeTypeController_DeleteScopeType_Throws_On_Null_ScopeType()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => scopeTypeController.DeleteScopeType(null));
+ }
+
+ [Test]
+ public void ScopeTypeController_DeleteScopeType_Throws_On_Negative_ScopeTypeId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
+ scopeType.ScopeTypeId = Null.NullInteger;
+
+ Assert.Throws(() => scopeTypeController.DeleteScopeType(scopeType));
+ }
+
+ [Test]
+ public void ScopeTypeController_DeleteScopeType_Calls_DataService_On_Valid_ContentTypeId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ var scopeType = ContentTestHelper.CreateValidScopeType();
+ scopeType.ScopeTypeId = Constants.SCOPETYPE_ValidScopeTypeId;
+
+ // Act
+ scopeTypeController.DeleteScopeType(scopeType);
+
+ // Assert
+ mockDataService.Verify(ds => ds.DeleteScopeType(scopeType));
+ }
+
+ [Test]
+ public void ScopeTypeController_GetScopeTypes_Calls_DataService()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetScopeTypes()).Returns(MockHelper.CreateValidScopeTypesReader(Constants.SCOPETYPE_ValidScopeTypeCount));
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ // Act
+ IQueryable scopeTypes = scopeTypeController.GetScopeTypes();
+
+ // Assert
+ mockDataService.Verify(ds => ds.GetScopeTypes());
+ }
+
+ [Test]
+ public void ScopeTypeController_GetScopeTypes_Returns_Empty_List_Of_ScopeTypes_If_No_ScopeTypes()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetScopeTypes()).Returns(MockHelper.CreateEmptyScopeTypeReader());
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ // Act
+ var scopeTypes = scopeTypeController.GetScopeTypes();
+
+ // Assert
+ Assert.IsNotNull(scopeTypes);
+ Assert.AreEqual(0, scopeTypes.Count());
+ }
+
+ [Test]
+ public void ScopeTypeController_GetScopeTypes_Returns_List_Of_ScopeTypes()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetScopeTypes()).Returns(MockHelper.CreateValidScopeTypesReader(Constants.SCOPETYPE_ValidScopeTypeCount));
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ // Act
+ var scopeTypes = scopeTypeController.GetScopeTypes();
+
+ // Assert
+ Assert.AreEqual(Constants.SCOPETYPE_ValidScopeTypeCount, scopeTypes.Count());
+ }
+
+ [Test]
+ public void ScopeTypeController_UpdateScopeType_Throws_On_Null_ScopeType()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => scopeTypeController.UpdateScopeType(null));
+ }
+
+ [Test]
+ public void ScopeTypeController_UpdateScopeType_Throws_On_Negative_ScopeTypeId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
+ scopeType.ScopeType = Constants.SCOPETYPE_InValidScopeType;
+
+ Assert.Throws(() => scopeTypeController.UpdateScopeType(scopeType));
+ }
+
+ [Test]
+ public void ScopeTypeController_UpdateScopeType_Calls_DataService_On_Valid_ContentType()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var scopeTypeController = new ScopeTypeController(mockDataService.Object);
+
+ ScopeType scopeType = ContentTestHelper.CreateValidScopeType();
+ scopeType.ScopeTypeId = Constants.SCOPETYPE_UpdateScopeTypeId;
+ scopeType.ScopeType = Constants.SCOPETYPE_UpdateScopeType;
+
+ // Act
+ scopeTypeController.UpdateScopeType(scopeType);
+
+ // Assert
+ mockDataService.Verify(ds => ds.UpdateScopeType(scopeType));
+ }
+ }
+}
diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Content/TermControllerTests.cs b/DNN Platform/Tests/DotNetNuke.Tests.Content/TermControllerTests.cs
index 32a80100d0e..0b45b390503 100644
--- a/DNN Platform/Tests/DotNetNuke.Tests.Content/TermControllerTests.cs
+++ b/DNN Platform/Tests/DotNetNuke.Tests.Content/TermControllerTests.cs
@@ -2,614 +2,629 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
-namespace DotNetNuke.Tests.Content
-{
- using System;
- using System.Linq;
-
- using DotNetNuke.Common.Utilities;
- using DotNetNuke.Entities.Content;
- using DotNetNuke.Entities.Content.Data;
- using DotNetNuke.Entities.Content.Taxonomy;
- using DotNetNuke.Entities.Users;
- using DotNetNuke.Services.Cache;
- using DotNetNuke.Tests.Content.Mocks;
- using DotNetNuke.Tests.Utilities;
- using DotNetNuke.Tests.Utilities.Mocks;
- using Moq;
- using NUnit.Framework;
-
- ///
- /// Summary description for TermTests.
- ///
- [TestFixture]
- public class TermControllerTests
- {
- private Mock mockCache;
-
- [SetUp]
- public void SetUp()
- {
- Mock vocabularyController = MockHelper.CreateMockVocabularyController();
- MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
-
- // Register MockCachingProvider
- this.mockCache = MockComponentProvider.CreateNew();
- }
-
- [TearDown]
- public void TearDown()
- {
- MockComponentProvider.ResetContainer();
- }
-
- [Test]
- public void TermController_AddTerm_Throws_On_Null_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.AddTerm(null));
- }
-
- [Test]
- public void TermController_AddTerm_Throws_On_Invalid_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
- term.Name = Constants.TERM_InValidName;
-
- // Act, Arrange
- Assert.Throws(() => termController.AddTerm(term));
- }
-
- [Test]
- public void TermController_AddTerm_Throws_On_Negative_VocabularyId()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);
-
- // Act, Arrange
- Assert.Throws(() => termController.AddTerm(term));
- }
-
- [Test]
- public void TermController_AddTerm_Should_Call_DataService_AddSimpleTerm_If_Term_Is_Simple_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
-
- // Act
- int termId = termController.AddTerm(term);
-
- // Assert
- mockDataService.Verify(ds => ds.AddSimpleTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
- }
-
- [Test]
- public void TermController_AddTerm_Should_Call_DataService_AddHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
-
- // Act
- int termId = termController.AddTerm(term);
-
- // Assert
- mockDataService.Verify(ds => ds.AddHeirarchicalTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
- }
-
- [Test]
- public void TermController_AddTerm_Returns_Valid_Id_On_Valid_Term_If_Term_Is_Simple_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
- mockDataService.Setup(ds => ds.AddSimpleTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
-
- // Act
- int termId = termController.AddTerm(term);
-
- // Assert
- Assert.AreEqual(Constants.TERM_AddTermId, termId);
- }
-
- [Test]
- public void TermController_AddTerm_Sets_Valid_Id_On_Valid_Term_If_Term_Is_Simple_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
- mockDataService.Setup(ds => ds.AddSimpleTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
-
- // Act
- termController.AddTerm(term);
-
- // Assert
- Assert.AreEqual(Constants.TERM_AddTermId, term.TermId);
- }
-
- [Test]
- public void TermController_AddTerm_Returns_Valid_Id_On_Valid_Term_If_Term_Is_Heirarchical_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
- mockDataService.Setup(ds => ds.AddHeirarchicalTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
-
- Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
-
- // Act
- int termId = termController.AddTerm(term);
-
- // Assert
- Assert.AreEqual(Constants.TERM_AddTermId, termId);
- }
-
- [Test]
- public void TermController_AddTerm_Sets_Valid_Id_On_Valid_Term_If_Term_Is_Heirarchical_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
- mockDataService.Setup(ds => ds.AddHeirarchicalTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
-
- Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
-
- // Act
- termController.AddTerm(term);
-
- // Assert
- Assert.AreEqual(Constants.TERM_AddTermId, term.TermId);
- }
-
- [Test]
- public void TermController_AddTerm_Clears_Term_Cache_On_Valid_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
-
- // Act
- termController.AddTerm(term);
-
- // Assert
- this.mockCache.Verify(cache => cache.Remove(string.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
- }
-
- [Test]
- public void TermController_AddTermToContent_Throws_On_Null_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- ContentItem content = ContentTestHelper.CreateValidContentItem();
-
- // Act, Arrange
- Assert.Throws(() => termController.AddTermToContent(null, content));
- }
-
- [Test]
- public void TermController_AddTermToContent_Throws_On_Null_ContentItem()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
-
- // Act, Arrange
- Assert.Throws(() => termController.AddTermToContent(term, null));
- }
-
- [Test]
- public void TermController_AddTermToContent_Should_Call_DataService_If_Valid_Params()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- ContentItem content = ContentTestHelper.CreateValidContentItem();
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
-
- // Act
- termController.AddTermToContent(term, content);
-
- // Assert
- mockDataService.Verify(ds => ds.AddTermToContent(term, content));
- }
-
- [Test]
- public void TermController_DeleteTerm_Throws_On_Null_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.DeleteTerm(null));
- }
-
- [Test]
- public void TermController_DeleteTerm_Throws_On_Negative_TermId()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- var term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
- term.TermId = Null.NullInteger;
-
- // Act, Arrange
- Assert.Throws(() => termController.DeleteTerm(term));
- }
-
- [Test]
- public void TermController_DeleteTerm_Should_Call_DataService_DeleteSimpleTerm_If_Term_Is_Simple_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- var term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
- term.TermId = Constants.TERM_DeleteTermId;
-
- // Act
- termController.DeleteTerm(term);
-
- // Assert
- mockDataService.Verify(ds => ds.DeleteSimpleTerm(term));
- }
-
- [Test]
- public void TermController_DeleteTerm_Should_Call_DataService_DeleteHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- var term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
- term.TermId = Constants.TERM_DeleteTermId;
-
- // Act
- termController.DeleteTerm(term);
-
- // Assert
- mockDataService.Verify(ds => ds.DeleteHeirarchicalTerm(term));
- }
-
- [Test]
- public void TermController_DeleteTerm_Clears_Term_Cache_On_Valid_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- var term = new Term(Constants.VOCABULARY_ValidVocabularyId) { TermId = Constants.TERM_DeleteTermId };
-
- // Act
- termController.DeleteTerm(term);
-
- // Assert
- this.mockCache.Verify(cache => cache.Remove(string.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
- }
-
- [Test]
- public void TermController_GetTerm_Throws_On_Negative_TermId()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.GetTerm(Null.NullInteger));
- }
-
- [Test]
- public void TermController_GetTerm_Returns_Null_On_InValidTermId()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_InValidTermId)).Returns(MockHelper.CreateEmptyTermReader());
-
- var termController = new TermController(mockDataService.Object);
-
- // Act
- Term term = termController.GetTerm(Constants.TERM_InValidTermId);
-
- // Assert
- Assert.IsNull(term);
- }
-
- [Test]
- public void TermController_GetTerm_Calls_DataService()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId)).Returns(MockHelper.CreateValidTermReader());
- var termController = new TermController(mockDataService.Object);
-
- // Act
- Term term = termController.GetTerm(Constants.TERM_ValidTermId);
-
- // Assert
- mockDataService.Verify(ds => ds.GetTerm(Constants.TERM_ValidTermId));
- }
-
- [Test]
- public void TermController_GetTerm_Returns_Term_On_Valid_TermId()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId)).Returns(MockHelper.CreateValidTermReader());
-
- var termController = new TermController(mockDataService.Object);
-
- // Act
- var term = termController.GetTerm(Constants.TERM_ValidTermId);
-
- // Assert
- Assert.AreEqual(Constants.TERM_ValidTermId, term.TermId);
- Assert.AreEqual(Constants.TERM_ValidName, term.Name);
- }
-
- [Test]
- public void TermController_GetTermsByContent_Throws_On_Invalid_ContentItemId()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.GetTermsByContent(Null.NullInteger));
- }
-
- [Test]
- public void TermController_GetTermsByContent_Calls_DataService()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1)).Returns(MockHelper.CreateValidTermsReader(
- Constants.TERM_ValidCountForContent1,
- v => Constants.TERM_ValidVocabularyId,
- c => Constants.TERM_ValidContent1));
- var termController = new TermController(mockDataService.Object);
-
- // Act
- IQueryable terms = termController.GetTermsByContent(Constants.TERM_ValidContent1);
-
- // Assert
- mockDataService.Verify(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1));
- }
-
- [Test]
- public void TermController_GetTermsByContent_Returns_Terms_On_Valid_ContentItemId()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1)).Returns(MockHelper.CreateValidTermsReader(
- Constants.TERM_ValidCountForContent1,
- v => Constants.TERM_ValidVocabularyId,
- c => Constants.TERM_ValidContent1));
-
- var termController = new TermController(mockDataService.Object);
-
- // Act
- var terms = termController.GetTermsByContent(Constants.TERM_ValidContent1).ToList();
-
- // Assert
- Assert.AreEqual(Constants.TERM_ValidCountForContent1, terms.Count);
-
- for (int i = 0; i < Constants.TERM_ValidCountForContent1; i++)
- {
- Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId);
- Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name);
- }
- }
-
- [Test]
- public void TermController_GetTermsByVocabulary_Throws_On_Invalid_VocabularyId()
- {
- // Arrange
- var mockDataService = new Mock();
- MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.GetTermsByVocabulary(Null.NullInteger));
- }
-
- [Test]
- public void TermController_GetTermsByVocabulary_Returns_Terms_On_Valid_VocabularyId()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1)).Returns(MockHelper.CreateValidTermsReader(
- Constants.TERM_ValidCountForVocabulary1,
- v => Constants.TERM_ValidVocabulary1,
- c => Constants.TERM_ValidContent1));
- MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
-
- var termController = new TermController(mockDataService.Object);
-
- // Act
- var terms = termController.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1).ToList();
-
- // Assert
- Assert.AreEqual(Constants.TERM_ValidCountForVocabulary1, terms.Count);
-
- for (int i = 0; i < Constants.TERM_ValidCountForVocabulary1; i++)
- {
- Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId);
- Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name);
- }
- }
-
- [Test]
- public void TermController_GetTermsByVocabulary_Throws_On_Invalid_VocabularyName()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.GetTermsByVocabulary(Null.NullString));
- }
-
- [Test]
- public void TermController_RemoveTermsFromContent_Throws_On_Null_ContentItem()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.RemoveTermsFromContent(null));
- }
-
- [Test]
- public void TermController_RemoveTermsFromContent_Should_Call_DataService_If_Valid_Params()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- ContentItem content = ContentTestHelper.CreateValidContentItem();
-
- // Act
- termController.RemoveTermsFromContent(content);
-
- // Assert
- mockDataService.Verify(ds => ds.RemoveTermsFromContent(content));
- }
-
- [Test]
- public void TermController_UpdateTerm_Throws_On_Null_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => termController.UpdateTerm(null));
- }
-
- [Test]
- public void TermController_UpdateTerm_Throws_On_Negative_TermId()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);
-
- // Act, Arrange
- Assert.Throws(() => termController.UpdateTerm(term));
- }
-
- [Test]
- public void TermController_UpdateTerm_Throws_On_Invalid_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
- term.Name = Constants.TERM_InValidName;
-
- // Act, Arrange
- Assert.Throws(() => termController.UpdateTerm(term));
- }
-
- [Test]
- public void TermController_UpdateTerm_Throws_On_Negative_VocabularyId()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);
-
- // Act, Arrange
- Assert.Throws(() => termController.UpdateTerm(term));
- }
-
- [Test]
- public void TermController_UpdateTerm_Should_Call_DataService_UpdateSimpleTerm_If_Term_Is_Simple_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
- term.TermId = Constants.TERM_UpdateTermId;
- term.Name = Constants.TERM_UpdateName;
- term.Weight = Constants.TERM_UpdateWeight;
-
- // Act
- termController.UpdateTerm(term);
-
- // Assert
- mockDataService.Verify(ds => ds.UpdateSimpleTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
- }
-
- [Test]
- public void TermController_UpdateTerm_Should_Call_DataService_UpdateHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
- term.TermId = Constants.TERM_UpdateTermId;
- term.Name = Constants.TERM_UpdateName;
- term.Weight = Constants.TERM_UpdateWeight;
-
- // Act
- termController.UpdateTerm(term);
-
- // Assert
- mockDataService.Verify(ds => ds.UpdateHeirarchicalTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
- }
-
- [Test]
- public void TermController_UpdateTerm_Clears_Term_Cache_On_Valid_Term()
- {
- // Arrange
- var mockDataService = new Mock();
- var termController = new TermController(mockDataService.Object);
-
- Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
- term.TermId = Constants.TERM_UpdateTermId;
- term.Name = Constants.TERM_UpdateName;
- term.Weight = Constants.TERM_UpdateWeight;
-
- // Act
- termController.UpdateTerm(term);
-
- // Assert
- this.mockCache.Verify(cache => cache.Remove(string.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
- }
- }
-}
+namespace DotNetNuke.Tests.Content
+{
+ using System;
+ using System.Linq;
+
+ using DotNetNuke.Abstractions;
+ using DotNetNuke.Abstractions.Application;
+ using DotNetNuke.Common;
+ using DotNetNuke.Common.Utilities;
+ using DotNetNuke.Entities.Content;
+ using DotNetNuke.Entities.Content.Data;
+ using DotNetNuke.Entities.Content.Taxonomy;
+ using DotNetNuke.Entities.Controllers;
+ using DotNetNuke.Entities.Users;
+ using DotNetNuke.Services.Cache;
+ using DotNetNuke.Tests.Content.Mocks;
+ using DotNetNuke.Tests.Utilities;
+ using DotNetNuke.Tests.Utilities.Mocks;
+
+ using Microsoft.Extensions.DependencyInjection;
+
+ using Moq;
+
+ using NUnit.Framework;
+
+ ///
+ /// Summary description for TermTests.
+ ///
+ [TestFixture]
+ public class TermControllerTests
+ {
+ private Mock mockCache;
+
+ [SetUp]
+ public void SetUp()
+ {
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddTransient(container => Mock.Of());
+ serviceCollection.AddTransient(container => new DotNetNuke.Application.ApplicationStatusInfo(Mock.Of()));
+ serviceCollection.AddTransient();
+ Globals.DependencyProvider = serviceCollection.BuildServiceProvider();
+
+ Mock vocabularyController = MockHelper.CreateMockVocabularyController();
+ MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
+
+ // Register MockCachingProvider
+ this.mockCache = MockComponentProvider.CreateNew();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Globals.DependencyProvider = null;
+ MockComponentProvider.ResetContainer();
+ }
+
+ [Test]
+ public void TermController_AddTerm_Throws_On_Null_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.AddTerm(null));
+ }
+
+ [Test]
+ public void TermController_AddTerm_Throws_On_Invalid_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+ term.Name = Constants.TERM_InValidName;
+
+ // Act, Arrange
+ Assert.Throws(() => termController.AddTerm(term));
+ }
+
+ [Test]
+ public void TermController_AddTerm_Throws_On_Negative_VocabularyId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.AddTerm(term));
+ }
+
+ [Test]
+ public void TermController_AddTerm_Should_Call_DataService_AddSimpleTerm_If_Term_Is_Simple_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+
+ // Act
+ int termId = termController.AddTerm(term);
+
+ // Assert
+ mockDataService.Verify(ds => ds.AddSimpleTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
+ }
+
+ [Test]
+ public void TermController_AddTerm_Should_Call_DataService_AddHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
+
+ // Act
+ int termId = termController.AddTerm(term);
+
+ // Assert
+ mockDataService.Verify(ds => ds.AddHeirarchicalTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
+ }
+
+ [Test]
+ public void TermController_AddTerm_Returns_Valid_Id_On_Valid_Term_If_Term_Is_Simple_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+ mockDataService.Setup(ds => ds.AddSimpleTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+
+ // Act
+ int termId = termController.AddTerm(term);
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_AddTermId, termId);
+ }
+
+ [Test]
+ public void TermController_AddTerm_Sets_Valid_Id_On_Valid_Term_If_Term_Is_Simple_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+ mockDataService.Setup(ds => ds.AddSimpleTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+
+ // Act
+ termController.AddTerm(term);
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_AddTermId, term.TermId);
+ }
+
+ [Test]
+ public void TermController_AddTerm_Returns_Valid_Id_On_Valid_Term_If_Term_Is_Heirarchical_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+ mockDataService.Setup(ds => ds.AddHeirarchicalTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
+
+ Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
+
+ // Act
+ int termId = termController.AddTerm(term);
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_AddTermId, termId);
+ }
+
+ [Test]
+ public void TermController_AddTerm_Sets_Valid_Id_On_Valid_Term_If_Term_Is_Heirarchical_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+ mockDataService.Setup(ds => ds.AddHeirarchicalTerm(It.IsAny(), It.IsAny())).Returns(Constants.TERM_AddTermId);
+
+ Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
+
+ // Act
+ termController.AddTerm(term);
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_AddTermId, term.TermId);
+ }
+
+ [Test]
+ public void TermController_AddTerm_Clears_Term_Cache_On_Valid_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+
+ // Act
+ termController.AddTerm(term);
+
+ // Assert
+ this.mockCache.Verify(cache => cache.Remove(string.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
+ }
+
+ [Test]
+ public void TermController_AddTermToContent_Throws_On_Null_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ ContentItem content = ContentTestHelper.CreateValidContentItem();
+
+ // Act, Arrange
+ Assert.Throws(() => termController.AddTermToContent(null, content));
+ }
+
+ [Test]
+ public void TermController_AddTermToContent_Throws_On_Null_ContentItem()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.AddTermToContent(term, null));
+ }
+
+ [Test]
+ public void TermController_AddTermToContent_Should_Call_DataService_If_Valid_Params()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ ContentItem content = ContentTestHelper.CreateValidContentItem();
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+
+ // Act
+ termController.AddTermToContent(term, content);
+
+ // Assert
+ mockDataService.Verify(ds => ds.AddTermToContent(term, content));
+ }
+
+ [Test]
+ public void TermController_DeleteTerm_Throws_On_Null_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.DeleteTerm(null));
+ }
+
+ [Test]
+ public void TermController_DeleteTerm_Throws_On_Negative_TermId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ var term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+ term.TermId = Null.NullInteger;
+
+ // Act, Arrange
+ Assert.Throws(() => termController.DeleteTerm(term));
+ }
+
+ [Test]
+ public void TermController_DeleteTerm_Should_Call_DataService_DeleteSimpleTerm_If_Term_Is_Simple_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ var term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+ term.TermId = Constants.TERM_DeleteTermId;
+
+ // Act
+ termController.DeleteTerm(term);
+
+ // Assert
+ mockDataService.Verify(ds => ds.DeleteSimpleTerm(term));
+ }
+
+ [Test]
+ public void TermController_DeleteTerm_Should_Call_DataService_DeleteHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ var term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
+ term.TermId = Constants.TERM_DeleteTermId;
+
+ // Act
+ termController.DeleteTerm(term);
+
+ // Assert
+ mockDataService.Verify(ds => ds.DeleteHeirarchicalTerm(term));
+ }
+
+ [Test]
+ public void TermController_DeleteTerm_Clears_Term_Cache_On_Valid_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ var term = new Term(Constants.VOCABULARY_ValidVocabularyId) { TermId = Constants.TERM_DeleteTermId };
+
+ // Act
+ termController.DeleteTerm(term);
+
+ // Assert
+ this.mockCache.Verify(cache => cache.Remove(string.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
+ }
+
+ [Test]
+ public void TermController_GetTerm_Throws_On_Negative_TermId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.GetTerm(Null.NullInteger));
+ }
+
+ [Test]
+ public void TermController_GetTerm_Returns_Null_On_InValidTermId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_InValidTermId)).Returns(MockHelper.CreateEmptyTermReader());
+
+ var termController = new TermController(mockDataService.Object);
+
+ // Act
+ Term term = termController.GetTerm(Constants.TERM_InValidTermId);
+
+ // Assert
+ Assert.IsNull(term);
+ }
+
+ [Test]
+ public void TermController_GetTerm_Calls_DataService()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId)).Returns(MockHelper.CreateValidTermReader());
+ var termController = new TermController(mockDataService.Object);
+
+ // Act
+ Term term = termController.GetTerm(Constants.TERM_ValidTermId);
+
+ // Assert
+ mockDataService.Verify(ds => ds.GetTerm(Constants.TERM_ValidTermId));
+ }
+
+ [Test]
+ public void TermController_GetTerm_Returns_Term_On_Valid_TermId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId)).Returns(MockHelper.CreateValidTermReader());
+
+ var termController = new TermController(mockDataService.Object);
+
+ // Act
+ var term = termController.GetTerm(Constants.TERM_ValidTermId);
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_ValidTermId, term.TermId);
+ Assert.AreEqual(Constants.TERM_ValidName, term.Name);
+ }
+
+ [Test]
+ public void TermController_GetTermsByContent_Throws_On_Invalid_ContentItemId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.GetTermsByContent(Null.NullInteger));
+ }
+
+ [Test]
+ public void TermController_GetTermsByContent_Calls_DataService()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1)).Returns(MockHelper.CreateValidTermsReader(
+ Constants.TERM_ValidCountForContent1,
+ v => Constants.TERM_ValidVocabularyId,
+ c => Constants.TERM_ValidContent1));
+ var termController = new TermController(mockDataService.Object);
+
+ // Act
+ IQueryable terms = termController.GetTermsByContent(Constants.TERM_ValidContent1);
+
+ // Assert
+ mockDataService.Verify(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1));
+ }
+
+ [Test]
+ public void TermController_GetTermsByContent_Returns_Terms_On_Valid_ContentItemId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetTermsByContent(Constants.TERM_ValidContent1)).Returns(MockHelper.CreateValidTermsReader(
+ Constants.TERM_ValidCountForContent1,
+ v => Constants.TERM_ValidVocabularyId,
+ c => Constants.TERM_ValidContent1));
+
+ var termController = new TermController(mockDataService.Object);
+
+ // Act
+ var terms = termController.GetTermsByContent(Constants.TERM_ValidContent1).ToList();
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_ValidCountForContent1, terms.Count);
+
+ for (int i = 0; i < Constants.TERM_ValidCountForContent1; i++)
+ {
+ Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId);
+ Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name);
+ }
+ }
+
+ [Test]
+ public void TermController_GetTermsByVocabulary_Throws_On_Invalid_VocabularyId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.GetTermsByVocabulary(Null.NullInteger));
+ }
+
+ [Test]
+ public void TermController_GetTermsByVocabulary_Returns_Terms_On_Valid_VocabularyId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1)).Returns(MockHelper.CreateValidTermsReader(
+ Constants.TERM_ValidCountForVocabulary1,
+ v => Constants.TERM_ValidVocabulary1,
+ c => Constants.TERM_ValidContent1));
+ MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
+
+ var termController = new TermController(mockDataService.Object);
+
+ // Act
+ var terms = termController.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1).ToList();
+
+ // Assert
+ Assert.AreEqual(Constants.TERM_ValidCountForVocabulary1, terms.Count);
+
+ for (int i = 0; i < Constants.TERM_ValidCountForVocabulary1; i++)
+ {
+ Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId);
+ Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name);
+ }
+ }
+
+ [Test]
+ public void TermController_GetTermsByVocabulary_Throws_On_Invalid_VocabularyName()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.GetTermsByVocabulary(Null.NullString));
+ }
+
+ [Test]
+ public void TermController_RemoveTermsFromContent_Throws_On_Null_ContentItem()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.RemoveTermsFromContent(null));
+ }
+
+ [Test]
+ public void TermController_RemoveTermsFromContent_Should_Call_DataService_If_Valid_Params()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ ContentItem content = ContentTestHelper.CreateValidContentItem();
+
+ // Act
+ termController.RemoveTermsFromContent(content);
+
+ // Assert
+ mockDataService.Verify(ds => ds.RemoveTermsFromContent(content));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Throws_On_Null_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.UpdateTerm(null));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Throws_On_Negative_TermId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.UpdateTerm(term));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Throws_On_Invalid_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+ term.Name = Constants.TERM_InValidName;
+
+ // Act, Arrange
+ Assert.Throws(() => termController.UpdateTerm(term));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Throws_On_Negative_VocabularyId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);
+
+ // Act, Arrange
+ Assert.Throws(() => termController.UpdateTerm(term));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Should_Call_DataService_UpdateSimpleTerm_If_Term_Is_Simple_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+ term.TermId = Constants.TERM_UpdateTermId;
+ term.Name = Constants.TERM_UpdateName;
+ term.Weight = Constants.TERM_UpdateWeight;
+
+ // Act
+ termController.UpdateTerm(term);
+
+ // Assert
+ mockDataService.Verify(ds => ds.UpdateSimpleTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Should_Call_DataService_UpdateHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);
+ term.TermId = Constants.TERM_UpdateTermId;
+ term.Name = Constants.TERM_UpdateName;
+ term.Weight = Constants.TERM_UpdateWeight;
+
+ // Act
+ termController.UpdateTerm(term);
+
+ // Assert
+ mockDataService.Verify(ds => ds.UpdateHeirarchicalTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
+ }
+
+ [Test]
+ public void TermController_UpdateTerm_Clears_Term_Cache_On_Valid_Term()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var termController = new TermController(mockDataService.Object);
+
+ Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);
+ term.TermId = Constants.TERM_UpdateTermId;
+ term.Name = Constants.TERM_UpdateName;
+ term.Weight = Constants.TERM_UpdateWeight;
+
+ // Act
+ termController.UpdateTerm(term);
+
+ // Assert
+ this.mockCache.Verify(cache => cache.Remove(string.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
+ }
+ }
+}
diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Content/VocabularyControllerTests.cs b/DNN Platform/Tests/DotNetNuke.Tests.Content/VocabularyControllerTests.cs
index 86a1ad450f9..c141ad0f645 100644
--- a/DNN Platform/Tests/DotNetNuke.Tests.Content/VocabularyControllerTests.cs
+++ b/DNN Platform/Tests/DotNetNuke.Tests.Content/VocabularyControllerTests.cs
@@ -2,322 +2,336 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
-namespace DotNetNuke.Tests.Content
-{
- using System;
- using System.Linq;
-
- using DotNetNuke.Common.Utilities;
- using DotNetNuke.Entities.Content.Data;
- using DotNetNuke.Entities.Content.Taxonomy;
- using DotNetNuke.Services.Cache;
- using DotNetNuke.Tests.Content.Mocks;
- using DotNetNuke.Tests.Utilities;
- using DotNetNuke.Tests.Utilities.Mocks;
- using Moq;
- using NUnit.Framework;
-
- ///
- /// Summary description for VocabularyTests.
- ///
- [TestFixture]
- public class VocabularyControllerTests
- {
- private Mock mockCache;
-
- [SetUp]
- public void SetUp()
- {
- // Register MockCachingProvider
- this.mockCache = MockComponentProvider.CreateNew();
- MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
- }
-
- [TearDown]
- public void TearDown()
- {
- MockComponentProvider.ResetContainer();
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Throws_On_Null_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.AddVocabulary(null));
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Throws_On_Invalid_Name()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.Name = Constants.VOCABULARY_InValidName;
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.AddVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Throws_On_Negative_ScopeTypeID()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.ScopeTypeId = Null.NullInteger;
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.AddVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Calls_DataService_On_Valid_Arguments()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
-
- // Act
- int vocabularyId = vocabularyController.AddVocabulary(vocabulary);
-
- // Assert
- mockDataService.Verify(ds => ds.AddVocabulary(vocabulary, It.IsAny()));
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Returns_ValidId_On_Valid_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny(), It.IsAny())).Returns(Constants.VOCABULARY_AddVocabularyId);
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
-
- // Act
- int vocabularyId = vocabularyController.AddVocabulary(vocabulary);
-
- // Assert
- Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabularyId);
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Sets_ValidId_On_Valid_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny(), It.IsAny())).Returns(Constants.VOCABULARY_AddVocabularyId);
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
-
- // Act
- vocabularyController.AddVocabulary(vocabulary);
-
- // Assert
- Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabulary.VocabularyId);
- }
-
- [Test]
- public void VocabularyController_AddVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
-
- // Act
- vocabularyController.AddVocabulary(vocabulary);
-
- // Assert
- this.mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
- }
-
- [Test]
- public void VocabularyController_DeleteVocabulary_Throws_On_Null_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.DeleteVocabulary(null));
- }
-
- [Test]
- public void VocabularyController_DeleteVocabulary_Throws_On_Negative_VocabularyId()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = new Vocabulary();
- vocabulary.VocabularyId = Null.NullInteger;
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.DeleteVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_DeleteVocabulary_Calls_DataService_On_Valid_Arguments()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.VocabularyId = Constants.VOCABULARY_ValidVocabularyId;
-
- // Act
- vocabularyController.DeleteVocabulary(vocabulary);
-
- // Assert
- mockDataService.Verify(ds => ds.DeleteVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_DeleteVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.VocabularyId = Constants.VOCABULARY_ValidVocabularyId;
-
- // Act
- vocabularyController.DeleteVocabulary(vocabulary);
-
- // Assert
- this.mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
- }
-
- [Test]
- public void VocabularyController_GetVocabularies_Calls_DataService()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetVocabularies()).Returns(MockHelper.CreateValidVocabulariesReader(Constants.VOCABULARY_ValidCount));
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- // Act
- IQueryable vocabularys = vocabularyController.GetVocabularies();
-
- // Assert
- mockDataService.Verify(ds => ds.GetVocabularies());
- }
-
- [Test]
- public void VocabularyController_GetVocabularies_Returns_List_Of_Vocabularies()
- {
- // Arrange
- var mockDataService = new Mock();
- mockDataService.Setup(ds => ds.GetVocabularies()).Returns(MockHelper.CreateValidVocabulariesReader(Constants.VOCABULARY_ValidCount));
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- // Act
- IQueryable vocabularys = vocabularyController.GetVocabularies();
-
- // Assert
- Assert.AreEqual(Constants.VOCABULARY_ValidCount, vocabularys.Count());
- }
-
- [Test]
- public void VocabularyController_UpdateVocabulary_Throws_On_Null_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.UpdateVocabulary(null));
- }
-
- [Test]
- public void VocabularyController_UpdateVocabulary_Throws_On_Negative_VocabularyId()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.VocabularyId = Null.NullInteger;
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.UpdateVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_UpdateVocabulary_Throws_On_Invalid_Name()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.Name = Constants.VOCABULARY_InValidName;
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.UpdateVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_UpdateVocabulary_Throws_On_Negative_ScopeTypeID()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.ScopeTypeId = Null.NullInteger;
-
- // Act, Arrange
- Assert.Throws(() => vocabularyController.UpdateVocabulary(vocabulary));
- }
-
- [Test]
- public void VocabularyController_UpdateVocabulary_Calls_DataService_On_Valid_Arguments()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.VocabularyId = Constants.VOCABULARY_UpdateVocabularyId;
-
- // Act
- vocabularyController.UpdateVocabulary(vocabulary);
-
- // Assert
- mockDataService.Verify(ds => ds.UpdateVocabulary(vocabulary, It.IsAny()));
- }
-
- [Test]
- public void VocabularyController__UpdateVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
- {
- // Arrange
- var mockDataService = new Mock();
- var vocabularyController = new VocabularyController(mockDataService.Object);
-
- Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
- vocabulary.VocabularyId = Constants.VOCABULARY_UpdateVocabularyId;
-
- // Act
- vocabularyController.UpdateVocabulary(vocabulary);
-
- // Assert
- this.mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
- }
- }
-}
+namespace DotNetNuke.Tests.Content
+{
+ using System;
+ using System.Linq;
+ using DotNetNuke.Abstractions;
+ using DotNetNuke.Common;
+ using DotNetNuke.Abstractions.Application;
+ using DotNetNuke.Common.Utilities;
+ using DotNetNuke.Entities.Content.Data;
+ using DotNetNuke.Entities.Content.Taxonomy;
+ using DotNetNuke.Entities.Controllers;
+ using DotNetNuke.Services.Cache;
+ using DotNetNuke.Tests.Content.Mocks;
+ using DotNetNuke.Tests.Utilities;
+ using DotNetNuke.Tests.Utilities.Mocks;
+
+ using Microsoft.Extensions.DependencyInjection;
+
+ using Moq;
+
+ using NUnit.Framework;
+
+ ///
+ /// Summary description for VocabularyTests.
+ ///
+ [TestFixture]
+ public class VocabularyControllerTests
+ {
+ private Mock mockCache;
+
+ [SetUp]
+ public void SetUp()
+ {
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddTransient(container => Mock.Of());
+ serviceCollection.AddTransient(container => new DotNetNuke.Application.ApplicationStatusInfo(Mock.Of()));
+ serviceCollection.AddTransient();
+ Globals.DependencyProvider = serviceCollection.BuildServiceProvider();
+
+ // Register MockCachingProvider
+ this.mockCache = MockComponentProvider.CreateNew();
+ MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(string.Empty);
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Globals.DependencyProvider = null;
+ MockComponentProvider.ResetContainer();
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Throws_On_Null_Vocabulary()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => vocabularyController.AddVocabulary(null));
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Throws_On_Invalid_Name()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+ vocabulary.Name = Constants.VOCABULARY_InValidName;
+
+ // Act, Arrange
+ Assert.Throws(() => vocabularyController.AddVocabulary(vocabulary));
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Throws_On_Negative_ScopeTypeID()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+ vocabulary.ScopeTypeId = Null.NullInteger;
+
+ // Act, Arrange
+ Assert.Throws(() => vocabularyController.AddVocabulary(vocabulary));
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Calls_DataService_On_Valid_Arguments()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+
+ // Act
+ int vocabularyId = vocabularyController.AddVocabulary(vocabulary);
+
+ // Assert
+ mockDataService.Verify(ds => ds.AddVocabulary(vocabulary, It.IsAny()));
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Returns_ValidId_On_Valid_Vocabulary()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny(), It.IsAny())).Returns(Constants.VOCABULARY_AddVocabularyId);
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+
+ // Act
+ int vocabularyId = vocabularyController.AddVocabulary(vocabulary);
+
+ // Assert
+ Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabularyId);
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Sets_ValidId_On_Valid_Vocabulary()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny(), It.IsAny())).Returns(Constants.VOCABULARY_AddVocabularyId);
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+
+ // Act
+ vocabularyController.AddVocabulary(vocabulary);
+
+ // Assert
+ Assert.AreEqual(Constants.VOCABULARY_AddVocabularyId, vocabulary.VocabularyId);
+ }
+
+ [Test]
+ public void VocabularyController_AddVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+
+ // Act
+ vocabularyController.AddVocabulary(vocabulary);
+
+ // Assert
+ this.mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
+ }
+
+ [Test]
+ public void VocabularyController_DeleteVocabulary_Throws_On_Null_Vocabulary()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ // Act, Arrange
+ Assert.Throws(() => vocabularyController.DeleteVocabulary(null));
+ }
+
+ [Test]
+ public void VocabularyController_DeleteVocabulary_Throws_On_Negative_VocabularyId()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = new Vocabulary();
+ vocabulary.VocabularyId = Null.NullInteger;
+
+ // Act, Arrange
+ Assert.Throws(() => vocabularyController.DeleteVocabulary(vocabulary));
+ }
+
+ [Test]
+ public void VocabularyController_DeleteVocabulary_Calls_DataService_On_Valid_Arguments()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+ vocabulary.VocabularyId = Constants.VOCABULARY_ValidVocabularyId;
+
+ // Act
+ vocabularyController.DeleteVocabulary(vocabulary);
+
+ // Assert
+ mockDataService.Verify(ds => ds.DeleteVocabulary(vocabulary));
+ }
+
+ [Test]
+ public void VocabularyController_DeleteVocabulary_Clears_Vocabulary_Cache_On_Valid_Vocabulary()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
+ vocabulary.VocabularyId = Constants.VOCABULARY_ValidVocabularyId;
+
+ // Act
+ vocabularyController.DeleteVocabulary(vocabulary);
+
+ // Assert
+ this.mockCache.Verify(cache => cache.Remove(Constants.VOCABULARY_CacheKey));
+ }
+
+ [Test]
+ public void VocabularyController_GetVocabularies_Calls_DataService()
+ {
+ // Arrange
+ var mockDataService = new Mock();
+ mockDataService.Setup(ds => ds.GetVocabularies()).Returns(MockHelper.CreateValidVocabulariesReader(Constants.VOCABULARY_ValidCount));
+ var vocabularyController = new VocabularyController(mockDataService.Object);
+
+ // Act
+ IQueryable vocabularys = vocabularyController.GetVocabularies();
+
+ // Assert
+ mockDataService.Verify(ds => ds.GetVocabularies());
+ }
+
+ [Test]
+ public void VocabularyController_GetVocabularies_Returns_List_Of_Vocabularies()
+ {
+ // Arrange
+ var mockDataService = new Mock