예제 #1
0
        public static void Main(string[] args)
        {
            var options = GetOptions(args);

            if(!options.RequiredOptionIsMissing)
            {
                try
                {
                    using (var destFs = new FileStream(options.DestinationsFile, FileMode.Open))
                    {
                        using(var taxFs = new FileStream(options.TaxonomyFile, FileMode.Open))
                        {
                            var destinationParser = new DestinationParser(destFs);
                            var templateLoader = new TemplateLoader();
                            var taxonomyParser = new TaxonomyParser(taxFs);
                            var htmlFileWriter = new HTMLFileWriter(templateLoader, taxonomyParser);

                            WriteFiles(destinationParser, htmlFileWriter, options);
                            Console.WriteLine("HTML Generation finished. Wrote files to {0}", options.OutputFolder);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: {0}", e.Message);
                }
            }
            Console.WriteLine("Press any key to exit...");
            Console.Read();
        }
        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.");
            }
        }
        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 Generate_introductory_info_for_a_destination()
        {
            using (var stream = new FileStream("Resources/sample_destinations.xml", FileMode.Open))
            {
                var parser = new DestinationParser(stream);
                var destination = parser.ReadAll().FirstOrDefault();

                Assert.That(destination, Has.Property("IntroductionOverview").ContainsSubstring("How do you capture the essence of Africa on paper without using up every cliché in the book?"));
            }
        }
        public void Not_fail_if_intro_is_missing()
        {
            using (var stream = new FileStream("Resources/problem_destinations.xml", FileMode.Open))
            {
                var parser = new DestinationParser(stream);
                var destination = parser.ReadAll().FirstOrDefault();

                Assert.That(destination, Has.Property("IntroductionOverview").Null);
            }
        }
        public void Provide_info_for_each_destination_in_the_file()
        {
            using (var stream = new FileStream("Resources/sample_destinations.xml", FileMode.Open))
            {
                var parser = new DestinationParser(stream);
                var destinations = parser.ReadAll().ToList();

                Assert.That(destinations, Has.Count.EqualTo(24));
                Assert.That(destinations, Has.All.With.Property("Title").Not.Null);
            }
        }
        public void Not_fail_if_destination_attributes_are_missing()
        {
            using(var stream = new FileStream("Resources/problem_destinations.xml", FileMode.Open))
            {
                var parser = new DestinationParser(stream);
                var destination = parser.ReadAll().FirstOrDefault();

                Assert.That(destination, Has.Property("AtlasId").Null);
                Assert.That(destination, Has.Property("AssetId").Null);
                Assert.That(destination, Has.Property("Title").Null);
                Assert.That(destination, Has.Property("TitleAscii").Null);
            }
        }
        public void Generate_destination_attribute_info_for_a_destination_in_the_file()
        {
            using(var stream = new FileStream("Resources/sample_destinations.xml", FileMode.Open))
            {
                var parser = new DestinationParser(stream);
                var destination = parser.ReadAll().FirstOrDefault();

                Assert.That(destination, Has.Property("AtlasId").EqualTo("355064"));
                Assert.That(destination, Has.Property("AssetId").EqualTo("22614-4"));
                Assert.That(destination, Has.Property("Title").EqualTo("Africa"));
                Assert.That(destination, Has.Property("TitleAscii").EqualTo("Africa"));
            }
        }
 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 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 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 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);
        }
예제 #15
0
 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.");
            }
        }