Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test that Nox projects dependencies are healthy #160

Merged
merged 1 commit into from
Jul 6, 2023
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
6 changes: 6 additions & 0 deletions src/Nox.Generator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.EntityFramework.Sqlite"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Generator", "Generator", "{154B838E-65DE-479F-80B7-D48CF9862306}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Tests", "..\tests\Nox.Tests\Nox.Tests.csproj", "{749A8B24-397E-4794-B647-3557E19FBA41}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -135,6 +137,10 @@ Global
{049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Release|Any CPU.Build.0 = Release|Any CPU
{749A8B24-397E-4794-B647-3557E19FBA41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{749A8B24-397E-4794-B647-3557E19FBA41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{749A8B24-397E-4794-B647-3557E19FBA41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{749A8B24-397E-4794-B647-3557E19FBA41}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
53 changes: 53 additions & 0 deletions tests/Nox.Tests/CodeAnalysisSolutionFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Reflection;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;

namespace Nox.Tests;

public class CodeAnalysisSolutionFixture : IAsyncLifetime
{
private const string SolutionPath = "src/Nox.Generator.sln";

public Solution Solution { get; private set; } = null!;
public Project NoxTypesProject { get; private set; } = null!;
public Project NoxSolutionNet7 { get; private set; } = null!;
public Project NoxSolutionNetStd20 { get; private set; } = null!;

public async Task InitializeAsync()
{
MSBuildLocator.RegisterDefaults();

var workspace = MSBuildWorkspace.Create();

Solution = await workspace.OpenSolutionAsync(GetSolutionFile());

NoxTypesProject = Solution.Projects.Single(project => project.Name == "Nox.Types");
NoxSolutionNet7 = Solution.Projects.Single(project => project.Name == "Nox.Solution(net7.0)");
NoxSolutionNetStd20 = Solution.Projects.Single(project => project.Name == "Nox.Solution(netstandard2.0)");
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}
private string GetSolutionFile()
{
return GetSolutionFile(Directory.GetParent(Assembly.GetExecutingAssembly().Location));
}

private string GetSolutionFile(DirectoryInfo? directoryInfo)
{
if (directoryInfo == null)
throw new Exception($"Could not find solution {SolutionPath}");

var filePath = Path.Combine(directoryInfo.FullName, SolutionPath);

if (File.Exists(filePath))
{
return filePath;
}

return GetSolutionFile(directoryInfo.Parent);
}
}
29 changes: 29 additions & 0 deletions tests/Nox.Tests/Nox.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions tests/Nox.Tests/ProjectsDependenciesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using FluentAssertions;

namespace Nox.Tests
{
public class ProjectsDependenciesTests: IClassFixture<CodeAnalysisSolutionFixture>
{
private readonly CodeAnalysisSolutionFixture _fixture;

public ProjectsDependenciesTests(CodeAnalysisSolutionFixture fixture)
{
_fixture = fixture;
}

[Fact]
public void Nox_Types_Cannot_Reference_Projects()
{
_fixture.NoxTypesProject.ProjectReferences.Should().BeEmpty();
}
[Fact]
public void Nox_Types__References_Nox_Types_Only()
{
_fixture.NoxSolutionNet7.ProjectReferences.Count().Should().Be(1);
_fixture.NoxSolutionNetStd20.ProjectReferences.Count().Should().Be(1);

(_fixture.NoxSolutionNet7.ProjectReferences.Single().ProjectId == _fixture.NoxTypesProject.Id).Should().BeTrue();
(_fixture.NoxSolutionNetStd20.ProjectReferences.Single().ProjectId == _fixture.NoxTypesProject.Id).Should().BeTrue();
}
}
}
1 change: 1 addition & 0 deletions tests/Nox.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;