32 lines
2.1 KiB
C#
32 lines
2.1 KiB
C#
using System.Reflection;
|
|
using HealthApp.Contracts;
|
|
using HealthApp.TestSupport;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Xunit;
|
|
namespace HealthApp.AcceptanceTests;
|
|
public sealed class ConformanceTests
|
|
{
|
|
[Fact]
|
|
public void Persistence_entities_and_contexts_are_private_and_dependency_graph_is_acyclic()
|
|
{
|
|
var assemblies=new[]{typeof(HealthApp.Profile.ProfileModule).Assembly,typeof(HealthApp.Observations.ObservationsModule).Assembly,typeof(HealthApp.Analytics.AnalyticsModule).Assembly,typeof(HealthApp.Overview.OverviewModule).Assembly,typeof(HealthApp.Guidance.GuidanceQueries).Assembly};
|
|
foreach(var assembly in assemblies)
|
|
{
|
|
Assert.DoesNotContain(assembly.GetExportedTypes(),t=>t.Name.EndsWith("DbContext")||t.Name is "Patient" or "BloodPressureObservation");
|
|
Assert.DoesNotContain(assembly.GetReferencedAssemblies(),a=>a.Name=="HealthApp");
|
|
}
|
|
foreach(var a in new[]{typeof(HealthApp.Analytics.AnalyticsModule).Assembly,typeof(HealthApp.Overview.OverviewModule).Assembly,typeof(HealthApp.Guidance.GuidanceQueries).Assembly})Assert.DoesNotContain(a.GetTypes(),t=>typeof(Microsoft.EntityFrameworkCore.DbContext).IsAssignableFrom(t));
|
|
Assert.Empty(typeof(AuthorizedPatientContext).GetConstructors(BindingFlags.Public|BindingFlags.Instance));
|
|
}
|
|
[Fact]
|
|
public void Final_solution_has_one_web_host_and_no_reference_project_or_internal_business_http()
|
|
{
|
|
var root=PatientProfile.AcceptanceTests.PatientApiFixture.FindRoot();var solution=File.ReadAllText(Path.Combine(root,"HealthApp.slnx"));Assert.DoesNotContain("Reference/",solution);
|
|
var webProjects=Directory.GetFiles(Path.Combine(root,"src"),"*.csproj",SearchOption.AllDirectories).Where(p=>File.ReadAllText(p).Contains("Sdk=\"Microsoft.NET.Sdk.Web\""));Assert.Single(webProjects);
|
|
foreach(var path in Directory.GetFiles(Path.Combine(root,"src"),"*.cs",SearchOption.AllDirectories).Where(p=>!p.Contains("/obj/")&&!p.Contains("/bin/")))
|
|
{var code=File.ReadAllText(path);Assert.DoesNotContain("IHttpClientFactory",code);Assert.DoesNotContain("X-Service-Key",code);Assert.DoesNotContain("X-Gateway-Key",code);}
|
|
}
|
|
}
|