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:
Steve Smith
2017-10-30 11:53:29 -07:00
committed by GitHub
parent 3d46c80cff
commit b864be9265
10 changed files with 119 additions and 1 deletions

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}