Skip to content

Commit

Permalink
Fixed arch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmackay committed Apr 14, 2024
1 parent 8dab299 commit 9effcf3
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions tests/Architecture.Tests/DatabaseEntitiesTest.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using NetArchTest.Rules;
using SSW.CleanArchitecture.Architecture.UnitTests.Common;
using SSW.CleanArchitecture.Domain.Common.Base;
using SSW.CleanArchitecture.Domain.Common.Interfaces;
using SSW.CleanArchitecture.Infrastructure;
using Xunit.Abstractions;

namespace SSW.CleanArchitecture.Architecture.UnitTests;

public class DatabaseEntities
{
private readonly ITestOutputHelper _outputHelper;

public DatabaseEntities(ITestOutputHelper outputHelper)
{
_outputHelper = outputHelper;
}

// // TODO: Fix this test
// [Fact]
// public void Entities_ShouldInheritsBaseComponent()
// {
// var entityTypes = Types.InAssembly(typeof(DependencyInjection).Assembly)
// .That()
// .Inherit(typeof(DbContext))
// .GetTypes()
// .SelectMany(t => t.GetProperties())
// .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>))
// .Select(p => p.PropertyType)
// .Select(t => t.GetGenericArguments().FirstOrDefault()?.Name)
// .ToArray();
//
// var result = Types.InAssembly(typeof(BaseEntity<>).Assembly)
// .That()
// .HaveName(entityTypes)
// .Should()
// .Inherit(typeof(BaseEntity<>));
//
// result.GetTypes().Count().Should().BePositive();
// result.GetResult().IsSuccessful.Should().BeTrue();
// }
[Fact]
public void Entities_ShouldInheritsBaseComponent()
{
var entityTypes = Types.InAssembly(typeof(DependencyInjection).Assembly)
.That()
.Inherit(typeof(DbContext))
.GetTypes()
.SelectMany(t => t.GetProperties())
.Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>))
.Select(p => p.PropertyType)
.Select(t => t.GetGenericArguments().FirstOrDefault()?.Name)
.ToArray();

var result = Types.InAssembly(typeof(BaseEntity<>).Assembly)
.That()
.HaveName(entityTypes)
.Should()
.Inherit(typeof(BaseEntity<>))
.Or()
.Inherit(typeof(IAggregateRoot))
;

result.GetResult().IsSuccessful.Should().BeTrue();
result.GetResult().DumpFailingTypes(_outputHelper);
}
}

0 comments on commit 9effcf3

Please sign in to comment.