diff --git a/src/Domain.LinnApps/PurchaseOrders/PurchaseOrderDetail.cs b/src/Domain.LinnApps/PurchaseOrders/PurchaseOrderDetail.cs index 4f1eb2fc5..d53d519fc 100644 --- a/src/Domain.LinnApps/PurchaseOrders/PurchaseOrderDetail.cs +++ b/src/Domain.LinnApps/PurchaseOrders/PurchaseOrderDetail.cs @@ -130,7 +130,12 @@ public bool ValidPrices() { return false; } - + + if (this.BaseOrderUnitPrice < 0) + { + return false; + } + return true; } diff --git a/tests/Unit/Domain.LinnApps.Tests/PurchaseOrderServiceTests/WhenUpdatingAndNegativeBaseUnitPrice.cs b/tests/Unit/Domain.LinnApps.Tests/PurchaseOrderServiceTests/WhenUpdatingAndNegativeBaseUnitPrice.cs new file mode 100644 index 000000000..a1da723e9 --- /dev/null +++ b/tests/Unit/Domain.LinnApps.Tests/PurchaseOrderServiceTests/WhenUpdatingAndNegativeBaseUnitPrice.cs @@ -0,0 +1,63 @@ +namespace Linn.Purchasing.Domain.LinnApps.Tests.PurchaseOrderServiceTests +{ + using System; + using System.Collections.Generic; + + using FluentAssertions; + + using Linn.Purchasing.Domain.LinnApps.Exceptions; + using Linn.Purchasing.Domain.LinnApps.PurchaseLedger; + using Linn.Purchasing.Domain.LinnApps.PurchaseOrders; + + using NSubstitute; + + using NUnit.Framework; + + public class WhenUpdatingAndNegativeBaseUnitPrice : ContextBase + { + private readonly int orderNumber = 600179; + + private PurchaseOrder updated; + + private Action act; + + [SetUp] + public void SetUp() + { + this.updated = new PurchaseOrder + { + OrderNumber = this.orderNumber, + Details = + new List + { + new PurchaseOrderDetail + { + Cancelled = "N", + Line = 1, + BaseNetTotal = 100m, + NetTotalCurrency = 120m, + BaseOrderUnitPrice = -100m, + OrderNumber = this.orderNumber, + OurQty = 99m, + OrderQty = 12m, + PartNumber = "P" + } + } + }; + + this.MockAuthService.HasPermissionFor(AuthorisedAction.PurchaseOrderUpdate, Arg.Any>()) + .Returns(true); + + this.PurchaseLedgerMaster.GetRecord().Returns(new PurchaseLedgerMaster { OkToRaiseOrder = "Y" }); + + this.act = () => this.Sut.UpdateOrder(new PurchaseOrder(), this.updated, new List()); + } + + + [Test] + public void ShouldThrow() + { + this.act.Should().Throw("Prices must be positive numbers"); + } + } +}