4 changed files with 101 additions and 4 deletions
@ -1,14 +1,21 @@ |
|||
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints |
|||
{ |
|||
public class UpdateCatalogItemRequest : BaseRequest |
|||
{ |
|||
[Range(1, 10000)] |
|||
public int Id { get; set; } |
|||
[Range(1, 10000)] |
|||
public int CatalogBrandId { get; set; } |
|||
[Range(1, 10000)] |
|||
public int CatalogTypeId { get; set; } |
|||
[Required] |
|||
public string Description { get; set; } |
|||
[Required] |
|||
public string Name { get; set; } |
|||
public string PictureUri { get; set; } |
|||
[Range(0.01, 10000)] |
|||
public decimal Price { get; set; } |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,60 @@ |
|||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; |
|||
using System.Collections.Generic; |
|||
using Microsoft.eShopWeb.UnitTests.Builders; |
|||
using Xunit; |
|||
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|||
using System; |
|||
|
|||
namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.OrderTests |
|||
{ |
|||
public class UpdateDetails |
|||
{ |
|||
private CatalogItem _testItem; |
|||
private decimal _testUnitPrice = 42m; |
|||
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)); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue