.net NetArchTest分层架构测试

pkln4tw6  于 2023-11-20  发布在  .NET
关注(0)|答案(1)|浏览(113)

我使用Ben Morris的NetArchTest.Rules包来执行分层架构。(具有依赖性)访问层中的任何其他项目,但结果总是返回false,我确信Assets项目与那些被检查的项目没有任何项目依赖关系在测试AssetsShouldNotReferenceAccess中。
Access LayerAssets Dependencies的数据库

private const string AssetsNamespace = "Flux.Access.Assets";
    private const string BlobNamespace = "Flux.Access.Blob";
    private const string ConfigurationsNamespace = "Flux.Access.Configurations";
    private const string MembersNamespace = "Flux.Access.Members";
    private const string CommonNamespace = "Flux.Access.Common";

    [Test]
    public void AssetsShouldNotReferenceOtherAccess()
    {
        var otherProjects = new[]
        {
            BlobNamespace, ConfigurationsNamespace, MembersNamespace
        };

        var result = Types
            .InCurrentDomain()
            .That()
            .ResideInNamespace(AssetsNamespace)
            .ShouldNot()
            .HaveDependencyOnAny(otherProjects)
            .GetResult()
            .IsSuccessful;

        Assert.True(result);
    }

    [Test]
    public void AssetsShouldReferenceCommon()
    {
        var result = Types
            .InCurrentDomain()
            .That()
            .ResideInNamespace(AssetsNamespace)
            .Should()
            .HaveDependencyOn(CommonNamespace)
            .GetResult()
            .IsSuccessful;

        Assert.True(result);
    }

字符串
如果我将代码改为Should而不是ShouldNot,我希望AssetsShouldNotReferenceAccess中的结果会改变,然而在这两种情况下,代码都返回False。在我在线阅读的软件包文档中,这似乎是测试代码的正确方法,但我无法让它工作。任何见解都会有所帮助:)

nukf8bse

nukf8bse1#

你可以用这样的东西

var result = Types.InAssembly(assembly)
            .Should()
            .NotHaveDependencyOnAll(notDependOnList)
            .GetResult();

字符串

相关问题