Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Services/id-portal/O2Bionics.Services.IdPortal.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "O2Bionics.Services.IdPortal
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{0F7BEA3A-BD1E-4BE3-BBBB-CCD0100D10A5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7B217EFF-A101-4C6D-A3D8-2E2F3430AF6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests.O2Bionics.Services.IdPortal", "tests\IntegrationTests.O2Bionics.Services.IdPortal\IntegrationTests.O2Bionics.Services.IdPortal.csproj", "{BDDE70F1-FDAB-4FC4-B07B-3D97ABA948F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.O2Bionics.Services.IdPortal", "tests\Tests.O2Bionics.Services.IdPortal\Tests.O2Bionics.Services.IdPortal.csproj", "{D65A7929-5FDB-49A8-8547-E98B73046140}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,11 +27,23 @@ Global
{0F7BEA3A-BD1E-4BE3-BBBB-CCD0100D10A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F7BEA3A-BD1E-4BE3-BBBB-CCD0100D10A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F7BEA3A-BD1E-4BE3-BBBB-CCD0100D10A5}.Release|Any CPU.Build.0 = Release|Any CPU
{BDDE70F1-FDAB-4FC4-B07B-3D97ABA948F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDDE70F1-FDAB-4FC4-B07B-3D97ABA948F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDDE70F1-FDAB-4FC4-B07B-3D97ABA948F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDDE70F1-FDAB-4FC4-B07B-3D97ABA948F2}.Release|Any CPU.Build.0 = Release|Any CPU
{D65A7929-5FDB-49A8-8547-E98B73046140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D65A7929-5FDB-49A8-8547-E98B73046140}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D65A7929-5FDB-49A8-8547-E98B73046140}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D65A7929-5FDB-49A8-8547-E98B73046140}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8AD066DD-B55F-49B5-8D69-6C076266C1B7}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BDDE70F1-FDAB-4FC4-B07B-3D97ABA948F2} = {7B217EFF-A101-4C6D-A3D8-2E2F3430AF6E}
{D65A7929-5FDB-49A8-8547-E98B73046140} = {7B217EFF-A101-4C6D-A3D8-2E2F3430AF6E}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ public VersionController(IWebHostEnvironment environment, ILogger<VersionControl
[HttpGet("[controller]")]
public object Index()
{
var exVersion = Assembly.GetExecutingAssembly().GetName().Version;
var exVersion = GetVersion();
_logger.LogInformation($"get version - {exVersion}");
return new
{
Environment = _environment.EnvironmentName,
Version = exVersion?.ToString()
};
}

protected virtual Version GetVersion()
{
var exVersion = Assembly.GetExecutingAssembly().GetName().Version;
return exVersion ?? throw new InvalidOperationException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="IntegrationTests.$(AssemblyName)" />
<InternalsVisibleTo Include="Tests.$(AssemblyName)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\O2Bionics.Services.IdPortal\O2Bionics.Services.IdPortal.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Testing;

using Xunit;

namespace IntegrationTests.O2Bionics.Services.IdPortal;

public class VersionApiTests
{
private readonly HttpClient _httpClient;
public VersionApiTests()
{
var webAppFactory = new WebApplicationFactory<Program>();
_httpClient = webAppFactory.CreateDefaultClient();
}

[Fact]
public async Task VersionApi_Get_Test()
{
// Act
const string url = "/version";
var response = await _httpClient.GetAsync(url);

// Assert
response.EnsureSuccessStatusCode(); // Status Code 200-299
Assert.Equal("application/json; charset=utf-8",
response.Content.Headers.ContentType?.ToString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using O2Bionics.Services.IdPortal.Controllers;

namespace Tests.O2Bionics.Services.IdPortal;

public class StubVersionController : VersionController
{
public string VersionString { get; init; }

#pragma warning disable CS8618
public StubVersionController(IWebHostEnvironment environment,
#pragma warning restore CS8618
// ReSharper disable once ContextualLoggerProblem
ILogger<VersionController> logger)
: base(environment, logger)
{
}

protected override Version GetVersion() => Version.Parse(VersionString);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\O2Bionics.Services.IdPortal\O2Bionics.Services.IdPortal.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;

namespace Tests.O2Bionics.Services.IdPortal;

public class VersionControllerTests
{
[Test]
public void VersionController_GetVersion_Test()
{
var moq = new Mock<IWebHostEnvironment>();
var loggerMoq = new Mock<ILogger<StubVersionController>>();
var stub = new StubVersionController(moq.Object, loggerMoq.Object)
{
VersionString = "1.0.0.0"
};

var result = stub.Index();

// Assert
Assert.NotNull(result);
}
}