Skip to content

Commit 85ec81b

Browse files
committed
Atualização de versões e melhorias em validações
* Atualização de versões - Alterado `SVPreview` e `SPVer` no `Directory.Build.props`. - Atualizada versão do `xunit.runner.visualstudio` no projeto de testes. * Melhoria nas validações - Adicionados novos métodos de teste para propriedades aninhadas. - Introduzidas classes `Foo`, `Bar` e `Baz` com validações. - Modificado a interface `IValidable` para definir corretamente o método `HasProblems`. - Aprimoradas as funcionalidades da classe `RuleSet` para validações aninhadas. - Adicionada nova delegate `ValidateFunc` para métodos de validação.
1 parent 18143c8 commit 85ec81b

File tree

6 files changed

+387
-65
lines changed

6 files changed

+387
-65
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</PropertyGroup>
1111
<PropertyGroup>
1212
<SVVer>1.0.0</SVVer>
13-
<SVPreview>-preview-1.0</SVPreview>
13+
<SVPreview>-preview-2.0</SVPreview>
1414
</PropertyGroup>
1515
<PropertyGroup>
16-
<SPVer>1.0.0-preview-4.2</SPVer>
16+
<SPVer>1.0.0-preview-4.3</SPVer>
1717
</PropertyGroup>
1818
</Project>

RoyalCode.SmartValidations.Tests/NestedTests.cs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,50 @@ public void NestedProperties_WithNestedProblems()
5656
// Assert
5757
Assert.True(hasProblems);
5858
Assert.NotNull(problems);
59-
Assert.Equal(2, problems!.Count); // Expecting problems for TotalAmount and ShippingAddress.Street
59+
Assert.Equal(2, problems.Count); // Expecting problems for TotalAmount and ShippingAddress.Street
60+
}
61+
62+
[Fact]
63+
public void NestedProperties_WithNestedProblems_And_NestedValidable()
64+
{
65+
// Arrange
66+
var foo = new Foo
67+
{
68+
Bar = new Bar(),
69+
Baz = new Baz
70+
{
71+
Value = "Baz Value" // This is valid
72+
}
73+
};
74+
75+
// Act
76+
var hasProblems = foo.HasProblems(out var problems);
77+
78+
// Assert
79+
Assert.True(hasProblems);
80+
Assert.NotNull(problems);
81+
Assert.Equal(2, problems.Count); // Foo.Value and Bar.Value should be empty
82+
}
83+
84+
[Fact]
85+
public void NestedProperties_WithNestedProblems_And_NestedValidable_And_NestedValidateFunc()
86+
{
87+
// Arrange
88+
var foo = new Foo
89+
{
90+
Value = "Foo Value", // This is valid
91+
Bar = new Bar
92+
{
93+
Value = "Bar Value" // This is valid
94+
},
95+
Baz = new Baz() // This will have problems
96+
};
97+
// Act
98+
var hasProblems = foo.HasProblems(out var problems);
99+
// Assert
100+
Assert.True(hasProblems);
101+
Assert.NotNull(problems);
102+
Assert.Single(problems);
60103
}
61104
}
62105

@@ -105,4 +148,46 @@ file class Address
105148

106149
[DisplayName("Country")]
107150
public string Country { get; set; } = string.Empty;
151+
}
152+
153+
file class Foo : IValidable
154+
{
155+
public string? Value { get; set; } = string.Empty;
156+
157+
public Bar? Bar { get; set; }
158+
159+
public Baz? Baz { get; set; }
160+
161+
public bool HasProblems([NotNullWhen(true)] out Problems? problems)
162+
{
163+
return Rules.Set<Foo>()
164+
.NotEmpty(Value)
165+
.NotNullNested(Bar)
166+
.Nested(Baz, b => b.HasProblems)
167+
.HasProblems(out problems);
168+
}
169+
}
170+
171+
file class Bar : IValidable
172+
{
173+
public string? Value { get; set; } = string.Empty;
174+
175+
public bool HasProblems([NotNullWhen(true)] out Problems? problems)
176+
{
177+
return Rules.Set<Bar>()
178+
.NotEmpty(Value)
179+
.HasProblems(out problems);
180+
}
181+
}
182+
183+
file class Baz
184+
{
185+
public string? Value { get; set; } = string.Empty;
186+
187+
public bool HasProblems([NotNullWhen(true)] out Problems? problems)
188+
{
189+
return Rules.Set<Baz>()
190+
.NotEmpty(Value)
191+
.HasProblems(out problems);
192+
}
108193
}

RoyalCode.SmartValidations.Tests/RoyalCode.SmartValidations.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
1414
<PackageReference Include="xunit" Version="2.9.3"/>
15-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.2">
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>

RoyalCode.SmartValidations/IValidable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public interface IValidable
2020
/// <c>true</c> if there are validation problems (invalid); otherwise, <c>false</c> (valid).
2121
/// </returns>
2222
public bool HasProblems([NotNullWhen(true)] out Problems? problems);
23-
}
23+
}

0 commit comments

Comments
 (0)