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.Entities.BasketAggregate; |
||||
using Microsoft.eShopWeb.ApplicationCore.Exceptions; |
using Microsoft.eShopWeb.ApplicationCore.Exceptions; |
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; |
using Microsoft.eShopWeb.ApplicationCore.Interfaces; |
||||
using Microsoft.eShopWeb.ApplicationCore.Services; |
using Microsoft.eShopWeb.ApplicationCore.Services; |
||||
using Moq; |
using Moq; |
||||
using System; |
using System; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Xunit; |
using Xunit; |
||||
|
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests |
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Services.BasketServiceTests |
||||
{ |
{ |
||||
public class SetQuantities |
public class SetQuantities |
||||
{ |
{ |
||||
private readonly int _invalidId = -1; |
private readonly int _invalidId = -1; |
||||
private readonly Mock<IAsyncRepository<Basket>> _mockBasketRepo; |
private readonly Mock<IRepository<Basket>> _mockBasketRepo = new(); |
||||
|
|
||||
public SetQuantities() |
[Fact] |
||||
{ |
public async Task ThrowsGivenInvalidBasketId() |
||||
_mockBasketRepo = new Mock<IAsyncRepository<Basket>>(); |
{ |
||||
} |
var basketService = new BasketService(_mockBasketRepo.Object, null); |
||||
|
|
||||
[Fact] |
await Assert.ThrowsAsync<BasketNotFoundException>(async () => |
||||
public async Task ThrowsGivenInvalidBasketId() |
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>())); |
||||
{ |
} |
||||
var basketService = new BasketService(_mockBasketRepo.Object, null); |
|
||||
|
[Fact] |
||||
await Assert.ThrowsAsync<BasketNotFoundException>(async () => |
public async Task ThrowsGivenNullQuantities() |
||||
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>())); |
{ |
||||
} |
var basketService = new BasketService(null, null); |
||||
|
|
||||
[Fact] |
await Assert.ThrowsAsync<ArgumentNullException>(async () => |
||||
public async Task ThrowsGivenNullQuantities() |
await basketService.SetQuantities(123, null)); |
||||
{ |
} |
||||
var basketService = new BasketService(null, null); |
} |
||||
|
} |
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => |
|
||||
await basketService.SetQuantities(123, null)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|||||
Loading…
Reference in new issue