-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
2,834 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
obj/ | ||
bin/ | ||
.vs/ |
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,67 @@ | ||
using edcClientDotnet; | ||
using edcClientDotnet.Injection; | ||
using edcClientDotnet.internalImpl; | ||
using edcClientDotnet.internalImpl.http; | ||
using edcClientDotnet.internalImpl.io; | ||
using edcClientDotnet.internalImpl.model; | ||
using edcClientDotnet.internalImpl.util; | ||
using edcClientDotnet.io; | ||
using edcClientDotnet.model; | ||
using edcClientDotnet.utils; | ||
using edcClientDotnetTest.internalImpl; | ||
using edcClientDotnet.internalImpl.factory; | ||
using edcClientDotnet.factory; | ||
|
||
namespace edcClientDotnetTest | ||
{ | ||
public abstract class CommonBase | ||
{ | ||
private IEdcReader? _edcReader; | ||
|
||
protected HttpClientDotnet CreateHttpClient() { return new HttpClientDotnet(); } | ||
|
||
protected IClientConfiguration CreateClientConfig() { return new ClientConfigurationImpl(); } | ||
|
||
protected IClientConfiguration CreateClientConfiguration() | ||
{ | ||
IClientConfiguration clientConfiguration = new ClientConfigurationImpl(); | ||
clientConfiguration.ServerUrl = Constants.SERVER_URL; | ||
return clientConfiguration; | ||
} | ||
|
||
protected IKeyUtil CreateKeyBuilder() { return new KeyUtilImpl(); } | ||
|
||
protected IEdcReader CreateEdcReader() | ||
{ | ||
if (_edcReader != null) | ||
{ | ||
return _edcReader; | ||
} | ||
HttpClientDotnet httpClient = CreateHttpClient(); | ||
IClientConfiguration clientConfiguration = CreateClientConfiguration(); | ||
IKeyUtil keyUtil = CreateKeyBuilder(); | ||
Startup.ConfigureServices(); | ||
ContextItemFactory? contextItemFactory = new ContextItemFactory(); | ||
DocumentationItemFactory? documentationItemFactory = new DocumentationItemFactory(); | ||
IInformationFactory? informationFactory = new InformationFactory(); | ||
I18NFactory? i18nFactory = new I18NFactory(); | ||
_edcReader = new HttpReaderImpl(httpClient, clientConfiguration, keyUtil, contextItemFactory, documentationItemFactory, informationFactory, i18nFactory); | ||
|
||
return _edcReader; | ||
} | ||
|
||
protected IUrlUtil CreateUrlBuilder() { return new UrlUtilImpl(CreateClientConfiguration()); } | ||
|
||
protected ITranslationUtil CreateTranslationUtil() { return new TranslationUtilImpl(); } | ||
|
||
protected IDocumentationManager CreateDocumentationManager() { return new DocumentationManagerImpl(CreateEdcReader(), CreateKeyBuilder()); } | ||
|
||
protected IInformationManager CreateInformationManager(){ return new InformationManagerImpl(CreateEdcReader()); } | ||
|
||
protected ITranslationManager CreateTranslationManager() { return new TranslationManagerImpl(CreateEdcReader(), CreateTranslationUtil()); } | ||
|
||
protected I18NContentImpl CreateIi8nContent() { return new I18NContentImpl(); } | ||
|
||
protected IEdcClient CreateEdcClient() { return new EdcClientImpl(CreateClientConfiguration(), CreateDocumentationManager(), CreateUrlBuilder(), CreateTranslationManager(), CreateInformationManager()); } | ||
} | ||
} |
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,102 @@ | ||
using edcClientDotnet; | ||
using edcClientDotnet.model; | ||
using Newtonsoft.Json; | ||
using edcClientDotnetTest.internalImpl; | ||
|
||
namespace edcClientDotnetTest; | ||
|
||
[TestClass] | ||
public class EdcClientSingletonTest | ||
{ | ||
private static string DEFAULT_URL = "https://demo.easydoccontents.com/help/home"; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
|
||
{ | ||
EdcClientSingleton.GetInstance().SetServerUrl(Constants.SERVER_URL); | ||
try | ||
{ | ||
EdcClientSingleton.GetInstance().SetWebHelpContextUrl("help"); | ||
EdcClientSingleton.GetInstance().SetDocumentationContextUrl("doc"); | ||
} | ||
catch (InvalidUrlException e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetUrl() | ||
{ | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", "en"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/context/edchelp/fr.techad.edc/help.center/en/0", url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetUrlWithForceReload() | ||
{ | ||
EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", "en"); | ||
EdcClientSingleton.GetInstance().ForceReload(); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", "en"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/context/edchelp/fr.techad.edc/help.center/en/0", url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetDefaultUrlErrorOnMainKey() | ||
{ | ||
EdcClientSingleton.GetInstance().ForceReload(); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl(null, "help.center", "en"); | ||
Assert.AreEqual(DEFAULT_URL, url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetNullUrlErrorOnSubKey() | ||
{ | ||
EdcClientSingleton.GetInstance().ForceReload(); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", null, "en"); | ||
Assert.AreEqual(DEFAULT_URL, url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetDefaultUrlOnLanguageCode() | ||
{ | ||
EdcClientSingleton.GetInstance().ForceReload(); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", null); | ||
Assert.AreEqual(DEFAULT_URL, url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetUrlWithNewWebHelpContext() | ||
{ | ||
EdcClientSingleton.GetInstance().SetWebHelpContextUrl("help"); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", "en"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/context/edchelp/fr.techad.edc/help.center/en/0", url); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(InvalidUrlException), | ||
"The WebHelp context is null")] | ||
public void ShouldThrowsExceptionOnNullWebHelpContext() | ||
{ | ||
EdcClientSingleton.GetInstance().SetWebHelpContextUrl(null); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(IOException))] | ||
public void ShouldThrowsExceptionOnUnknownDocumentationContext() | ||
{ | ||
EdcClientSingleton.GetInstance().SetDocumentationContextUrl("my-doc"); | ||
EdcClientSingleton.GetInstance().ForceReload(); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", null); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(InvalidUrlException))] | ||
public void ShouldThrowsExceptionOnNullServer() | ||
{ | ||
EdcClientSingleton.GetInstance().SetServerUrl(null); | ||
EdcClientSingleton.GetInstance().ForceReload(); | ||
String url = EdcClientSingleton.GetInstance().GetContextWebHelpUrl("fr.techad.edc", "help.center", "en"); | ||
} | ||
} |
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 @@ | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; |
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>edcClientDotnetTest</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\edc-client-dotnet\edc-client-dotnet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,7 @@ | ||
namespace edcClientDotnetTest.internalImpl | ||
{ | ||
public static class Constants | ||
{ | ||
public const string SERVER_URL = "https://demo.easydoccontents.com"; | ||
} | ||
} |
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,76 @@ | ||
using edcClientDotnet; | ||
using edcClientDotnet.model; | ||
|
||
namespace edcClientDotnetTest.internalImpl | ||
{ | ||
[TestClass] | ||
public class EdcClientImplTest : CommonBase | ||
{ | ||
private IEdcClient _edcClient; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
_edcClient = CreateEdcClient(); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetContextUrl() | ||
{ | ||
String url = _edcClient.GetContextWebHelpUrl("fr.techad.edc", "help.center", "en"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/context/edchelp/fr.techad.edc/help.center/en/0", url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetContextUrlWithRank() | ||
{ | ||
String url = _edcClient.GetContextWebHelpUrl("fr.techad.edc", "help.center", 2, "en"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/context/edchelp/fr.techad.edc/help.center/en/2", url); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetLabel() | ||
{ | ||
String label = _edcClient.GetLabel("articles", "en", "webmailmain"); | ||
Assert.AreEqual("Need more...", label); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetError() | ||
{ | ||
String error = _edcClient.GetError("failedData", "en", "webmailmain"); | ||
Assert.AreEqual("Une erreur est survenue lors de la récupération des données !\nVérifiez les clés de la brique fournies au composant EdcHelp.", error); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetContext() | ||
{ | ||
IContextItem contextItem = _edcClient.GetContextItem("fr.techad.edc", "help.center", "en"); | ||
_edcClient.LoadContext(); | ||
Assert.IsNotNull(contextItem); | ||
Assert.AreEqual(1, contextItem.ArticleSize()); | ||
Assert.AreEqual(3, contextItem.LinkSize()); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetDocumentationUrl() | ||
{ | ||
String documentationWebHelpUrl = _edcClient.GetDocumentationWebHelpUrl(434L, "ru", "myPluginId"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/doc/myPluginId/434/ru", documentationWebHelpUrl); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetDocumentationUrlWithNullLanguage() | ||
{ | ||
String documentationWebHelpUrl = _edcClient.GetDocumentationWebHelpUrl(434L, null, "myPluginId"); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/doc/myPluginId/434", documentationWebHelpUrl); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetDocumentationUrlWithNullPublicationId() | ||
{ | ||
String documentationWebHelpUrl = _edcClient.GetDocumentationWebHelpUrl(434L, null, null); | ||
Assert.AreEqual("https://demo.easydoccontents.com/help/doc/434", documentationWebHelpUrl); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
edc-client-dotnet-test/internalImpl/http/HttpClientDotnetTest.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,22 @@ | ||
namespace edcClientDotnetTest.internalImpl.http | ||
{ | ||
[TestClass] | ||
public class HttpClientDotnetTest | ||
{ | ||
private HttpClient httpClient; | ||
HttpResponseMessage response; | ||
String result; | ||
|
||
[TestInitialize] | ||
public void Setup() { httpClient = new HttpClient(); } | ||
|
||
[TestMethod] | ||
public void ShouldGetAFile() | ||
{ | ||
HttpResponseMessage response = httpClient.GetAsync("https://demo.easydoccontents.com/doc/edchelp/context.json").Result; | ||
Assert.IsNotNull(response); | ||
result = response.Content.ReadAsStringAsync().Result; | ||
Assert.IsFalse(String.IsNullOrEmpty(result)); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
edc-client-dotnet-test/internalImpl/io/HttpReaderImplTest.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,58 @@ | ||
using edcClientDotnet.internalImpl.util; | ||
using edcClientDotnet.io; | ||
using edcClientDotnet.model; | ||
using edcClientDotnet.utils; | ||
using NLog; | ||
|
||
namespace edcClientDotnetTest.internalImpl.io | ||
{ | ||
[TestClass] | ||
public class HttpReaderImplTest : CommonBase | ||
{ | ||
private IEdcReader? _edcReader; | ||
String _languageCode = "en"; | ||
HashSet<String> _languagesCodes = new HashSet<String>(); | ||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
_languagesCodes.Add("en"); | ||
_languagesCodes.Add("fr"); | ||
_edcReader = CreateEdcReader(); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldGetContextJson() | ||
{ | ||
IKeyUtil keyUtil = new KeyUtilImpl(); | ||
|
||
Dictionary<String, IContextItem> contextItemDictionary = _edcReader.ReadContext(); | ||
Assert.AreEqual(39, contextItemDictionary.Count); | ||
|
||
IContextItem contextItem = contextItemDictionary.GetValueOrDefault(keyUtil.GetKey("fr.techad.edc", "help.center", "en")); | ||
_languageCode = contextItem.LanguageCode; | ||
Assert.AreEqual("All you need about edc", contextItem.Description); | ||
Assert.AreEqual("About edc", contextItem.Label); | ||
Assert.AreEqual("en", contextItem.LanguageCode); | ||
Assert.AreEqual("edchelp/html/en/1/12523/index.html", contextItem.Url); | ||
Assert.AreEqual(1, contextItem.ArticleSize()); | ||
Assert.AreEqual(3, contextItem.LinkSize()); | ||
} | ||
|
||
|
||
|
||
[TestMethod] | ||
public void ShouldGetErrorValueWithDefinedLanguage() | ||
{ | ||
|
||
//String errorLabelEN = _edcReader.ReadLabel(_languagesCodes).GetTranslation("en", "errors", "failedData", "leftmenu.account"); | ||
//Assert.IsFalse(String.IsNullOrEmpty(errorLabelEN)); | ||
//Assert.AreEqual("An error occurred when fetching data !\nCheck the brick keys provided to the EdcHelp component.", errorLabelEN); | ||
|
||
String errorLabelFR = _edcReader.ReadLabel(_languagesCodes).GetTranslation("fr", "errors", "failedData", "webmailmain"); | ||
Assert.IsFalse(String.IsNullOrEmpty(errorLabelFR)); | ||
Assert.AreEqual("Une erreur est survenue lors de la récupération des données !\nVérifiez les clés de la brique fournies au composant EdcHelp.", errorLabelFR); | ||
} | ||
} | ||
} |
Oops, something went wrong.