public void FieldParserCreationTest() { // Arrange var propertyName = "StringProperty"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); // Assert var expected = propertyName; var actual = fieldParser.FieldName; Assert.AreEqual<string>(expected, actual); }
public void FieldParserWithPatternFailedTest() { // Arrange var propertyName = "StringPropertyWithPattern"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse("****"); // Assert Assert.IsNull(actual); var expectedErrorCount = 1; var actualErrorCount = fieldParser.Errors.Count(); Assert.AreEqual<int>(expectedErrorCount, actualErrorCount); var expectedErrorMessage = String.Format("{0}: {1} does not match pattern >>> {2}", fieldParser.FieldName, fieldParser.FieldInput, fieldParser.ParseBehavior.Pattern); var actualErrorMessage = fieldParser.Errors.Single(); Assert.AreEqual<string>(expectedErrorMessage, actualErrorMessage); }
public void FieldParserWithPatternTest() { // Arrange var propertyName = "StringPropertyWithPattern"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse("*****@*****.**"); // Assert var expected = "*****@*****.**"; Assert.AreEqual(expected, actual); Assert.IsFalse(fieldParser.Errors.Any()); }
public void ParseSingleUnparsableTest() { // Arrange var propertyName = "SingleProperty"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse("ABCD"); // Assert Assert.IsNull(actual); var expectedErrorCount = 1; var actualErrorCount = fieldParser.Errors.Count(); Assert.AreEqual<int>(expectedErrorCount, actualErrorCount); var expectedErrorMessage = String.Format("{0}: Unparsable System.Single >>> {1}", fieldParser.FieldName, fieldParser.FieldInput); var actualErrorMessage = fieldParser.Errors.Single(); Assert.AreEqual<string>(expectedErrorMessage, actualErrorMessage); }
public void ParseSingleTest() { // Arrange var propertyName = "SingleProperty"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse("9.87"); // Assert Assert.IsNotNull(actual); Assert.IsFalse(fieldParser.Errors.Any()); }
public void ParseNullableInt32Test() { // Arrange var propertyName = "NullableInt32Property"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse(String.Empty); // Assert Assert.IsNull(actual); Assert.IsFalse(fieldParser.Errors.Any()); }
public void ParseInt64Test() { // Arrange var propertyName = "Int64Property"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); var input = (Int64.MaxValue).ToString(); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse(input); // Assert Assert.IsNotNull(actual); Assert.IsFalse(fieldParser.Errors.Any()); }
public void ParseInt64OverflowTest() { // Arrange var propertyName = "Int64Property"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Deliberate concatenation, not a addition... var input = Int64.MaxValue.ToString() + "0"; // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse(input); // Assert Assert.IsNull(actual); var expectedErrorCount = 1; var actualErrorCount = fieldParser.Errors.Count(); Assert.AreEqual<int>(expectedErrorCount, actualErrorCount); var expectedErrorMessage = String.Format("{0}: Unparsable {1} >>> {2}", fieldParser.FieldName, fieldParser.FieldType, fieldParser.FieldInput); var actualErrorMessage = fieldParser.Errors.Single(); Assert.AreEqual<string>(expectedErrorMessage, actualErrorMessage); }
public void ParseDateTimeTest() { // Arrange var propertyName = "DateTimeProperty"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse("24/12/1900"); // Assert var expected = new DateTime(1900, 12, 24); Assert.AreEqual(expected, actual); Assert.IsFalse(fieldParser.Errors.Any()); }
public void ParseByteTest() { // Arrange var propertyName = "ByteProperty"; var propertyInfo = typeof(Foo).GetProperties().Single(p => p.Name == propertyName); // Act var fieldParser = new FieldParser(propertyInfo); var actual = fieldParser.Parse("123"); // Assert var expected = (byte) 123; Assert.AreEqual(expected, actual); Assert.IsFalse(fieldParser.Errors.Any()); }