Skip to content

Commit

Permalink
task: added a second test library to ensure multiple libs are support…
Browse files Browse the repository at this point in the history
…ed corrrectly
  • Loading branch information
dtanglr committed Feb 15, 2024
1 parent b86e5f3 commit e404cd8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Primitively.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acme.TestLib2", "test\Acme.TestLib2\Acme.TestLib2.csproj", "{BCFCC6F3-A32F-4431-A962-8B3B22EBBD88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,10 @@ Global
{F159F852-EC63-4AB9-A68F-C1F10E2B6CD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F159F852-EC63-4AB9-A68F-C1F10E2B6CD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F159F852-EC63-4AB9-A68F-C1F10E2B6CD9}.Release|Any CPU.Build.0 = Release|Any CPU
{BCFCC6F3-A32F-4431-A962-8B3B22EBBD88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCFCC6F3-A32F-4431-A962-8B3B22EBBD88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCFCC6F3-A32F-4431-A962-8B3B22EBBD88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCFCC6F3-A32F-4431-A962-8B3B22EBBD88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -86,6 +92,7 @@ Global
{507D94C8-CB04-42C5-A300-5A7764E14338} = {85259CD9-4D3F-4D53-BDF4-B598410B676B}
{7B98BCBA-B006-4C04-B2B6-17C8820736C1} = {85259CD9-4D3F-4D53-BDF4-B598410B676B}
{F159F852-EC63-4AB9-A68F-C1F10E2B6CD9} = {65B53329-4C22-4004-81AE-36F9FE861175}
{BCFCC6F3-A32F-4431-A962-8B3B22EBBD88} = {65B53329-4C22-4004-81AE-36F9FE861175}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2F8C44A9-087B-42DD-A219-45CBA101A5D0}
Expand Down
32 changes: 32 additions & 0 deletions test/Acme.TestLib2/Acme.TestLib2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Primitively\Primitively.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\src\Primitively.Abstractions\Primitively.Abstractions.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" Visible="false" />
</ItemGroup>

<!--
To target netstandard2.0, the below props are required to support some features introduced after netstandard2.0 and
the c# 7.3 lang version release dates, such as 'record structs' which came with c# 10.
-->

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions test/Acme.TestLib2/GuidId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Primitively;

namespace Acme.TestLib2;

[Guid]
public partial record struct GuidId;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.Extensions.Options;
using Primitively.AspNetCore.Mvc.ModelBinding;
using Xunit;
using PrimitiveLibrary1 = Acme.TestLib.PrimitiveLibrary;
using PrimitiveLibrary2 = Acme.TestLib2.PrimitiveLibrary;

namespace Primitively.IntegrationTests;

Expand All @@ -15,7 +17,9 @@ public void PrimitiveModelBinderProvider_IsRegistered()
// Arrange
var services = new ServiceCollection();

services.AddPrimitively(options => options.Register(PrimitiveLibrary.Respository))
services.AddPrimitively(options => options
.Register(PrimitiveLibrary1.Respository)
.Register(PrimitiveLibrary2.Respository))
.AddMvc();

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Primitively.Configuration;
using Swashbuckle.AspNetCore.SwaggerGen;
using Xunit;
using PrimitiveLibrary1 = Acme.TestLib.PrimitiveLibrary;
using PrimitiveLibrary2 = Acme.TestLib2.PrimitiveLibrary;

namespace Primitively.IntegrationTests;

Expand All @@ -14,11 +16,15 @@ public class PrimitiveAspNetCoreSwaggerGenTests
public void PrimitiveSchemaFilter_IsRegistered()
{
// Arrange
var repository = PrimitiveLibrary.Respository;
var services = new ServiceCollection();
var types = new List<PrimitiveInfo>();
types.AddRange(PrimitiveLibrary1.Respository.GetTypes());
types.AddRange(PrimitiveLibrary2.Respository.GetTypes());

services.AddPrimitively(options => options.Register(repository))
.AddSwaggerGen();
var services = new ServiceCollection();
services.AddPrimitively(options => options
.Register(PrimitiveLibrary1.Respository)
.Register(PrimitiveLibrary2.Respository))
.AddSwaggerGen();

// Act
var serviceProvider = services.BuildServiceProvider();
Expand All @@ -32,12 +38,15 @@ public void PrimitiveSchemaFilter_IsRegistered()
filter.Should().NotBeNull();
filter!.Arguments.Length.Should().Be(1);

var arg = filter.Arguments[0] as PrimitiveRegistry;
arg.Should().NotBeNull();
var registry = filter.Arguments[0] as PrimitiveRegistry;
registry.Should().NotBeNull();

var registryTypes = registry!.ToList();
registryTypes.Should().NotBeNullOrEmpty();

foreach (var type in repository.GetTypes())
foreach (var type in types)
{
type.Should().NotBeNull();
registryTypes.Should().ContainSingle(r => r.Equals(type));
}

var schemaFilter = Activator.CreateInstance(filter.Type, filter.Arguments) as PrimitiveSchemaFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ProjectReference Include="..\..\src\Primitively.FluentValidation\Primitively.FluentValidation.csproj" />
<ProjectReference Include="..\..\src\Primitively.MongoDB.Bson\Primitively.MongoDB.Bson.csproj" />
<ProjectReference Include="..\Acme.TestLib\Acme.TestLib.csproj" />
<ProjectReference Include="..\Acme.TestLib2\Acme.TestLib2.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion test/Primitively.IntegrationTests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
global using Acme.TestLib;
global using Primitively;

0 comments on commit e404cd8

Please sign in to comment.