Я получаю непрерывную ошибку IndexOutOfRangeException в моем коде C#. Ниже приведен фрагмент кода:Проблема, связанная с IndexOutOfRangeException
public void GetAccountSalesDataTestWithAccountsIncluded()
{
AccountSalesDataRepository target = new AccountSalesDataRepository();
AccountSalesDataSearchCriteria[] searchCriteria = new AccountSalesDataSearchCriteria[2]
{
new AccountSalesDataSearchCriteria
{
ProgramAccountId = new AccountSalesDataSearchCriteria.SearchCriteria<int>[1] { new AccountSalesDataSearchCriteria.SearchCriteria<int>(98, true) }
},
new AccountSalesDataSearchCriteria()
};
AccountSalesDataSummary[] results;
results = target.GetAggregateAccountSalesData(searchCriteria, true);
try
{
Assert.IsNotNull(results, "The result set should not be null with the given account");
Assert.IsTrue(results.Length > 0, "The result set should not be empty with given account");
}
catch (AssertFailedException /*ex*/)
{
}
this.AccountSalesDataSummaryBasicTest(results, true);
try
{
Assert.AreEqual(results[0].AccountId, 2);
Assert.AreEqual(results[0].TotalPurchaseAmount, decimal.Parse("200"), "The total purchase amount is incorrect");
Assert.AreEqual(results[0].TotalPurchaseQuantity, 2000, "The total purchase quantity is incorrect");
Assert.AreEqual(results[0].TotalSaleQuantity, double.Parse("200"), "The total sales quantity is incorrect");
Assert.AreEqual(results[0].TotalSalesAmount, decimal.Parse("20"), "The total sales amount is incorrect");
}
catch (AssertFailedException /*ex*/)
{
}
}
Что может быть вероятной причиной этого?
Прошу простить меня, если я могу дать понять, что я не согласен с моими концепциями, потому что я действительно новичок в этом.
В какой строке выбрано исключение. –
Assert.AreEqual (результаты [0] .AccountId, 2); Все утверждения assert.areequal дают такую же ошибку. – ssingh
Как насчет запуска с 'Assert.IsTrue (results.Count> 0)'? –