Adding additional unit tests (#406)
* Creating new test class for RemoveEmptyItems * Adding tests for AddItemToBasket in BasketService * Removing unused GetBasketItemCountAsync * Adding tests for BasketWithItemsSpecification * Adding CustomerORdersWithItemsSpecification tests * Adding CatalogFilterPaginatedSpecifciation tests * Adding CatalogItemsSpecification tests
This commit is contained in:
@@ -22,8 +22,8 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate
|
||||
ShipToAddress = shipToAddress;
|
||||
_orderItems = items;
|
||||
}
|
||||
public string BuyerId { get; private set; }
|
||||
|
||||
public string BuyerId { get; private set; }
|
||||
public DateTimeOffset OrderDate { get; private set; } = DateTimeOffset.Now;
|
||||
public Address ShipToAddress { get; private set; }
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate
|
||||
{
|
||||
|
||||
public class OrderItem : BaseEntity
|
||||
{
|
||||
public CatalogItemOrdered ItemOrdered { get; private set; }
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<int> GetBasketItemCountAsync(string userName);
|
||||
Task TransferBasketAsync(string anonymousId, string userName);
|
||||
Task AddItemToBasket(int basketId, int catalogItemId, decimal price, int quantity = 1);
|
||||
Task SetQuantities(int basketId, Dictionary<string, int> quantities);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Specifications;
|
||||
using System.Linq;
|
||||
using Ardalis.GuardClauses;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
||||
|
||||
@@ -37,21 +36,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
|
||||
await _basketRepository.DeleteAsync(basket);
|
||||
}
|
||||
|
||||
public async Task<int> GetBasketItemCountAsync(string userName)
|
||||
{
|
||||
Guard.Against.NullOrEmpty(userName, nameof(userName));
|
||||
var basketSpec = new BasketWithItemsSpecification(userName);
|
||||
var basket = (await _basketRepository.FirstOrDefaultAsync(basketSpec));
|
||||
if (basket == null)
|
||||
{
|
||||
_logger.LogInformation($"No basket found for {userName}");
|
||||
return 0;
|
||||
}
|
||||
int count = basket.Items.Sum(i => i.Quantity);
|
||||
_logger.LogInformation($"Basket for {userName} has {count} items.");
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task SetQuantities(int basketId, Dictionary<string, int> quantities)
|
||||
{
|
||||
Guard.Against.Null(quantities, nameof(quantities));
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
{
|
||||
AddInclude(b => b.Items);
|
||||
}
|
||||
|
||||
public BasketWithItemsSpecification(string buyerId) : base(b => b.BuyerId == buyerId)
|
||||
{
|
||||
AddInclude(b => b.Items);
|
||||
|
||||
Reference in New Issue
Block a user