Skip to content

Commit

Permalink
Merge pull request #184 from Judopay/UpdateFluentValidation-JR-7629-0
Browse files Browse the repository at this point in the history
JR-7629 : Update FluentValidation dependency from 8.1.2 to 11.8.0
  • Loading branch information
Stuart-Baillie authored Nov 27, 2023
2 parents 56c3001 + ca53c04 commit 3ec3a98
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 140 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
command: dotnet restore
- save_cache:
key: judokit-dotnet-sdk-{{ checksum "JudoPayDotNet/JudoPayDotNet.csproj" }}-{{ checksum "JudoPayDotNetTests/JudoPayDotNetTests.csproj" }}-{{checksum "JudoPayDotNetIntegrationTests/JudoPayDotNetIntegrationTests.csproj" }}
paths: ~/.nuget/packages
paths:
- ~/.nuget/packages
build_sdk:
executor: win/default
steps:
Expand Down
2 changes: 1 addition & 1 deletion JudoPayDotNet/JudoPayDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.1.2" />
<PackageReference Include="FluentValidation" Version="11.8.0" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions JudoPayDotNet/Validation/PaymentReceiptValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FluentValidation;
using JudoPayDotNet.Models;

namespace JudoPayDotNet.Validation
{
internal class PaymentReceiptValidator : AbstractValidator<PaymentReceiptModel>
{
public PaymentReceiptValidator()
{
RuleFor(model => model.ReceiptId)
.NotEmpty().WithMessage("The response must contain a receipt ID");

RuleFor(model => model.Type)
.NotEmpty().WithMessage("The response must contain an Type");

RuleFor(model => model.JudoId)
.NotEmpty().WithMessage("The response must contain an Judo Id");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentValidation;
using JudoPayDotNet.Models;

namespace JudoPayDotNet.Validation
{
internal class PaymentRequiresThreeDSecureTwoValidator : AbstractValidator<PaymentRequiresThreeDSecureTwoModel>
{
public PaymentRequiresThreeDSecureTwoValidator()
{
RuleFor(model => model.ReceiptId)
.NotEmpty().WithMessage("The response must contain a receipt ID");

RuleFor(model => model.MethodUrl)
.NotEmpty().WithMessage("The response must contain a MethodUrl");

RuleFor(model => model.Version)
.NotEmpty().WithMessage("The response must contain a Version");

RuleFor(model => model.Md)
.NotEmpty().WithMessage("The response must contain a Md");
}
}
}
62 changes: 0 additions & 62 deletions JudoPayDotNet/Validation/PolymorphicValidator.cs

This file was deleted.

17 changes: 0 additions & 17 deletions JudoPayDotNetTests/Model/Validations/PaymentReceiptValidation.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion JudoPayDotNetTests/Validation/PaymentsValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public void ValidatePkPaymentWithErrorOnSpecificCardPaymentInformation()

var validator = new PKPaymentValidator();

validator.ShouldHaveValidationErrorFor(model => model.PkPayment, payment);
var result = validator.TestValidate(payment);

result.ShouldHaveValidationErrorFor(model => model.PkPayment);
}
}
}
29 changes: 13 additions & 16 deletions JudoPayDotNetTests/Validation/TransactionResultValidationTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using JudoPayDotNet.Models;
using JudoPayDotNet.Validation;
using JudoPayDotNetTests.Model.Validations;
using NUnit.Framework;

namespace JudoPayDotNetTests.Validation
Expand All @@ -12,39 +11,37 @@ public class TransactionResultValidationTests
[Test]
public void ValidateATransactionResult()
{
ITransactionResult transactionResult = new PaymentReceiptModel();
var receipt = new PaymentReceiptModel();

var validator = new PolymorphicValidator<ITransactionResult>(new TransactionResultValidation())
// ReSharper disable RedundantTypeArgumentsOfMethod
.Add<PaymentReceiptModel>(new PaymentReceiptValidation());
// ReSharper restore RedundantTypeArgumentsOfMethod
var validator = new PaymentReceiptValidator();

var result = validator.Validate(transactionResult);
var result = validator.Validate(receipt);

Assert.IsNotNull(result);

var inner = result.First();
Assert.IsFalse(result.IsValid);

var firstError = result.Errors.First();

Assert.IsTrue(inner.PropertyName == "ReceiptId");
Assert.IsTrue(firstError.PropertyName == "ReceiptId");
}

[Test]
public void ValidateAThreeDSecureTwoTransactionResult()
{
ITransactionResult transactionResult = new PaymentRequiresThreeDSecureTwoModel();
var transactionResult = new PaymentRequiresThreeDSecureTwoModel();

var validator = new PolymorphicValidator<ITransactionResult>(new TransactionResultValidation())
// ReSharper disable RedundantTypeArgumentsOfMethod
.Add<PaymentRequiresThreeDSecureTwoModel>(new PaymentRequiresThreeDSecureTwoModelValidator());
// ReSharper restore RedundantTypeArgumentsOfMethod
var validator = new PaymentRequiresThreeDSecureTwoValidator();

var result = validator.Validate(transactionResult);

Assert.IsNotNull(result);

var inner = result.First();
Assert.IsFalse(result.IsValid);

var firstError = result.Errors.First();

Assert.IsTrue(inner.PropertyName == "ReceiptId");
Assert.IsTrue(firstError.PropertyName == "ReceiptId");
}
}
}

0 comments on commit 3ec3a98

Please sign in to comment.