Skip to content

Instantly share code, notes, and snippets.

@Imater
Created October 1, 2014 10:23
Show Gist options
  • Save Imater/474aabda872be40e3945 to your computer and use it in GitHub Desktop.
Save Imater/474aabda872be40e3945 to your computer and use it in GitHub Desktop.
test for cases in c#
using System;
using Ksnsi.Services.Validation.ColValidators;
using NUnit.Framework;
namespace Ksnsi.Services.Tests
{
[TestFixture]
internal class ColValidatorNumericTest
{
private IColValidator _validator;
public TestCaseData[] TestValidationTestCases()
{
return new[]
{
new TestCaseData("5,35", 1, 2).Returns(5.35),
new TestCaseData("5", 1, 2).Returns(5),
new TestCaseData("5.55", 1, 2).Returns(5.55),
new TestCaseData(" 5.55 ", 1, 2).Returns(5.55),
new TestCaseData("0", 1, 2).Returns(0),
new TestCaseData(".1", 1, 2).Returns(0.1),
new TestCaseData("0.0", 1, 2).Returns(0),
new TestCaseData(".0", 1, 2).Returns(0),
new TestCaseData("", 1, 2).Returns(null),
new TestCaseData(null, 1, 2).Returns(null),
new TestCaseData("4-8", 1, 2).Returns(null),
new TestCaseData("word", 1, 2).Returns(null)
};
}
[TestFixtureSetUp]
public void SetUp()
{
var autoSelectValidator = new AutoSelectValidator();
_validator = autoSelectValidator.GetValidator("Numeric");
}
[Test]
[TestCaseSource("TestValidationTestCases")]
public object NumericTest(string paramValue, int columnIndex, int rowIndex)
{
ColValidationResult colValidationResult = _validator.Validate(paramValue, columnIndex, rowIndex);
return colValidationResult.Value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment