ArgumentNullException handling using throw expressions

Solves #64
This commit is contained in:
etomas 2017-02-27 10:35:31 +01:00
parent 6d72c7dda0
commit e66b6a2402
9 changed files with 15 additions and 74 deletions

View File

@ -22,8 +22,7 @@ namespace Identity.API.Services
async public Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var subject = context.Subject;
if (subject == null) throw new ArgumentNullException(nameof(context.Subject));
var subject = context.Subject ?? throw new ArgumentNullException(nameof(context.Subject));
var subjectId = subject.Claims.Where(x => x.Type == "sub").FirstOrDefault().Value;
@ -37,8 +36,7 @@ namespace Identity.API.Services
async public Task IsActiveAsync(IsActiveContext context)
{
var subject = context.Subject;
if (subject == null) throw new ArgumentNullException(nameof(context.Subject));
var subject = context.Subject ?? throw new ArgumentNullException(nameof(context.Subject));
var subjectId = subject.Claims.Where(x => x.Type == "sub").FirstOrDefault().Value;
var user = await _userManager.FindByIdAsync(subjectId);

View File

@ -15,18 +15,8 @@
// Using DI to inject infrastructure persistence Repositories
public CreateOrderCommandHandler(IBuyerRepository buyerRepository, IOrderRepository orderRepository)
{
if (buyerRepository == null)
{
throw new ArgumentNullException(nameof(buyerRepository));
}
if (orderRepository == null)
{
throw new ArgumentNullException(nameof(orderRepository));
}
_buyerRepository = buyerRepository;
_orderRepository = orderRepository;
_buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository));
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
}
public async Task<bool> Handle(CreateOrderCommand message)

View File

@ -15,7 +15,7 @@
public OrderQueries(string constr)
{
_connectionString = constr;
_connectionString = !string.IsNullOrWhiteSpace(constr) ? constr : throw new ArgumentNullException(nameof(constr));
}

View File

@ -20,24 +20,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentityService identityService)
{
if (mediator == null)
{
throw new ArgumentNullException(nameof(mediator));
}
if (orderQueries == null)
{
throw new ArgumentNullException(nameof(orderQueries));
}
if (identityService == null)
{
throw new ArgumentException(nameof(identityService));
}
_mediator = mediator;
_orderQueries = orderQueries;
_identityService = identityService;
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
_orderQueries = orderQueries ?? throw new ArgumentNullException(nameof(orderQueries));
_identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
}
[Route("new")]

View File

@ -13,12 +13,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Servi
public IdentityService(IHttpContextAccessor context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_context = context;
_context = context ?? throw new ArgumentNullException(nameof(context));
}
public string GetUserIdentity()

View File

@ -21,12 +21,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
public Buyer(string identity) : this()
{
if (String.IsNullOrWhiteSpace(identity))
{
throw new ArgumentNullException(nameof(identity));
}
IdentityGuid = identity;
IdentityGuid = !string.IsNullOrWhiteSpace(identity) ? identity : throw new ArgumentNullException(nameof(identity));
}

View File

@ -21,20 +21,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
{
if (String.IsNullOrWhiteSpace(cardNumber))
{
throw new ArgumentException(nameof(cardNumber));
}
if (String.IsNullOrWhiteSpace(securityNumber))
{
throw new ArgumentException(nameof(securityNumber));
}
if (String.IsNullOrWhiteSpace(cardHolderName))
{
throw new ArgumentException(nameof(cardHolderName));
}
_cardNumber = !string.IsNullOrWhiteSpace(cardNumber) ? cardNumber : throw new ArgumentException(nameof(cardNumber));
_securityNumber = !string.IsNullOrWhiteSpace(securityNumber) ? securityNumber : throw new ArgumentException(nameof(securityNumber));
_cardHolderName = !string.IsNullOrWhiteSpace(cardHolderName) ? cardHolderName : throw new ArgumentException(nameof(cardHolderName));
if (expiration < DateTime.UtcNow)
{
@ -42,9 +32,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
}
_alias = alias;
_cardNumber = cardNumber;
_securityNumber = securityNumber;
_cardHolderName = cardHolderName;
_expiration = expiration;
_cardTypeId = cardTypeId;
}

View File

@ -22,12 +22,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
public BuyerRepository(OrderingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_context = context;
_context = context ?? throw new ArgumentNullException(nameof(context));
}
public Buyer Add(Buyer buyer)

View File

@ -19,12 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
public OrderRepository(OrderingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
_context = context;
_context = context ?? throw new ArgumentNullException(nameof(context));
}
public Order Add(Order order)