Adding Tests and Refactoring
Functional Tests for RazorPages added
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ApplicationCore.Entities.OrderAggregate
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using ApplicationCore.Exceptions;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
||||
|
||||
namespace Ardalis.GuardClauses
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using ApplicationCore.Entities.OrderAggregate;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ApplicationCore.Interfaces
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Infrastructure.Data
|
||||
{
|
||||
return _dbContext.Orders
|
||||
.Include(o => o.OrderItems)
|
||||
.Include("OrderItems.ItemOrdered")
|
||||
.Include($"{nameof(Order.OrderItems)}.{nameof(OrderItem.ItemOrdered)}")
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Infrastructure.Data
|
||||
{
|
||||
return _dbContext.Orders
|
||||
.Include(o => o.OrderItems)
|
||||
.Include("OrderItems.ItemOrdered")
|
||||
.Include($"{nameof(Order.OrderItems)}.{nameof(OrderItem.ItemOrdered)}")
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,28 +69,5 @@ namespace Microsoft.eShopWeb.Controllers
|
||||
};
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
private OrderViewModel GetOrder()
|
||||
{
|
||||
var order = new OrderViewModel()
|
||||
{
|
||||
OrderDate = DateTimeOffset.Now.AddDays(-1),
|
||||
OrderNumber = 12354,
|
||||
Status = "Submitted",
|
||||
Total = 123.45m,
|
||||
ShippingAddress = new Address("123 Main St.", "Kent", "OH", "United States", "44240")
|
||||
};
|
||||
|
||||
order.OrderItems.Add(new OrderItemViewModel()
|
||||
{
|
||||
ProductId = 1,
|
||||
PictureUrl = "",
|
||||
ProductName = "Something",
|
||||
UnitPrice = 5.05m,
|
||||
Units = 2
|
||||
});
|
||||
|
||||
return order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,15 @@ namespace Microsoft.eShopWeb
|
||||
public void ConfigureDevelopmentServices(IServiceCollection services)
|
||||
{
|
||||
// use in-memory database
|
||||
ConfigureTestingServices(services);
|
||||
ConfigureInMemoryDatabases(services);
|
||||
|
||||
// use real database
|
||||
// ConfigureProductionServices(services);
|
||||
|
||||
ConfigureServices(services);
|
||||
}
|
||||
public void ConfigureTestingServices(IServiceCollection services)
|
||||
|
||||
private void ConfigureInMemoryDatabases(IServiceCollection services)
|
||||
{
|
||||
// use in-memory database
|
||||
services.AddDbContext<CatalogContext>(c =>
|
||||
@@ -46,8 +48,6 @@ namespace Microsoft.eShopWeb
|
||||
// Add Identity DbContext
|
||||
services.AddDbContext<AppIdentityDbContext>(options =>
|
||||
options.UseInMemoryDatabase("Identity"));
|
||||
|
||||
ConfigureServices(services);
|
||||
}
|
||||
|
||||
public void ConfigureProductionServices(IServiceCollection services)
|
||||
@@ -86,6 +86,10 @@ namespace Microsoft.eShopWeb
|
||||
options.ExpireTimeSpan = TimeSpan.FromHours(1);
|
||||
options.LoginPath = "/Account/Signin";
|
||||
options.LogoutPath = "/Account/Signout";
|
||||
options.Cookie = new CookieBuilder
|
||||
{
|
||||
IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy
|
||||
};
|
||||
});
|
||||
|
||||
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
|
||||
|
||||
Reference in New Issue
Block a user