Adding Tests and Refactoring

Functional Tests for RazorPages added
This commit is contained in:
Steve Smith
2018-05-31 12:28:55 -04:00
parent 5fb9e741dd
commit 814d3e249c
22 changed files with 275 additions and 142 deletions

View File

@@ -1,8 +1,7 @@
using ApplicationCore.Interfaces;
using Ardalis.GuardClauses;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace ApplicationCore.Entities.BuyerAggregate
{
@@ -14,13 +13,15 @@ namespace ApplicationCore.Entities.BuyerAggregate
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly();
protected Buyer()
private Buyer()
{
// required by EF
}
public Buyer(string identity) : this()
{
IdentityGuid = !string.IsNullOrWhiteSpace(identity) ? identity : throw new ArgumentNullException(nameof(identity));
Guard.Against.NullOrEmpty(identity, nameof(identity));
IdentityGuid = identity;
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
namespace ApplicationCore.Entities.OrderAggregate
{

View File

@@ -1,21 +1,29 @@
namespace ApplicationCore.Entities.OrderAggregate
using Ardalis.GuardClauses;
namespace ApplicationCore.Entities.OrderAggregate
{
/// <summary>
/// Represents the item that was ordered. If catalog item details change, details of
/// Represents a snapshot of the item that was ordered. If catalog item details change, details of
/// the item that was part of a completed order should not change.
/// </summary>
public class CatalogItemOrdered // ValueObject
{
public CatalogItemOrdered(int catalogItemId, string productName, string pictureUri)
{
Guard.Against.OutOfRange(catalogItemId, nameof(catalogItemId), 1, int.MaxValue);
Guard.Against.NullOrEmpty(productName, nameof(productName));
Guard.Against.NullOrEmpty(pictureUri, nameof(pictureUri));
CatalogItemId = catalogItemId;
ProductName = productName;
PictureUri = pictureUri;
}
private CatalogItemOrdered()
{
// required by EF
}
public int CatalogItemId { get; private set; }
public string ProductName { get; private set; }
public string PictureUri { get; private set; }

View File

@@ -1,4 +1,5 @@
using ApplicationCore.Interfaces;
using Ardalis.GuardClauses;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using System;
using System.Collections.Generic;
@@ -9,13 +10,18 @@ namespace ApplicationCore.Entities.OrderAggregate
{
private Order()
{
// required by EF
}
public Order(string buyerId, Address shipToAddress, List<OrderItem> items)
{
Guard.Against.NullOrEmpty(buyerId, nameof(buyerId));
Guard.Against.Null(shipToAddress, nameof(shipToAddress));
Guard.Against.Null(items, nameof(items));
BuyerId = buyerId;
ShipToAddress = shipToAddress;
_orderItems = items;
BuyerId = buyerId;
}
public string BuyerId { get; private set; }
@@ -43,6 +49,5 @@ namespace ApplicationCore.Entities.OrderAggregate
}
return total;
}
}
}

View File

@@ -9,9 +9,11 @@ namespace ApplicationCore.Entities.OrderAggregate
public decimal UnitPrice { get; private set; }
public int Units { get; private set; }
protected OrderItem()
private OrderItem()
{
// required by EF
}
public OrderItem(CatalogItemOrdered itemOrdered, decimal unitPrice, int units)
{
ItemOrdered = itemOrdered;

View File

@@ -1,5 +1,4 @@
using ApplicationCore.Exceptions;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
namespace Ardalis.GuardClauses

View File

@@ -1,5 +1,4 @@
using ApplicationCore.Entities.OrderAggregate;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ApplicationCore.Interfaces