Browse Source
* Updating repositories and specification version Need to fix broken tests * removing test that would just be testing mocked result now * Refactored from IAsyncRepository and removed it. Tests pass. * Update packagesmain
committed by
GitHub
39 changed files with 281 additions and 289 deletions
@ -1,21 +0,0 @@ |
|||
using Ardalis.Specification; |
|||
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Microsoft.eShopWeb.ApplicationCore.Interfaces |
|||
{ |
|||
public interface IAsyncRepository<T> where T : BaseEntity, IAggregateRoot |
|||
{ |
|||
Task<T> GetByIdAsync(int id, CancellationToken cancellationToken = default); |
|||
Task<IReadOnlyList<T>> ListAllAsync(CancellationToken cancellationToken = default); |
|||
Task<IReadOnlyList<T>> ListAsync(ISpecification<T> spec, CancellationToken cancellationToken = default); |
|||
Task<T> AddAsync(T entity, CancellationToken cancellationToken = default); |
|||
Task UpdateAsync(T entity, CancellationToken cancellationToken = default); |
|||
Task DeleteAsync(T entity, CancellationToken cancellationToken = default); |
|||
Task<int> CountAsync(ISpecification<T> spec, CancellationToken cancellationToken = default); |
|||
Task<T> FirstAsync(ISpecification<T> spec, CancellationToken cancellationToken = default); |
|||
Task<T> FirstOrDefaultAsync(ISpecification<T> spec, CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Ardalis.Specification; |
|||
|
|||
namespace Microsoft.eShopWeb.ApplicationCore.Interfaces |
|||
{ |
|||
public interface IReadRepository<T> : IReadRepositoryBase<T> where T : class, IAggregateRoot |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Ardalis.Specification; |
|||
|
|||
namespace Microsoft.eShopWeb.ApplicationCore.Interfaces |
|||
{ |
|||
public interface IRepository<T> : IRepositoryBase<T> where T : class, IAggregateRoot |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using Ardalis.Specification; |
|||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; |
|||
|
|||
namespace Microsoft.eShopWeb.ApplicationCore.Specifications |
|||
{ |
|||
public class OrderWithItemsByIdSpec : Specification<Order>, ISingleResultSpecification |
|||
{ |
|||
public OrderWithItemsByIdSpec(int orderId) |
|||
{ |
|||
Query |
|||
.Where(order => order.Id == orderId) |
|||
.Include(o => o.OrderItems) |
|||
.ThenInclude(i => i.ItemOrdered); |
|||
} |
|||
} |
|||
} |
|||
@ -1,40 +1,35 @@ |
|||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|||
using Microsoft.eShopWeb.ApplicationCore.Exceptions; |
|||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; |
|||
using Microsoft.eShopWeb.ApplicationCore.Services; |
|||
using Moq; |
|||
using System; |
|||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|||
using Microsoft.eShopWeb.ApplicationCore.Exceptions; |
|||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; |
|||
using Microsoft.eShopWeb.ApplicationCore.Services; |
|||
using Moq; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Xunit; |
|||
using Xunit; |
|||
|
|||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests |
|||
{ |
|||
public class SetQuantities |
|||
{ |
|||
private readonly int _invalidId = -1; |
|||
private readonly Mock<IAsyncRepository<Basket>> _mockBasketRepo; |
|||
|
|||
public SetQuantities() |
|||
{ |
|||
_mockBasketRepo = new Mock<IAsyncRepository<Basket>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ThrowsGivenInvalidBasketId() |
|||
{ |
|||
var basketService = new BasketService(_mockBasketRepo.Object, null); |
|||
|
|||
await Assert.ThrowsAsync<BasketNotFoundException>(async () => |
|||
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>())); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ThrowsGivenNullQuantities() |
|||
{ |
|||
var basketService = new BasketService(null, null); |
|||
|
|||
await Assert.ThrowsAsync<ArgumentNullException>(async () => |
|||
await basketService.SetQuantities(123, null)); |
|||
} |
|||
} |
|||
} |
|||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests |
|||
{ |
|||
public class SetQuantities |
|||
{ |
|||
private readonly int _invalidId = -1; |
|||
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new(); |
|||
|
|||
[Fact] |
|||
public async Task ThrowsGivenInvalidBasketId() |
|||
{ |
|||
var basketService = new BasketService(_mockBasketRepo.Object, null); |
|||
|
|||
await Assert.ThrowsAsync<BasketNotFoundException>(async () => |
|||
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>())); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ThrowsGivenNullQuantities() |
|||
{ |
|||
var basketService = new BasketService(null, null); |
|||
|
|||
await Assert.ThrowsAsync<ArgumentNullException>(async () => |
|||
await basketService.SetQuantities(123, null)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue