-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4824 from berkarslan-xo/bugfix/Issue-4823
Custom Analyzer types generate System.MissingMethodException
- Loading branch information
Showing
5 changed files
with
109 additions
and
2 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
36 changes: 36 additions & 0 deletions
36
DNN Platform/Tests/DotNetNuke.Tests.Core/Framework/ReflectionTests.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,36 @@ | ||
namespace DotNetNuke.Tests.Core.Framework | ||
{ | ||
using System.Text; | ||
using DotNetNuke.Framework; | ||
using NUnit.Framework; | ||
|
||
public class ReflectionTests | ||
{ | ||
[Test] | ||
public void CreateInstance_WithArgs_WorksCorrectly() | ||
{ | ||
// Arrange | ||
var typeToCreate = typeof(StringBuilder); | ||
var argToPass = new object[] { "one" }; | ||
|
||
// Act | ||
var result = (StringBuilder)Reflection.CreateInstance(typeToCreate, argToPass); | ||
|
||
// Assert | ||
Assert.AreEqual("one", result.ToString()); | ||
} | ||
|
||
[Test] | ||
public void CreateInstance_WithoutArgs_WorksCorrectly() | ||
{ | ||
// Arrange | ||
var typeToCreate = typeof(StringBuilder); | ||
|
||
// Act | ||
var result = (StringBuilder)Reflection.CreateInstance(typeToCreate); | ||
|
||
// Assert | ||
Assert.AreEqual(string.Empty, result.ToString()); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...atform/Tests/DotNetNuke.Tests.Core/Services/Search/Internals/LuceneControllerImplTests.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,54 @@ | ||
namespace DotNetNuke.Tests.Core.Services.Search.Internals | ||
{ | ||
using System.Data; | ||
using DotNetNuke.Abstractions; | ||
using DotNetNuke.Abstractions.Application; | ||
using DotNetNuke.Common; | ||
using DotNetNuke.Common.Utilities; | ||
using DotNetNuke.Services.Search.Internals; | ||
using DotNetNuke.Tests.Utilities.Mocks; | ||
using Lucene.Net.Analysis.Cz; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
public class LuceneControllerImplTests | ||
{ | ||
[Test] | ||
public void GetCustomAnalyzer_WithTheProvidedAnalyzer_ReturnsTheAnalyzerCorrectly() | ||
{ | ||
// Arrange | ||
const string HostSettingsTableName = "HostSettings"; | ||
const string SettingNameColumnName = "SettingName"; | ||
const string SettingValueColumnName = "SettingValue"; | ||
const string SettingIsSecureColumnName = "SettingIsSecure"; | ||
const string CustomAnalyzerCacheKeyName = "Search_CustomAnalyzer"; | ||
const string CzechAnalyzerTypeName = "Lucene.Net.Analysis.Cz.CzechAnalyzer, Lucene.Net.Contrib.Analyzers"; | ||
var services = new ServiceCollection(); | ||
var mockData = MockComponentProvider.CreateDataProvider(); | ||
var hostSettings = new DataTable(HostSettingsTableName); | ||
var nameCol = hostSettings.Columns.Add(SettingNameColumnName); | ||
hostSettings.Columns.Add(SettingValueColumnName); | ||
hostSettings.Columns.Add(SettingIsSecureColumnName); | ||
hostSettings.PrimaryKey = new[] { nameCol }; | ||
hostSettings.Rows.Add(CustomAnalyzerCacheKeyName, CzechAnalyzerTypeName, true); | ||
mockData.Setup(c => c.GetHostSettings()).Returns(hostSettings.CreateDataReader()); | ||
var mockedApplicationStatusInfo = new Mock<IApplicationStatusInfo>(); | ||
mockedApplicationStatusInfo.Setup(s => s.Status).Returns(UpgradeStatus.Install); | ||
mockedApplicationStatusInfo.Setup(s => s.ApplicationMapPath).Returns(string.Empty); | ||
services.AddTransient(container => Mock.Of<IHostSettingsService>()); | ||
services.AddTransient(container => mockedApplicationStatusInfo.Object); | ||
services.AddTransient(container => Mock.Of<INavigationManager>()); | ||
Globals.DependencyProvider = services.BuildServiceProvider(); | ||
MockComponentProvider.CreateDataCacheProvider(); | ||
DataCache.ClearCache(); | ||
var luceneController = new LuceneControllerImpl(); | ||
|
||
// Act | ||
var analyzer = luceneController.GetCustomAnalyzer(); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<CzechAnalyzer>(analyzer); | ||
} | ||
} | ||
} |