Adding guards and more tests (#68)
* Adding single entity by spec method to repository * Adding guards and more unit tests
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using ApplicationCore.Exceptions;
|
||||
using ApplicationCore.Interfaces;
|
||||
using ApplicationCore.Services;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Moq;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace UnitTests.ApplicationCore.Services.BasketServiceTests
|
||||
{
|
||||
public class SetQuantities
|
||||
{
|
||||
private int _invalidId = -1;
|
||||
private Mock<IAsyncRepository<Basket>> _mockBasketRepo;
|
||||
|
||||
public SetQuantities()
|
||||
{
|
||||
_mockBasketRepo = new Mock<IAsyncRepository<Basket>>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ThrowsGivenInvalidBasketId()
|
||||
{
|
||||
var basketService = new BasketService(_mockBasketRepo.Object, null, null, null);
|
||||
|
||||
await Assert.ThrowsAsync<BasketNotFoundException>(async () =>
|
||||
await basketService.SetQuantities(_invalidId, new System.Collections.Generic.Dictionary<string, int>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ThrowsGivenNullQuantities()
|
||||
{
|
||||
var basketService = new BasketService(null, null, null, null);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
|
||||
await basketService.SetQuantities(123, null));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using ApplicationCore.Services;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace UnitTests.ApplicationCore.Services.BasketServiceTests
|
||||
{
|
||||
public class TransferBasket
|
||||
{
|
||||
[Fact]
|
||||
public async void ThrowsGivenNullAnonymousId()
|
||||
{
|
||||
var basketService = new BasketService(null, null, null, null);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await basketService.TransferBasketAsync(null, "steve"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ThrowsGivenNullUserId()
|
||||
{
|
||||
var basketService = new BasketService(null, null, null, null);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await basketService.TransferBasketAsync("abcdefg", null));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user