Код: Выделить всё
public SaveActionResultWithCustomizedErrors SaveOrderAllocation(OrderAllocation orderAllocation, FillOrderOutput fillOrderOutput)
{
var saveResult = new SaveActionResultWithCustomizedErrors();
int? maxOfNinetyPercentAllocationQty = null;
//// this is the class where I need to pass orderAllocation greater of either 90% of the Order Allocation Qty OR Pre Order Demand (Open + Released + Shipped).
var title = new orderAllocationInput() {Ean = orderAllocation.Ean};
try
{
//validate pre order allocation qty before sending to product master using isUnlimited flag.
if (!orderAllocation.IsUnlimitedAllocation)
{
if (orderAllocation.PreorderAllocationQty != null &
orderAllocation.PreorderAllocationQty.HasValue)
{
var preDemandQty = (fillOrderOutput.OpenQuantity + fillOrderOutput.ReleasedQuantity + fillOrderOutput.ShippedQuantity);
maxOfNinetyPercentAllocationQty = Math.Max(.9 * orderAllocation.PreorderAllocationQty.Value, preDemandQty).RoundToInt();
}
if (maxOfNinetyPercentAllocationQty != null) title.PreorderAllocation = maxOfNinetyPercentAllocationQty.Value;
}
ItemDao.SavePreorderAllocation(orderAllocation, fillOrderOutput);
saveResult.SuccessfulItems.Add(orderAllocation.SystemId, orderAllocation.SystemId);
}
this works fine, now I'm looking for a NUnit test method to fullfill the above calculation.
[Test]
public void SaveOrderAllocation_With_OrderAllocationToMaxOf90Percent_Or_PreDemandQtyTest()
{
// Arrange
var orderAllocation = new OrderAllocation
{
Ean = "EAN123",
Sysid = 1,
PreorderAllocationQty = 100,
IsUnlimitedAllocation = false
};
var fillOrderOutput = new FillOrderOutput
{
OpenQuantity = 80,
ReleasedQuantity = 30,
ShippedQuantity = 20
};
var preDemandQty = fillOrderOutput.OpenQuantity + fillOrderOutput.ReleasedQuantity + fillOrderOutput.ShippedQuantity;
// The preDemandQty is 80 + 30 + 20 = 130
// 90% of 100 = 90, so max(90, 130) = 130
//var expected = (int) (testParameter.PreorderAllocationQty * .9);
var expected = Math.Max(.9 * orderAllocation.PreorderAllocationQty.Value, preDemandQty).RoundToInt();
// Act
var result = Testee.SaveOrderAllocation(orderAllocation, fillOrderOutput);
// Assert
_itemDaoMock.Verify(x => x.SavePreorderAllocation(orderAllocation, fillOrderOutput), Times.Once());
Assert.IsTrue(result.Success);
Assert.That(result.FailedItems.Count, Is.EqualTo(0));
Assert.That(result.SuccessfulItems.Count, Is.EqualTo(1));
Assert.AreEqual(expected, preDemandQty); // 130
}
Код: Выделить всё
if (!orderAllocation.IsUnlimitedAllocation)
{
if (orderAllocation.PreorderAllocationQty != null &
orderAllocation.PreorderAllocationQty.HasValue)
maxOfNinetyPercentAllocationQty = (int?)(.9 * preorderAllocation.PreorderAllocationQty.Value);
if (maxOfNinetyPercentAllocationQty != null) title.PreorderAllocation = maxOfNinetyPercentAllocationQty.Value;
}
Заранее спасибо.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ctionality
Мобильная версия