private void DestinationParserThrowsExceptionWhenSetValueDoesNotMatchDataType(Enums.DataTypes dataType, string SetValue) { // Arrange var id = new ImportDefinition(); var s = "DESTINATION Name " + dataType.ToString() + " SET {" + SetValue + "}"; var expectedException = "Destination Property Name " + "attempted to declare a Set Value of " + SetValue + " which cannot be cast to the declared data type of " + dataType.ToString(); // Act try { DestinationParser.Parse(s, id); Assert.Fail("InvalidCastException expected, not thrown."); } catch (InvalidCastException ex) { Assert.AreEqual(expectedException, ex.Message); } catch (Exception ex) { Assert.Fail("InvalidCastException expected, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserThrowsExceptionOnDuplicatePropertyName() { // Arrange var id = new ImportDefinition(); id.DestinationProperties.Add(new DestinationPropertyDefinition() { PropertyName = "APropertyName", DataType = Enums.DataTypes.STRING }); // Act try { DestinationParser.Parse("DESTINATION APropertyName STRING SET {A Value}", id); Assert.Fail("InvalidOperationException expected, not thrown."); } catch (InvalidOperationException ex) { Assert.AreEqual("A destination property named APropertyName is defined more than once.", ex.Message); } catch (Exception ex) { Assert.Fail("InvalidOperationException expected, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserThrowsExceptionWhenLineHasTooFewTokens() { try { DestinationParser.Parse("DESTINATION PropertyName", new ImportDefinition()); Assert.Fail("Expected ArgumentException, not thrown."); } catch (ArgumentException ex) { Assert.AreEqual("Destination definition line must contain at least 4 tokens.", ex.Message); } catch (Exception ex) { Assert.Fail("Expected ArgumentException, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserThrowsExceptionWhenLineNotADestination() { try { DestinationParser.Parse("COLUMN 0 MyColumn STRING", new ImportDefinition()); Assert.Fail("Expected ArgumentException, not thrown."); } catch (ArgumentException ex) { Assert.AreEqual("Line is not a DESTINATION declaration.", ex.Message); } catch (Exception ex) { Assert.Fail("Expected ArgumentException, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserCreatesGuidWithGenerate() { // Arrange var id = new ImportDefinition(); var s = "DESTINATION PropertyName GUID GENERATE"; // Act DestinationParser.Parse(s, id); // Assert Assert.AreEqual(1, id.DestinationProperties.Count); var d = id.DestinationProperties[0]; Assert.AreEqual("PropertyName", d.PropertyName); Assert.AreEqual(Enums.DataTypes.GUID, d.DataType); Assert.IsTrue(d.Generate); Assert.IsNull(d.SetValue); }
public void DestinationParserThrowsExceptionWhenDataTypeIsInvalid() { try { DestinationParser.Parse("DESTINATION APropertyName NOTATYPE SET {Not a Value}", new ImportDefinition()); Assert.Fail("InvalidOperationException expected, not thrown."); } catch (InvalidCastException ex) { Assert.AreEqual("Cannot convert the token NOTATYPE to a valid DataType.", ex.Message); } catch (Exception ex) { Assert.Fail("InvalidOperationException expected, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserThrowsExceptionWhenImportDefinitionIsNull() { // Act try { DestinationParser.Parse("DESTINATION ColumnName STRING", null); Assert.Fail("Expected ArgumentNullException, not thrown."); } catch (ArgumentNullException ex) { Assert.AreEqual("ID", ex.ParamName); } catch (Exception ex) { Assert.Fail("Expected ArgumentNullException, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserCreatesDateTimeWithGenerateDateOnly() { // Arrange var id = new ImportDefinition(); var s = "DESTINATION PropertyName DATETIME GENERATE DATEONLY"; // Act DestinationParser.Parse(s, id); // Assert Assert.AreEqual(1, id.DestinationProperties.Count); var d = id.DestinationProperties[0]; Assert.AreEqual("PropertyName", d.PropertyName); Assert.AreEqual(Enums.DataTypes.DATETIME, d.DataType); Assert.IsTrue(d.Generate); Assert.IsTrue(d.GenerateDateOnly); Assert.IsNull(d.SetValue); }
private static void ParseLine(string line, ImportDefinition id) { if (line.StartsWith("#")) { // This is a comment return; } if (line.StartsWith("COLUMN")) { ColumnDefinitionParser.Parse(line, id); return; } if (line.StartsWith("FILETYPE")) { FileTypeParser.Parse(line, id); return; } else if (line.StartsWith("HEADERROW")) { HeaderRowParser.Parse(line, id); return; } else if (line.StartsWith("TABLE")) { TableDefinitionParser.Parse(line, id); return; } else if (line.StartsWith("RULE")) { RuleDefinitionParser.Parse(line, id); return; } else if (line.StartsWith("DESTINATION")) { DestinationParser.Parse(line, id); return; } else { throw new ArgumentException("Invalid token at beginning of line: " + line); } }
private void DestinationParserCreatesDestinationOfType(Enums.DataTypes dataType, string SetValue) { // Arrange var id = new ImportDefinition(); var s = "DESTINATION Name " + dataType.ToString() + " SET {" + SetValue + "}"; // Act DestinationParser.Parse(s, id); // Assert Assert.AreEqual(1, id.DestinationProperties.Count); var d = id.DestinationProperties[0]; Assert.AreEqual("Name", d.PropertyName); Assert.AreEqual(dataType, d.DataType); Assert.IsFalse(d.Generate); Assert.AreEqual(SetValue, d.SetValue); Assert.IsFalse(d.Substitute); Assert.IsNull(d.SubstitutionName); }
public void DestinationParserCreatesSubstitution() { // Arrange var id = new ImportDefinition(); var s = "DESTINATION AProperty STRING SUBSTITUTE {PlaceholderName}"; // Act DestinationParser.Parse(s, id); // Assert Assert.AreEqual(1, id.DestinationProperties.Count); var d = id.DestinationProperties[0]; Assert.AreEqual("AProperty", d.PropertyName); Assert.AreEqual(Enums.DataTypes.STRING, d.DataType); Assert.IsFalse(d.Generate); Assert.IsFalse(d.GenerateDateOnly); Assert.IsNull(d.SetValue); Assert.IsTrue(d.Substitute); Assert.AreEqual("PlaceholderName", d.SubstitutionName); }
private void DestinationParserThrowsExceptionWhenLineIsNullEquivalent(string line) { // Arrange var id = new ImportDefinition(); // Act try { DestinationParser.Parse(line, id); Assert.Fail("ArgumentNullException expected, not thrown."); } catch (ArgumentNullException ex) { Assert.AreEqual("Line", ex.ParamName); } catch (Exception ex) { Assert.Fail("Expected ArgumentNullException, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserThrowsExceptionWhenSUBSTITUTEIsMissingPlaceholder() { // Arrange var id = new ImportDefinition(); var s = "DESTINATION PropertyName STRING SUBSTITUTE"; // Act try { DestinationParser.Parse(s, id); Assert.Fail("IndexOutOfRangeException expected, none thrown."); } catch (IndexOutOfRangeException ex) { Assert.AreEqual("SUBSTITUTE called with no parameter name specified.", ex.Message); } catch (Exception ex) { Assert.Fail("Expected IndexOutOfRangeException, " + ex.GetType().Name + " thrown instead."); } }
public void DestinationParserThrowsExceptionWhenInvalidTokenFollowsDataType() { // Arrange var id = new ImportDefinition(); var s = "DESTINATION AColumn STRING NOTAVALIDTOKEN"; // Act try { DestinationParser.Parse(s, id); Assert.Fail("ArgumentException expected, not thrown."); } catch (ArgumentException ex) { Assert.AreEqual("Invalid token for Destination declaration: NOTAVALIDTOKEN", ex.Message); } catch (Exception ex) { Assert.Fail("ArgumentException expected, " + ex.GetType().Name + " thrown instead."); } }
private void DestinationParserThrowsExceptionWhenSettingGenerateOnInvalidDataType(Enums.DataTypes dataType) { // Arrange var id = new ImportDefinition(); var s = "DESTINATION ColumnName " + dataType.ToString() + " GENERATE"; // Act try { DestinationParser.Parse(s, id); Assert.Fail("Expected ArgumentException, not thrown."); } catch (ArgumentException ex) { Assert.AreEqual("Cannot set GENERATE on a data type other than GUID and DATETIME.", ex.Message); } catch (Exception ex) { Assert.Fail("Expected ArgumentException, " + ex.GetType().Name + " thrown instead."); } }