Browse Source

Add creation event traces to Validator classes to validate issue #1041

pull/1044/head
Miguel Veloso 5 years ago
parent
commit
fd2bf42a5f
5 changed files with 25 additions and 20 deletions
  1. +1
    -0
      docker-compose.override.yml
  2. +5
    -6
      src/Services/Ordering/Ordering.API/Application/Validations/CancelOrderCommandValidator.cs
  3. +9
    -6
      src/Services/Ordering/Ordering.API/Application/Validations/CreateOrderCommandValidator.cs
  4. +5
    -2
      src/Services/Ordering/Ordering.API/Application/Validations/IdentifiedCommandValidator.cs
  5. +5
    -6
      src/Services/Ordering/Ordering.API/Application/Validations/ShipOrderCommandValidator.cs

+ 1
- 0
docker-compose.override.yml View File

@ -111,6 +111,7 @@ services:
- OrchestratorType=${ORCHESTRATOR_TYPE}
- UseLoadTest=${USE_LOADTEST:-False}
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
- Serilog__MinimumLevel__Override__Ordering.API=Verbose
ports:
- "5102:80" # Important: In a production environment your should remove the external port (5102) kept here for microservice debugging purposes.
# The API Gateway redirects and access through the internal port (80).


+ 5
- 6
src/Services/Ordering/Ordering.API/Application/Validations/CancelOrderCommandValidator.cs View File

@ -1,17 +1,16 @@
using FluentValidation;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.Validations
{
public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
{
public CancelOrderCommandValidator()
public CancelOrderCommandValidator(ILogger<CancelOrderCommandValidator> logger)
{
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
}
}
}
}

+ 9
- 6
src/Services/Ordering/Ordering.API/Application/Validations/CreateOrderCommandValidator.cs View File

@ -1,5 +1,6 @@
using FluentValidation;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,19 +10,21 @@ namespace Ordering.API.Application.Validations
{
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
{
public CreateOrderCommandValidator()
public CreateOrderCommandValidator(ILogger<CreateOrderCommandValidator> logger)
{
RuleFor(command => command.City).NotEmpty();
RuleFor(command => command.Street).NotEmpty();
RuleFor(command => command.State).NotEmpty();
RuleFor(command => command.Country).NotEmpty();
RuleFor(command => command.ZipCode).NotEmpty();
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19);
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19);
RuleFor(command => command.CardHolderName).NotEmpty();
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date");
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3);
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date");
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3);
RuleFor(command => command.CardTypeId).NotEmpty();
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found");
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
}
private bool BeValidExpirationDate(DateTime dateTime)
@ -34,4 +37,4 @@ namespace Ordering.API.Application.Validations
return orderItems.Any();
}
}
}
}

+ 5
- 2
src/Services/Ordering/Ordering.API/Application/Validations/IdentifiedCommandValidator.cs View File

@ -1,13 +1,16 @@
using FluentValidation;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
namespace Ordering.API.Application.Validations
{
public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand,bool>>
{
public IdentifiedCommandValidator()
public IdentifiedCommandValidator(ILogger<IdentifiedCommandValidator> logger)
{
RuleFor(command => command.Id).NotEmpty();
RuleFor(command => command.Id).NotEmpty();
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
}
}
}

+ 5
- 6
src/Services/Ordering/Ordering.API/Application/Validations/ShipOrderCommandValidator.cs View File

@ -1,17 +1,16 @@
using FluentValidation;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.Validations
{
public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
{
public ShipOrderCommandValidator()
public ShipOrderCommandValidator(ILogger<ShipOrderCommandValidator> logger)
{
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
}
}
}
}

Loading…
Cancel
Save