Adding guards and more tests (#68)
* Adding single entity by spec method to repository * Adding guards and more unit tests
This commit is contained in:
23
src/ApplicationCore/Exceptions/BasketNotFoundException.cs
Normal file
23
src/ApplicationCore/Exceptions/BasketNotFoundException.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace ApplicationCore.Exceptions
|
||||
{
|
||||
public class BasketNotFoundException : Exception
|
||||
{
|
||||
public BasketNotFoundException(int basketId) : base($"No basket found with id {basketId}")
|
||||
{
|
||||
}
|
||||
|
||||
protected BasketNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
|
||||
public BasketNotFoundException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public BasketNotFoundException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/ApplicationCore/Exceptions/GuardExtensions.cs
Normal file
14
src/ApplicationCore/Exceptions/GuardExtensions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using ApplicationCore.Exceptions;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
|
||||
namespace Ardalis.GuardClauses
|
||||
{
|
||||
public static class FooGuard
|
||||
{
|
||||
public static void NullBasket(this IGuardClause guardClause, int basketId, Basket basket)
|
||||
{
|
||||
if (basket == null)
|
||||
throw new BasketNotFoundException(basketId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user