This NUnit TestFixture demonstrates some unexpected behavior in CPayments. Note that you will need to alter or provide some of the values to run on your machine, if you so choose, but I think you can see by reading this some gotchas to look out for:
using System;
using System.Configuration;
using Asi.iBO;
using Asi.iBO.Financials;
using NUnit.Framework;
namespace Crown.Imis.IntegrationTests
{
[TestFixture, Explicit("demos")]
public class CPaymentGotchaDemonstrations
{
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
iboAdmin.InitializeSystem(ConfigurationManager.ConnectionStrings["DataSource.iMIS.Connection"].ConnectionString);
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Demo_Setting_CreditCardNumber_toVisaTestNumberAfterSetting_CashAccountCode_CausesUnhandledException()
{
var payment = new CPayment(CStaffUser.GetDefaultStaffUser())
{
CashAccountCode = "VISA",
CreditCardNumber = "4007000000027" // VISA test number, eh?
};
}
[Test]
[ExpectedException(typeof(Asi.iBO.InvalidCardNumberException))]
public void Demo_Setting_CreditCardNumber_to011201539123After_CashAccountCode_Causes_InvalidCardNumberException()
{
var payment = new CPayment(CStaffUser.GetDefaultStaffUser())
{
CashAccountCode = "VISA",
CreditCardNumber = "011201539123" // it's irrelevant how I came up with this number. No idea yet on what is wrong with it.
};
}
[Test]
public void Demo_Setting_PaymentType_After_CreditCardNumber_Clears_CreditCardNumber()
{
var payment = new CPayment(CStaffUser.GetDefaultStaffUser())
{
CreditCardNumber = "4007000000027", // VISA test number
PaymentType = EnumPaymentType.Check
};
Assert.IsNullOrEmpty(payment.CreditCardNumber);
}
[Test]
public void Demo_SettingCashAccountCodeChangesPaymentTypeToCreditWhenCashAccountIsCreditType()
{
var payment = new CPayment(CStaffUser.GetDefaultStaffUser());
payment.PaymentType = EnumPaymentType.Check;
payment.CashAccountCode = "VISA";
Assert.AreEqual(EnumPaymentType.CreditCard, payment.PaymentType);
}
}
}