Почему мой метод тестирования NUnit всегда проходит проверку некоторых функций расчетаC#

Место общения программистов C#
Ответить
Anonymous
 Почему мой метод тестирования NUnit всегда проходит проверку некоторых функций расчета

Сообщение Anonymous »

У меня есть сценарий, что мой метод модульного тестирования потерпит неудачу, если я изменю вызываемый/реализация моего метода презентатора. пожалуйста, смотрите ниже, дайте мне знать, если не получите это.

Код: Выделить всё

    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
}

Теперь, как мне подтвердить, что расчет в методе SaveOrderAllocation в моем классе изменится. как показано ниже

Код: Выделить всё

            if (!orderAllocation.IsUnlimitedAllocation)
{
if (orderAllocation.PreorderAllocationQty != null &
orderAllocation.PreorderAllocationQty.HasValue)
maxOfNinetyPercentAllocationQty = (int?)(.9 * preorderAllocation.PreorderAllocationQty.Value);
if (maxOfNinetyPercentAllocationQty != null) title.PreorderAllocation = maxOfNinetyPercentAllocationQty.Value;
}
в этом случае мой описанный выше метод тестирования должен дать сбой? как мне утверждать, не меняя тело метода (SaveOrderAllocation). пожалуйста, помогите.
Заранее спасибо.

Подробнее здесь: https://stackoverflow.com/questions/792 ... ctionality
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»