Browse Source
* Introduce nullable types to Core, Infrastructure and PublicApi projects * Refactor unit tests * Fixed failing tests * Introduce Parameter object for CatalogItem update method * Refactor CataloItemDetails param object * Refactor following PR commentsmain
committed by
GitHub
51 changed files with 168 additions and 256 deletions
@ -1,55 +0,0 @@ |
|||||
using System; |
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.CatalogItemTests; |
|
||||
|
|
||||
public class UpdateDetails |
|
||||
{ |
|
||||
private CatalogItem _testItem; |
|
||||
private int _validTypeId = 1; |
|
||||
private int _validBrandId = 2; |
|
||||
private string _validDescription = "test description"; |
|
||||
private string _validName = "test name"; |
|
||||
private decimal _validPrice = 1.23m; |
|
||||
private string _validUri = "/123"; |
|
||||
|
|
||||
public UpdateDetails() |
|
||||
{ |
|
||||
_testItem = new CatalogItem(_validTypeId, _validBrandId, _validDescription, _validName, _validPrice, _validUri); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void ThrowsArgumentExceptionGivenEmptyName() |
|
||||
{ |
|
||||
string newValue = ""; |
|
||||
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(newValue, _validDescription, _validPrice)); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void ThrowsArgumentExceptionGivenEmptyDescription() |
|
||||
{ |
|
||||
string newValue = ""; |
|
||||
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(_validName, newValue, _validPrice)); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void ThrowsArgumentNullExceptionGivenNullName() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentNullException>(() => _testItem.UpdateDetails(null, _validDescription, _validPrice)); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void ThrowsArgumentNullExceptionGivenNullDescription() |
|
||||
{ |
|
||||
Assert.Throws<ArgumentNullException>(() => _testItem.UpdateDetails(_validName, null, _validPrice)); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(0)] |
|
||||
[InlineData(-1.23)] |
|
||||
public void ThrowsArgumentExceptionGivenNonPositivePrice(decimal newPrice) |
|
||||
{ |
|
||||
Assert.Throws<ArgumentException>(() => _testItem.UpdateDetails(_validName, _validDescription, newPrice)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,34 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
||||
using Microsoft.eShopWeb.ApplicationCore.Exceptions; |
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; |
|
||||
using Microsoft.eShopWeb.ApplicationCore.Services; |
|
||||
using Moq; |
|
||||
using Xunit; |
|
||||
|
|
||||
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