Skip to content

Commit

Permalink
[Improve] code coverage for AppConfigService
Browse files Browse the repository at this point in the history
  • Loading branch information
samatrhea committed Nov 19, 2023
1 parent 43566e5 commit 0e7dc63
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CometServer.Tests/CometServer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
<None Update="config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Data.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Data\" />
<Folder Include="Services\CherryPick\" />
</ItemGroup>

Expand Down
72 changes: 72 additions & 0 deletions CometServer.Tests/Configuration/AppConfigServiceTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AppConfigServiceTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2023 RHEA System S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate
//
// This file is part of CDP4-COMET Webservices Community Edition.
// The CDP4-COMET Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C.
// This is an auto-generated class. Any manual changes to this file will be overwritten!
//
// The CDP4-COMET Web Services Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET Web Services Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace CometServer.Tests.Configuration
{
using System.IO;
using CometServer.Configuration;
using Microsoft.Extensions.Configuration;

using NUnit.Framework;

/// <summary>
/// Suite of tests for the <see cref="AppConfigService"/>
/// </summary>
[TestFixture]
public class AppConfigServiceTestFixture
{
private IConfiguration configuration;

[SetUp]
public void SetUp()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "appsettings.json");

// Initialize the configuration builder
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path, optional: false, reloadOnChange: true);

// Build the IConfiguration instance
this.configuration = configurationBuilder.Build();
}

[Test]
public void Verify_that_configuration_is_loaded_from_appsettings()
{
var appConfigService = new AppConfigService(this.configuration);

Assert.That(appConfigService.AppConfig.Backtier.Database, Is.EqualTo("cdp4server"));

Assert.That(appConfigService.AppConfig.Changelog.CollectChanges, Is.True);

Assert.That(appConfigService.AppConfig.EmailService.SMTP, Is.EqualTo("smtp.cdp4.org"));

Assert.That(appConfigService.AppConfig.HealthConfig.RequireHost, Is.Empty);

Assert.That(appConfigService.AppConfig.Midtier.BacktierWaitTime, Is.EqualTo(333));
}
}
}
46 changes: 46 additions & 0 deletions CometServer.Tests/Data/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
}
}
},
"Midtier": {
"UploadDirectory": "upload",
"FileStorageDirectory": "storage",
"IsExportEnabled": true,
"ExportDirectory": "export",
"BacktierWaitTime": 333
},
"Backtier": {
"HostName": "localhost",
"Port": 5432,
"UserName": "cdp4",
"Password": "cdp4",
"Database": "cdp4server",
"DatabaseRestore": "cdp4serverrestore",
"DatabaseManage": "cdp4manage",
"StatementTimeout": 180,
"IsDbSeedEnabled": true,
"IsDbRestoreEnabled": true,
"IsDbImportEnabled": false
},
"EmailService": {
"Sender": "CDP4",
"SMTP": "smtp.cdp4.org",
"Port": 587,
"UserName": "cdp4postmaster-username",
"Password": "cdp4postmaster-password"
},
"Defaults": {
"PersonPassword": "pass"
},
"Changelog": {
"CollectChanges": true,
"AllowEmailNotification": false
},
"Health": {
"RequireHost": []
}
}

0 comments on commit 0e7dc63

Please sign in to comment.