-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dab299
commit 9effcf3
Showing
1 changed file
with
38 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |