-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for repository, tables and new validations
- Loading branch information
Showing
14 changed files
with
195 additions
and
50 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/DistributionCenter.Infraestructure/Validators/Extensions/ValidationExtensions.Numbers.cs
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace DistributionCenter.Infraestructure.Validators.Extensions; | ||
|
||
using System.Globalization; | ||
using System.Text.RegularExpressions; | ||
using Components.Builders.Interfaces; | ||
|
||
public static partial class ValidationExtensions | ||
{ | ||
public static IValidationBuilder<double> DecimalSize( | ||
this IValidationBuilder<double> builder, | ||
int decimalQuantity, | ||
string message) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder, nameof(builder)); | ||
|
||
return builder.AddRule(x => | ||
{ | ||
string number = x.ToString(CultureInfo.InvariantCulture); | ||
return Regex.IsMatch(number, $@"^\d+(\.\d{{{decimalQuantity}}})?$"); | ||
}, message); | ||
} | ||
|
||
public static IValidationBuilder<int> NumberRange( | ||
this IValidationBuilder<int> builder, | ||
uint? min, | ||
uint? max, | ||
string message) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder, nameof(builder)); | ||
|
||
return builder.AddRule(x => (x >= (min ?? uint.MinValue) && x <= (max ?? uint.MaxValue)), message); | ||
} | ||
|
||
public static IValidationBuilder<int> NonNegatives(this IValidationBuilder<int> builder, string message) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder, nameof(builder)); | ||
|
||
return builder.AddRule(x => x >= 0, message); | ||
} | ||
} |
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
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,2 +1,5 @@ | ||
global using DistributionCenter.Application.Repositories.Concretes; | ||
global using DistributionCenter.Application.Tables.Components.Information.Concretes; | ||
global using DistributionCenter.Application.Tables.Core.Concretes; | ||
global using Moq; | ||
global using Xunit; |
1 change: 0 additions & 1 deletion
1
test/DistributionCenter.Application.Tests/Repositories/Concretes/ClientRepositoryTests.cs
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
17 changes: 17 additions & 0 deletions
17
test/DistributionCenter.Application.Tests/Repositories/Concretes/ProductRepositoryTests.cs
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace DistributionCenter.Application.Tests.Repositories.Concretes; | ||
|
||
using DistributionCenter.Application.Contexts.Interfaces; | ||
|
||
public class ProductRepositoryTests | ||
{ | ||
[Fact] | ||
public void Constructor_InitializesRepository() | ||
{ | ||
// Define Input and Output | ||
Mock<IContext> contextMock = new(); | ||
ProductRepository repository = new(contextMock.Object); | ||
|
||
// Verify actual result | ||
Assert.NotNull(repository); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
....Application.Tests/Tables/Components/Information/Concretes/ClientTableInformationTests.cs
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
83 changes: 83 additions & 0 deletions
83
...Application.Tests/Tables/Components/Information/Concretes/ProductTableInformationTests.cs
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
namespace DistributionCenter.Application.Tests.Tables.Components.Information.Concretes; | ||
|
||
public class ProductTableInformationTests | ||
{ | ||
private readonly ProductTableInformation _table; | ||
|
||
public ProductTableInformationTests() | ||
{ | ||
_table = new ProductTableInformation(); | ||
} | ||
|
||
[Fact] | ||
public void TableName_ReturnsExpectedString() | ||
{ | ||
// Define Input and Output | ||
string result; | ||
string expected = "product"; | ||
|
||
// Execute actual operation | ||
result = _table.TableName; | ||
|
||
// Verify actual result | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Fact] | ||
public void GetByIdFields_ReturnsExpectedString() | ||
{ | ||
// Define Input and Output | ||
string result; | ||
string expected = | ||
"id AS Id, name, description, weight_gr AS Weight, is_active AS IsActive, created_at AS CreatedAt, updated_at AS UpdatedAt"; | ||
|
||
// Execute actual operation | ||
result = _table.GetByIdFields; | ||
|
||
// Verify actual result | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Fact] | ||
public void CreateFields_ReturnsExpectedString() | ||
{ | ||
// Define Input and Output | ||
string result; | ||
string expected = "id, name, description, weight_gr, is_active, created_at, updated_at"; | ||
|
||
// Execute actual operation | ||
result = _table.CreateFields; | ||
|
||
// Verify actual result | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Fact] | ||
public void CreateValues_ReturnsExpectedString() | ||
{ | ||
// Define Input and Output | ||
string result; | ||
string expected = "@Id, @Name, @Description, @Weight, @IsActive, @CreatedAt, @UpdatedAt"; | ||
|
||
// Execute actual operation | ||
result = _table.CreateValues; | ||
|
||
// Verify actual result | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Fact] | ||
public void UpdateFields_ReturnsExpectedString() | ||
{ | ||
// Define Input and Output | ||
string result; | ||
string expected = | ||
"name = @Name, description = @Description, weight_gr = @Weight, is_active = @IsActive, updated_at = @UpdatedAt"; | ||
|
||
// Execute actual operation | ||
result = _table.UpdateFields; | ||
|
||
// Verify actual result | ||
Assert.Equal(expected, result); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
test/DistributionCenter.Application.Tests/Tables/Core/Concretes/ClientTableTests.cs
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
21 changes: 21 additions & 0 deletions
21
test/DistributionCenter.Application.Tests/Tables/Core/Concretes/ProductTableTests.cs
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace DistributionCenter.Application.Tests.Tables.Core.Concretes; | ||
|
||
using Application.Tables.Components.Information.Interfaces; | ||
using Application.Tables.Connections.Interfaces; | ||
|
||
public class ProductTableTests | ||
{ | ||
[Fact] | ||
public void GetInformation_ShouldReturnProductTableInformation() | ||
{ | ||
// Define Input and Output | ||
Mock<IDbConnectionFactory> mockFactory = new(); | ||
ProductTable table = new(mockFactory.Object); | ||
|
||
// Execute actual operation | ||
ITableInformation info = table.GetInformation(); | ||
|
||
// Verify actual result | ||
_ = Assert.IsType<ProductTableInformation>(info); | ||
} | ||
} |
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
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
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
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
19 changes: 19 additions & 0 deletions
19
test/DistributionCenter.Infraestructure.Tests/Validators/ValidationExtensionsTests.cs
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace DistributionCenter.Infraestructure.Tests.Validators; | ||
|
||
using Infraestructure.Validators.Components.Builders.Concretes; | ||
using Infraestructure.Validators.Extensions; | ||
|
||
public class ValidationExtensionsTests | ||
{ | ||
[Fact] | ||
public void CheckedThanTheLimitOfTheDecimalNumbersWasValidated() | ||
{ | ||
double validNumber = 1345.52; | ||
double invalidNumber = 1345.5242; | ||
ValidationBuilder<double> validations = new(); | ||
_ = validations.DecimalSize(2, "The number couldn't has more than 2 decimal numbers"); | ||
|
||
Assert.Empty(validations.Validate(validNumber)); | ||
Assert.NotEmpty(validations.Validate(invalidNumber)); | ||
} | ||
} |