英文:
Architecture test using NetArchTest gives false result when trying to assert sealed class fitness rule
问题
I'm writing Architecture Fitness Test using NetArchTest and I'm trying to Assert
if all of my Request Class
are sealed
using the below test,
[Fact]
public void Should_Have_Request_To_Be_Sealed()
{
var result =
Types.InAssembly(typeof(ApplicationServiceRegistration).Assembly)
.That()
.AreClasses()
.And()
.Inherit(typeof(IRequest))
.Should()
.BeSealed()
.GetResult();
Assert.True(result.IsSuccessful);
}
Here are the examples of my Request Class
,
public class CreateCategoryCommand : IRequest<Result<CategoryDto, BaseError>>
{
public string Name { get; set; } = string.Empty;
public string? Code { get; set; }
}
public class CreateClientCommand : IRequest<Result<ClientDto, BaseError>>
{
public string Name { get; set; } = string.Empty;
}
As we can see, the Request Class
are not sealed
, but still the test gets passed.
Am I missing anything? Please assist.
英文:
I'm writing Architecture Fitness Test using NetArchTest and I'm trying to Assert
if all of my Request Class
are sealed
using the below test,
[Fact]
public void Should_Have_Request_To_Be_Sealed()
{
var result =
Types.InAssembly(typeof(ApplicationServiceRegistration).Assembly)
.That()
.AreClasses()
.And()
.Inherit(typeof(IRequest))
.Should()
.BeSealed()
.GetResult();
Assert.True(result.IsSuccessful);
}
Here are the examples of my Request Class
,
public class CreateCategoryCommand : IRequest<Result<CategoryDto, BaseError>>
{
public string Name { get; set; } = string.Empty;
public string? Code { get; set; }
}
public class CreateClientCommand : IRequest<Result<ClientDto, BaseError>>
{
public string Name { get; set; } = string.Empty;
}
As we can see, the Request Class
are not sealed
, but still the test gets passed.
Am I missing anything? Please assist.
答案1
得分: 0
我明白了。我应该使用ImplementInterface
而不是Inherit
,如下所示,
[Fact]
public void Should_Have_Request_To_Be_Sealed()
{
var result =
Types.InAssembly(typeof(ApplicationServiceRegistration).Assembly)
.That()
.AreClasses()
.And()
.ImplementInterface(typeof(IRequest)) <-- 这里改变了
.Should()
.BeSealed()
.GetResult();
Assert.True(result.IsSuccessful);
}
英文:
I figured out. I should use ImplementInterface
instead of Inherit
as shown below,
[Fact]
public void Should_Have_Request_To_Be_Sealed()
{
var result =
Types.InAssembly(typeof(ApplicationServiceRegistration).Assembly)
.That()
.AreClasses()
.And()
.ImplementInterface(typeof(IRequest)) <-- Changed here
.Should()
.BeSealed()
.GetResult();
Assert.True(result.IsSuccessful);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论